Installation
Arkiv provides an official TypeScript/JavaScript SDK — @arkiv-network/sdk — that works in Node.js, Bun, and the browser. It handles client creation, queries, mutations, event subscriptions, and payload encoding.
Install the SDK
Section titled “Install the SDK”npm install @arkiv-network/sdkbun add @arkiv-network/sdkClient Setup
Section titled “Client Setup”WalletClient (read/write)
Section titled “WalletClient (read/write)”Requires a private key. Use for creating, updating, and deleting entities:
import { createWalletClient, http } from "@arkiv-network/sdk"import { privateKeyToAccount } from "@arkiv-network/sdk/accounts"import { kaolin } from "@arkiv-network/sdk/chains"
const walletClient = createWalletClient({ chain: kaolin, transport: http(), account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),})PublicClient (read-only)
Section titled “PublicClient (read-only)”No private key needed. Use for queries — safe for frontend use:
import { createPublicClient, http } from "@arkiv-network/sdk"import { kaolin } from "@arkiv-network/sdk/chains"
const publicClient = createPublicClient({ chain: kaolin, transport: http(),})Hello, World!
Section titled “Hello, World!”-
Create your project
Terminal window mkdir hello-arkiv && cd hello-arkivnpm init -ynpm install @arkiv-network/sdk dotenv typescriptTerminal window mkdir hello-arkiv && cd hello-arkivbun init -ybun add @arkiv-network/sdk dotenv -
Add your private key
.env PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HEREGet test ETH from the Kaolin Faucet.
-
Write your first entity
hello.ts import { createWalletClient, createPublicClient, http } from '@arkiv-network/sdk';import { stringToPayload } from '@arkiv-network/sdk/utils';import { kaolin } from '@arkiv-network/sdk/chains';import { privateKeyToAccount } from '@arkiv-network/sdk/accounts';import { config } from 'dotenv';config({ path: '.env' });const walletClient = createWalletClient({chain: kaolin,transport: http(),account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),});const publicClient = createPublicClient({chain: kaolin,transport: http(),});// Create an entityconst { entityKey, txHash } = await walletClient.createEntity({payload: stringToPayload('Hello, Arkiv!'),contentType: 'text/plain',attributes: [{ key: 'type', value: 'greeting' }],expiresIn: 3600,});console.log('Entity created:', entityKey);console.log('Transaction:', txHash);// Read it backconst entity = await publicClient.getEntity(entityKey);console.log('Retrieved:', entity.toText()); -
Run it
Terminal window npx tsx hello.tsTerminal window bun run hello.ts
Browser Usage (CDN)
Section titled “Browser Usage (CDN)”For static HTML/JS pages without a bundler:
import { createPublicClient, http } from 'https://esm.sh/@arkiv-network/sdk@0.6.0?target=es2022&bundle-deps'import { eq } from 'https://esm.sh/@arkiv-network/sdk@0.6.0/query?target=es2022&bundle-deps'import { kaolin } from 'https://esm.sh/@arkiv-network/sdk@0.6.0/chains?target=es2022&bundle-deps'