Onchain Service: supported networks, native and token balances, and transactions. These endpoints take a network key (e.g. ethereum_mainnet, bitcoin_mainnet, tron_mainnet), not a chain; list-networks returns the live list.

Balances are strings in the asset's smallest unit (wei, satoshi), so nothing is lost to floating point; convert with each token's decimals.

Values

MAX_BATCH_BALANCES

MAX_BATCH_BALANCES: Int 100

Functions

batch-balances

fn (network: Str, addresses: Vec<Str>): Map
fn (network: Str, addresses: Vec<Str>, opts: Map): Map

Balances for up to 100 addresses: {network, chain, balances: [...]} in request order. A failed address carries its own error instead of failing the call.

Example

out ::cipherowl::onchain/batch-balances("ethereum_mainnet", ["0x0000000000000000000000000000000000000001", "0x93df2c9c8786242b8fdca3f96b3914b8b4a9f704"])
map(out.balances, (b) { b.balance })

batch-balances-request

fn (network: Str, addresses: Vec<Str>): Map

The spec for a batch balance read: 1 to 100 addresses. Exposed for testing.

Example

spec ::cipherowl::onchain/batch-balances-request("ethereum_mainnet", ["0x0000000000000000000000000000000000000001"])
spec.path  // "/api/onchain/v1/networks/ethereum_mainnet/balances:batchget"
is-err(::cipherowl::onchain/batch-balances-request("ethereum_mainnet", []))  // true

get-balance

fn (network: Str, address: Str): Map
fn (network: Str, address: Str, opts: Map): Map

An address's balance on a network: {network, chain, balance: {address, balance, unit, tokens: [{contract, name, symbol, balance, decimals, type}], error}}.

Example

out ::cipherowl::onchain/get-balance("ethereum_mainnet", "0x0000000000000000000000000000000000000001")
out.balance.balance

get-transaction-scripts

fn (network: Str, txid: Str): Map
fn (network: Str, txid: Str, opts: Map): Map

The scripts of one transaction (Bitcoin-family networks only, currently bitcoin_mainnet).

Example

::cipherowl::onchain/get-transaction-scripts("bitcoin_mainnet", "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")

list-address-transactions

fn (network: Str, address: Str, options: Map): Map
fn (network: Str, address: Str, options: Map, opts: Map): Map

One page of an address's transactions: {network, chain, address, transactions, page, totalPages, totalItems}. Page numbers start at 1; the next page exists while page is below totalPages (see next-page).

Example

page ::cipherowl::onchain/list-address-transactions("bitcoin_mainnet", "bc1qexample", {page: 1, pageSize: 50})
page.transactions

// The next page, or null on the last one
::cipherowl::onchain/next-page(page)

list-networks

fn (): Map
fn (opts: Map): Map

The networks the Onchain Service supports: {chains: [{network, name, symbol, supportsTokens}]}.

Example

out ::cipherowl::onchain/list-networks()
map(out.chains, (c) { c.network })

next-page

fn (page: Any): Int?

The next 1-based page number for a numbered page, or null on the last page. Pure.

Example

::cipherowl::onchain/next-page({page: 1, totalPages: 3})  // 2
::cipherowl::onchain/next-page({page: 3, totalPages: 3})  // null

transactions-request

fn (network: Str, address: Str, options: Map): Map

The spec for one page of an address's transactions. options takes page (1-based), pageSize (default 25, max 100) and opReturnOnly. Exposed for testing.

Example

::cipherowl::onchain/transactions-request("bitcoin_mainnet", "bc1qexample", {page: 2}).path
// "/api/onchain/v1/networks/bitcoin_mainnet/addresses/bc1qexample/transactions/scripts?page=2"