library / AI and blockchain / SI0004
ElizaOS account plugin
An ElizaOS plugin that reads Solana through Carbium and cannot write: a provider adds the current slot to each turn, and an action reads one account when the chat names an address. The slot read costs 1 cell a turn, an account read 10.
What the plugin does
An ElizaOS agent reaches the chain through plugins. A plugin is an object with a name, a description and lists of actions, providers, evaluators and services. This one fills two of the lists. A provider adds the current Solana slot to the context of each turn. An action, CARBIUM_CHECK_ACCOUNT, reads one account when the conversation contains an address.
Both go through one RPC client on Carbium's RPC endpoint. The plugin holds no wallet and no private key, and it has no code path that builds, signs or sends a transaction. A user who tells the agent to move tokens gets an agent that has nothing to do it with. The endpoint will not enforce that for you: it serves sendTransaction (20 cells without preflight, 70 with it), so the boundary is the code you write. Read-only model tools applies the same idea to a model's tool calls with a fixed method allowlist, and SPL token balance reads a token balance, which is the natural second action here.
Provider or action
Pick by who decides. A provider runs on its own before the model writes its reply, and the text it returns goes into the prompt. An action runs only when the model picks it from the list of action names, similes and descriptions, and validate can veto the pick first.
| Piece | Runs when | Chain call | Cost on Carbium |
|---|---|---|---|
| Provider CARBIUM_SLOT | each turn | getSlot | 1 cell |
| Action CARBIUM_CHECK_ACCOUNT | the model picks it and the text holds an address | getAccountInfo | 10 cells |
The cell counts settle which read goes where. getSlot is a cached read at 1 cell, and an account read is 10 cells. An account read inside a provider would charge ten cells on every message, including "gm". A slot inside an action would make the model decide to ask for something the prompt should already carry.
validate is the gate in front of the handler. It looks for a string of 32 to 44 base58 characters that isAddress from @solana/kit accepts. A chat line without an address never reaches the network, and neither does a made-up string of the wrong length or one that does not decode to 32 bytes. The handler repeats the lookup so it does not depend on validate having run.
The plugin file
One file. Node 24 runs the TypeScript directly and @solana/kit 8.6.0 is the only dependency. Set CARBIUM_KEY first; the file exits with a message when it is missing. CARBIUM_RPC_URL overrides the endpoint, which defaults to https://services.carbium.sh.
The client is built once at load and both pieces share it. Connections stay open 600 s and TLS sessions resume, so a client reused across turns skips most handshakes. The key goes in the x-api-key header. RPC also takes ?api-key= in the URL, but a URL ends up in proxy and access logs and in error messages, so the plugin keeps the key out of it.
// SI0004 · ElizaOS account plugin// https://carbium.sh/library/si/elizaos-account-plugin// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only ElizaOS-style plugin: one provider, one action. Run: CARBIUM_KEY=... node main.ts [address]import { createDefaultRpcTransport, createSolanaRpcFromTransport, isAddress } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1);}const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));// Local copies of the plugin shape; import the real types from @elizaos/core when you register this.type Message = { content: { text?: string } };type Callback = (reply: { text: string; actions?: string[] }) => Promise<unknown>;const findAddress = (text = "") => text.match(/[1-9A-HJ-NP-Za-km-z]{32,44}/g)?.find(isAddress);// Runs each turn, so it makes only a 1-cell read. No commitment passed: kit fills in confirmed.const slotProvider = { name: "CARBIUM_SLOT", description: "The current Solana slot at confirmed commitment.", get: async () => { const slot = await rpc.getSlot().send(); return { text: `Solana slot now: ${slot} (confirmed)`, values: { slot: String(slot) } }; },};// Runs only when the model picks it and the message holds an address: one 10-cell read.const checkAccount = { name: "CARBIUM_CHECK_ACCOUNT", similes: ["CHECK_ACCOUNT", "READ_ACCOUNT"], description: "Read one Solana account by address: lamports, owner, executable flag, data size. Read only.", validate: async (_runtime: unknown, message: Message) => findAddress(message.content.text) !== undefined, handler: async (_runtime: unknown, message: Message, _state?: unknown, _options?: unknown, callback?: Callback) => { const target = findAddress(message.content.text); if (!target) return false; let text: string; try { const { value } = await rpc.getAccountInfo(target, { encoding: "base64" }).send(); if (!value) { text = `${target} has no account on chain.`; } else { const sol = (Number(value.lamports) / 1e9).toFixed(9); const size = Buffer.from(value.data[0], "base64").length; text = `${target}: ${value.lamports} lamports (${sol} SOL), owner ${value.owner}, executable ${value.executable}, ${size} data bytes.`; } } catch (e) { text = `Could not read ${target}: ${(e as Error).message}`; } await callback?.({ text, actions: ["CARBIUM_CHECK_ACCOUNT"] }); return true; },};export const carbiumAccountPlugin = { name: "carbium-account", description: "Read-only Solana account lookups through Carbium.", actions: [checkAccount], providers: [slotProvider],};if (import.meta.main) { const target = process.argv[2] ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; const message: Message = { content: { text: `what does ${target} hold?` } }; console.log((await slotProvider.get()).text); console.log("validate:", await checkAccount.validate(undefined, message)); await checkAccount.handler(undefined, message, undefined, undefined, async (reply) => console.log(reply.text)); console.log("validate on chat:", await checkAccount.validate(undefined, { content: { text: "gm" } }));}
run: node main.ts
The main block plays one turn without the framework. It prints what the provider returns, calls validate and the handler with a message that carries the address (pass your own as the first argument; the default is the USDC mint), then calls validate on a line with no address. Expect a slot line, validate: true, an account line with lamports, owner, executable flag and data size, and validate on chat: false. For the mint the owner is the token program and the data is 82 bytes.
What a turn costs
| Plan | Slot read, req/s (1 cell) | Account read, req/s (10 cells) |
|---|---|---|
| Free | 5 | 0.5 |
| Dev | 30 | 15 |
| Business | 100 | 50 |
| Pro | 500 | 400 |
On Free, 0.5 req/s means one account read every two seconds. One agent talking to one person stays far under that. Several agents can reach it: limits are per account and an account's keys share one budget, so a second agent with its own key draws on the same cells.
A call the rate limit refuses gets a 429 with a retry-after hint. The handler does not retry. It catches the error and turns it into a short reply, so the user hears that the read failed and asks again. A retry loop inside a handler holds the conversation turn open while it waits.
What the reply means
Text a provider returns is prompt text, so keep it to facts the code computed. The slot line is a number the model can quote, and the reply says it was read at confirmed. An account's data holds content its creator chose, which the model should never read as instructions, and that is why the action reports only its size. The reply gives lamports as the exact integer and SOL with nine decimals, because a model handed only lamports converts them itself and sometimes misplaces the point.
A missing account comes back as a null value and the reply says there is no account on chain. At confirmed, an account created a moment ago can still read as missing.
Where it ends
- The action reads one account on request. A wallet's SOL balance is the lamports in that reply. A token balance sits in a token account with its own address, and this action does not look for it. To read several accounts in one call, getMultipleAccounts charges 10 cells per pubkey and takes up to 300 (100 below Pro).
- The plugin cannot watch anything. For a live balance, accountSubscribe stays silent for a plain SOL wallet; use logsSubscribe with a mention filter, which streams transaction logs, plus getBalance. A subscription opens at 5, 25 or 200 credits by filter weight and then costs 20 credits per MiB sent.
- Recent activity needs getSignaturesForAddress, 50 cells a call. Carbium serves it from its own address index, which reaches back 30 days at most. An empty page past that means the index's age limit and says nothing about the address's first transaction.
- Methods Carbium does not serve, such as getTokenLargestAccounts, answer -32601, method not served. Do not retry them.
- There is no signing here. A plugin that spends needs its own process, its own key handling and a human approval step, and does not belong beside a chat plugin that only reads.
- The file does not import the framework. Registering it, typing it against your @elizaos/core version and choosing which agents load it are steps you do.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The model invents an address or pastes a truncated one and the handler reads garbage. | Gate on isAddress in validate and again in the handler. A string that is not a valid 32-byte address never reaches the network, and the action stays out of the turn. |
| Every message spends a 10-cell account read. | Keep account reads in an action and give the provider only getSlot. The provider runs each turn, the action only when the model picks it. |
| A 429 reaches the user as a stack trace or stalls the turn. | Catch the error in the handler and send a one-line reply through the callback. Do not retry inside the handler. Limits are per account, so look for other agents or keys spending the same budget. |
| The key shows up in a reply, a log line or the model's context. | Set it once in the transport headers and keep it out of the URL, where ?api-key= would land in logs. Reply with the error's message only, and never log the transport or its configuration. |
| A freshly funded account answers "no account on chain". | The read is at confirmed and a null value is a reading at one moment. Ask again after a few seconds before telling the user the account does not exist. |
| A user asks the agent to send tokens and the model hunts for a way. | The plugin has no write path, and its action description says read only. Have the reply say so and offer the read instead. |
Questions
Does this plugin import ElizaOS?
No. It declares small local types that follow the plugin shape, so node main.ts runs it alone. To register it, import the real types from @elizaos/core, check the field names against your version and add the exported plugin to your agent's plugin list.
Which commitment do the reads use?
Confirmed. @solana/kit 8.6.0 fills it in when a call leaves it out, while the JSON-RPC server's own default is finalized. Pass { commitment: "finalized" } in the call's config to change it.
How many account reads can an agent make per second?
At 10 cells each, account reads run at 0.5 req/s on Free, 15 on Dev, 50 on Business and 400 on Pro. An account's keys share one budget.
Can the agent send a transaction through this plugin?
No. No code path builds, signs or sends, and the plugin holds no key. The endpoint serves sendTransaction, so the code you write is the boundary.