Skip to content

PublicArkivActions

PublicArkivActions<transport, chain, account> = Pick<PublicActions<transport, chain, account>, "getBalance" | "getBlock" | "getBlockNumber" | "getChainId" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "waitForTransactionReceipt" | "watchEvent"> & object

Defined in: src/clients/decorators/arkivPublic.ts:18

buildQuery: () => QueryBuilder

Returns a QueryBuilder instance for building and executing queries. The QueryBuilder object follows the Builder pattern, allowing you to chain methods to build a query and then execute it.

QueryBuilder

A QueryBuilder instance for building and executing queries. QueryBuilder

import { createPublicClient, http } from 'arkiv'
import { braga } from 'arkiv/chains'
const client = createPublicClient({
chain: braga,
transport: http(),
})
const query = client.buildQuery()
const entities = await query.where("key", "=", "value").ownedBy("0x123").fetch()

getBlockTiming: () => Promise<{ blockDuration: number; currentBlock: bigint; currentBlockTime: number; }>

Returns the current block timing.

Promise<{ blockDuration: number; currentBlock: bigint; currentBlockTime: number; }>

The current block timing. GetBlockTimingReturnType

import { createPublicClient, http } from 'arkiv'
import { braga } from 'arkiv/chains'
const client = createPublicClient({
chain: braga,
transport: http(),
})
const blockTiming = await client.getBlockTiming()
// {
// currentBlock: 10n, // block number
// currentBlockTime: 1234567890, // block timestamp
// blockDuration: 2, // in seconds
// }

getEntity: (key) => Promise<Entity>

Returns the entity with the given key.

Hex

The entity key (hex string)

Promise<Entity>

The entity with the given key. Entity

import { createPublicClient, http } from 'arkiv'
import { braga } from 'arkiv/chains'
const client = createPublicClient({
chain: braga,
transport: http(),
})
const entity = await client.getEntity("0x123")
// {
// key: "0x123",
// value: "0x123",
// }

getEntityCount: () => Promise<number>

Returns the number of entities in the DBChain.

Promise<number>

The number of entities in the DBChain

import { createPublicClient, http } from 'arkiv'
import { braga } from 'arkiv/chains'
const client = createPublicClient({
chain: braga,
transport: http(),
})
const entityCount = await client.getEntityCount()
// entityCount = 0

query: (query, queryOptions?) => Promise<QueryReturnType>

Returns a QueryResult instance for fetching the results of a raw query. If no query options are provided, all payload is included, but no metadata (like owner, expiredAt, etc.) and attributes.

string

The raw query string

QueryOptions

The optional query options - QueryOptions

Promise<QueryReturnType>

A QueryReturnType instance - QueryReturnType

import { createPublicClient, http } from 'arkiv'
import { braga } from 'arkiv/chains'
const client = createPublicClient({
chain: braga,
transport: http(),
})
const queryResult = client.query('key = value && $owner = 0x123')
// queryResult = { entities: [{ key: "0x123", value: "0x123" }], cursor: undefined, blockNumber: undefined }
const queryResultWithOptions = client.query('key = value && $owner = 0x123', {
includeData: {
attributes: false,
payload: true,
metadata: true,
},
resultsPerPage: 10,
cursor: undefined,
atBlock: undefined,
})
// queryResultWithOptions = { entities: [{ key: "0x123", value: "0x123" }], cursor: "...", blockNumber: 32223n }

select: {(selection?): SelectQueryBuilder<FullEntity>; <S>(selection): SelectQueryBuilder<ProjectedEntity<S>>; (selection): SelectQueryBuilder<FullEntity>; }

Returns a SelectQueryBuilder for building and executing queries — the recommended way to read entities. You declare up front which parts of an entity you want returned, so results always contain exactly the data you asked for.

(selection?): SelectQueryBuilder<FullEntity>

Select every field. Pass nothing or "*"; the returned entities contain all fields.

"*"

SelectQueryBuilder<FullEntity>

<S>(selection): SelectQueryBuilder<ProjectedEntity<S>>

Pick the entity fields to return. Set the ones you want to true (at least one is required); the result is typed to exactly those fields, so reading anything else is a compile error.

Available fields: key, owner, creator, contentType, payload, attributes, expiresAtBlock, createdAtBlock, lastModifiedAtBlock, transactionIndexInBlock, operationIndexInTransaction.

Pass the selection inline so its fields stay literal true. A selection stored in a let/ const variable widens to boolean and the result type can no longer be narrowed — annotate it as const (e.g. const sel = { owner: true } as const) in that case.

S extends EntitySelection

S

SelectQueryBuilder<ProjectedEntity<S>>

client.select({ owner: true, attributes: true }) // entities typed { owner, attributes }
client.select({ key: true, payload: true }) // includes payload → toText()/toJson() too

(selection): SelectQueryBuilder<FullEntity>

Dynamic selection: accepts a value typed SelectArg (e.g. built at runtime). The result cannot be narrowed in this case, so the entities are typed as the full entity.

SelectArg

SelectQueryBuilder<FullEntity>

What to include in the results. Omit it (or pass "*") to select everything, or pass an object to select specific parts (at least one field is required). Every part is opt-in, including the key. The selection is flat — each field maps to an entity field. SelectArg

A SelectQueryBuilder instance for building and executing queries. SelectQueryBuilder

import { createPublicClient, http } from 'arkiv'
import { braga } from 'arkiv/chains'
import { eq } from 'arkiv/query'
const client = createPublicClient({
chain: braga,
transport: http(),
})
// select everything
await client.select().where(eq("category", "docs")).fetch()
await client.select("*").where(eq("category", "docs")).fetch()
// only the key
await client.select({ key: true }).where(eq("category", "docs")).fetch()
// select specific fields — result typed { owner: Hex; attributes: Attribute[] }
await client.select({ owner: true, attributes: true }).fetch()
// a single field — result typed { owner: Hex }
await client.select({ owner: true }).fetch()

subscribeEntityEvents: ({ onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpiresInExtended, }, pollingInterval?, fromBlock?) => Promise<() => void>

Subscribes to entity events. Takes an object with event handlers: {onError, onEntityCreated, onEntityUpdated, onEntityDeleted, onEntityExpiresInExtended}

{
onError,
onEntityCreated,
onEntityUpdated,
onEntityDeleted,
onEntityExpiresInExtended,
\}

(event) => void

(event) => void

(event) => void

(event) => void

(event) => void

(error) => void

number

The polling interval in milliseconds

bigint

The block number to start from

Promise<() => void>

A function to unsubscribe from the events

import { createPublicClient, http } from 'arkiv'
import { braga } from 'arkiv/chains'
const client = createPublicClient({
chain: braga,
transport: http(),
})
const unsubscribe = await client.subscribeEntityEvents({
onError: (error) => console.error("subscribeEntityEvents error", error),
})
unsubscribe() // unsubscribe from the events

transport extends Transport = Transport

chain extends Chain | undefined = Chain | undefined

account extends Account | undefined = Account | undefined