Skip to main content

Public Client

A public client reads Aleo chain state and nothing else: blocks, transactions, balances, program mappings, staking data, and network metrics. It carries no account and no proving configuration, so it cannot sign or submit a transaction — every method is a network read through its transport. This mirrors viem's publicClient: the read surface is separate from the write surface, so an application can hold a public client with no wallet connected at all.

Create a public client

import { createPublicClient, http } from '@provablehq/veil-core'

const client = createPublicClient({
transport: http('https://api.provable.com/v2', { network: 'mainnet' }),
})

createPublicClient takes a PublicClientConfig:

FieldTypeDescription
transportTransportCarries every read request to the network. See Transports.
keystring (optional)Identifier for the client's type. Defaults to 'public'.
namestring (optional)Human-readable name. Defaults to 'Public Client'.

Actions

Every method below hits the network through the client's transport and returns a typed result. Full parameters, return types, and examples live on each action's own page.

Chain state

ActionDescription
getBlockNumberLatest block height.
getBlockHashLatest block hash.
getBlockBlock by height or hash.
getBlocksBlocks in a height range.
getBlockTransactionsConfirmed transactions in a block, by height.
getBlockTransactionsByHashConfirmed transactions in a block, by hash.
getBlockHeightByHashHeight of the block with the given hash.
getBlockSummarySummary of the latest 1000 blocks.
getStateRootGlobal state root at a height, or the latest.
getStatePathMerkle path proving a record commitment's inclusion.
getStatePathsMerkle paths for multiple commitments.
findBlockHeightByStateRootHeight of the block that produced a state root.
findBlockHashHash of the block containing a transaction.

Transactions

ActionDescription
getTransactionFull transaction by id.
getConfirmedTransactionConfirmed transaction, wrapped with accepted/rejected status.
getUnconfirmedTransactionTransaction in its as-submitted form.
getTransactionByTransitionTransaction that contains a given transition.
getTransactionsByAddressTransactions involving an address.
getTransactionSummarySummary of the latest 1000 transactions.
findTransactionIdTransaction id that contains a transition.

Transitions

ActionDescription
getTransitionsTransition summaries involving an address.
findTransitionIdTransition id that consumed or produced an input/output.
getTransitionViewKeysView keys for a transition's outputs.

Programs, mappings & editions

ActionDescription
getCodeProgram source code.
getProgramAlias of getCode.
readContractRead a mapping value.
readMappingAlias for readContract.
getMappingNamesMapping names declared by a program.
getDeploymentTransactionTransaction that deployed a program.
getProgramCallsLatest calls into a program.
getProgramCallsPaginatedCalls into a program, paginated.
getLatestEditionLatest edition number for an upgradeable program.
getProgramByEditionProgram source at a specific edition.
getAmendmentCountNumber of amendments made to a program.
getAmendmentCountByEditionAmendment count as of a specific edition.
getDeploymentTransactionByEditionDeployment transaction for a specific edition.
getOriginalDeploymentTransactionThe program's first deployment transaction.
getAmendmentDeploymentTransactionDeployment transaction for a specific amendment.
getProgramIdByAddressProgram id owning a given program address.
getProgramAddressProgram address for a given program id.

Account

ActionDescription
getBalancePublic credits balance for an address, in microcredits.

Committee & staking

ActionDescription
getCommitteeCurrent or historical validator committee.
getDelegatorsDelegator addresses bonded to a validator.
getStakingEarningsCumulative staking rewards for an address.

Metrics

ActionDescription
getTransactionMetricsDaily transaction counts.
getProgramMetricsProgram call counts over the last 7 days.
getProgramMetricsByRangeProgram call counts over a custom range.
getApyCurrent network-wide staking APY.
getValidatorApyPer-validator APY.

Supply & tokens

ActionDescription
getTotalSupplyTotal ALEO supply.
getCirculatingSupplyCirculating ALEO supply.
getTvlTotal value locked across DeFi programs.
getTokensToken registry data.
getTokenDetailsDetail record for one token.

Examples

Read a mapping value

const balance = await client.readContract({
programId: 'credits.aleo',
mapping: 'account',
key: 'aleo1...',
})
// '5000000u64'

Get the current block

const height = await client.getBlockNumber()
const block = await client.getBlock({ height: Number(height) })
console.log(block.block_hash, block.header.metadata.timestamp)

Query staking state

const committee = await client.getCommittee()
const delegators = await client.getDelegators({ validator: 'aleo1validator...' })
const earnings = await client.getStakingEarnings({ address: 'aleo1...' })

extend()

createPublicClient builds on the base client returned by createClient and layers its read actions on with extend. Any client — public, wallet, or test — can take the same path to add its own methods without losing what an earlier extend call attached:

const client = createPublicClient({
transport: http('https://api.provable.com/v2', { network: 'mainnet' }),
}).extend((base) => ({
getBlockAge: async () => {
const block = await base.request({ method: 'getBlock', params: {} })
return Date.now() / 1000 - (block as any).header.metadata.timestamp
},
}))

Each extend call returns a new client carrying the base client's properties plus whatever the passed function returns, so decorators compose — this is how publicActions, walletActions, testActions, devnodeActions, and leoActions are all implemented.