Installation
This guide targets the Tiramisu testnet. Check Networks for current testnets and faucets.
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 watching, and payload encoding.
The SDK builds on viem. It declares viem as a peer dependency. Install viem alongside the SDK.
Install the SDK
Section titled “Install the SDK”npm install @arkiv-network/sdk viembun add @arkiv-network/sdk viemClient Setup
Section titled “Client Setup”WalletClient (read/write)
Section titled “WalletClient (read/write)”WalletClient needs a private key. Use it to create, patch, and delete entities:
import { createWalletClient } from "@arkiv-network/sdk"import { tiramisu } from "@arkiv-network/sdk/chains"import { http } from "viem"import { privateKeyToAccount } from "viem/accounts"
const walletClient = createWalletClient({ chain: tiramisu, transport: http(), account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),})PublicClient (read-only)
Section titled “PublicClient (read-only)”PublicClient needs no private key. Use it for queries. It is safe for frontend use:
import { createPublicClient } from "@arkiv-network/sdk"import { tiramisu } from "@arkiv-network/sdk/chains"import { http } from "viem"
const publicClient = createPublicClient({ chain: tiramisu, transport: http(),})Hello, World!
Section titled “Hello, World!”-
Create your project
Terminal window mkdir hello-arkiv && cd hello-arkivnpm init -ynpm pkg set type=modulenpm install @arkiv-network/sdk viem typescriptTerminal window mkdir hello-arkiv && cd hello-arkivbun init -ybun add @arkiv-network/sdk viem -
Add your private key
.env PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HEREArkiv chains use GLM as the native gas token. Get test GLM from the faucet.
-
Write your first entity
hello.ts import { createWalletClient, createPublicClient, ExpirationTime } from '@arkiv-network/sdk';import { stringToPayload } from '@arkiv-network/sdk/utils';import { tiramisu } from '@arkiv-network/sdk/chains';import { http } from 'viem';import { privateKeyToAccount } from 'viem/accounts';const walletClient = createWalletClient({chain: tiramisu,transport: http(),account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),});const publicClient = createPublicClient({chain: tiramisu,transport: http(),});// Create an entityconst { entityKey, txHash } = await walletClient.createEntity({payload: stringToPayload('Hello, Arkiv!'),contentType: 'text/plain',attributes: { type: 'greeting' },expires: ExpirationTime.fromHours(1),});console.log('Entity created:', entityKey);console.log('Transaction:', txHash);// Read it backconst entity = await publicClient.getEntity(entityKey);console.log('Retrieved:', entity.toText()); -
Run it
Run it with:
Terminal window npx tsx --env-file=.env 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 } from 'https://esm.sh/@arkiv-network/sdk?target=es2022&bundle-deps'import { eq } from 'https://esm.sh/@arkiv-network/sdk/query?target=es2022&bundle-deps'import { tiramisu } from 'https://esm.sh/@arkiv-network/sdk/chains?target=es2022&bundle-deps'import { http } from 'https://esm.sh/viem?target=es2022'