SDK walkthrough, part 1 of 3
SDK quickstart
From an empty folder to a transfer sent from your own code.
The SDK is the same package as the CLI, @arxiumlabs/sdk. It has no runtime dependencies and runs in Node, browsers and Workers. These pages use plain JavaScript files run with Node, so there's nothing to compile.
Before you start
- Node 20 or later.
- An API key from Endpoints and API keys.
- A Console key holding test ARX: sign in at the Console, generate a key under Settings, claim ARX under Faucet, then click Export encrypted key.
1. Create a project
mkdir my-arxium-app && cd my-arxium-appnpm init -ynpm pkg set type=modulenpm install @arxiumlabs/sdkMove the exported key file into the folder, then set the same variables the CLI uses:
export ARX_RPC=https://retracer-api.arxium.network/rpc/corechain-devnetexport ARX_TOKEN=rk_...export ARX_KEY=arxium-devnet-key-xxxxxxxx.jsonexport ARX_PASSPHRASE=... # the key's passphrase2. Connect and unlock your key
Every script in this walkthrough imports this one file:
// Shared by every script: one client, your key, and a send() that signs, submits and waits.import { readFile } from "node:fs/promises";import { ArxiumRpc, unlockKey } from "@arxiumlabs/sdk"; export const rpc = new ArxiumRpc({ rpc: process.env.ARX_RPC, token: process.env.ARX_TOKEN });export const me = JSON.parse(await readFile(process.env.ARX_KEY, "utf8")); // the key file exported from the Consoleconst privateKey = await unlockKey(me, process.env.ARX_PASSPHRASE); export const send = (payload) => rpc.sendAction({ privateKey, sender: me.address, payload });unlockKey decrypts the key in memory with WebCrypto. The key and passphrase never leave your machine. send fetches your nonce, signs locally, submits the action and waits until it's in a block. In a real app, load the passphrase from a secret store rather than the environment.
3. Read a balance and send ARX
import { arxToIum, encodeTransfer, iumToArx } from "@arxiumlabs/sdk";import { me, rpc, send } from "./arxium.mjs"; const account = await rpc.account(me.address);console.log(`${me.address} holds ${iumToArx(BigInt(account.balance))} ARX`); const { action, status } = await send(encodeTransfer(process.argv[2], arxToIum("1")));console.log(`${status.status} at height ${status.height}, signature ${action.signature.slice(0, 16)}…`);Pass any address, such as a second Console account's:
node send.mjs arx1urfs...arx1k29t… holds 10 ARXconfirmed at height 11, signature b41d56b8ba908cee…Each encode… function builds one action's payload, and send does the rest. Amounts are bigint base units: arxToIum("1") is 1_000_000_000n. If the chain refuses an action, send throws an ActionDroppedError carrying the node's reason. Part 3 turns that into a message for your user.