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:17

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,
},
orderBy: [{ name: "key", type: "string", desc: "asc" }],
resultsPerPage: 10,
cursor: undefined,
atBlock: undefined,
})
// queryResultWithOptions = { entities: [{ key: "0x123", value: "0x123" }], cursor: "...", blockNumber: 32223n }

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