library / Integrations / I0015
n8n RPC workflow
A Node script writes an importable n8n workflow that polls your Carbium RPC every 5 minutes with one HTTP Request node, reads a balance and the slot, and flags a low balance. It first runs the same two methods to check your key and address.
What the workflow does
Reading Solana state from n8n needs no Solana node. A read is a JSON-RPC POST, and the HTTP Request node sends one. The workflow has three nodes: a Schedule Trigger that fires every 5 minutes, an HTTP Request node that posts a two-call batch to Carbium, and a Code node that reads the answers and sets low when one account's balance falls under a limit.
| Node | Job |
|---|---|
| Every 5 minutes | Starts a run on a timer. |
| Call Carbium | POSTs one batch with getSlot and getBalance, authenticated by a Header Auth credential, and retries a failed call after 5 seconds. |
| Read result | Matches the answers by id, stops the run on any RPC error, and returns address, slot, sol and low. |
The workflow ends there on purpose. Add an IF or Filter node on low, then whatever node notifies you: Slack, email or a webhook call. A short Node script writes the workflow as JSON, so the address, the limit and the endpoint come from environment variables. Before it writes anything it runs the same two methods, getSlot and getBalance, to prove that your key and address work.
The Carbium side: one batch, one header
Carbium's RPC endpoint is https://services.carbium.sh. The key goes in the x-api-key header, and ?api-key= on the URL also works. In n8n use the header. A key in the URL lands in the node's saved parameters and in every workflow export. A header credential is stored once by n8n, and an export carries only its name.
Carbium takes one call or a batch of up to 100 in a single POST. The workflow sends a batch of two, getSlot and getBalance, with ids slot and balance. A JSON-RPC batch answers with an array and does not promise the order of the answers, so the Code node matches on id.
The Code node throws on any answer that has an error field, so the execution shows as failed in n8n and the message carries the code. -32601 is method not found, and it is not worth a retry. Methods such as getTokenLargestAccounts and getProgramAccountsV2 are not served and answer it.
The n8n side: one credential
In n8n, create a credential of type Header Auth. Set the name to x-api-key, set the value to your key, and call the credential Carbium key. The generated workflow sets the HTTP Request node to use a Header Auth credential but names none, since credential ids differ between n8n installs. After you import it, open Call Carbium and pick yours.
The node's Retry On Fail setting is on, with 5 seconds between tries. A fixed 5 seconds suits a poll that runs every 5 minutes, and a brief network fault or a busy moment passes before the second try.
The script never writes your key into the workflow. It reads CARBIUM_KEY for the check and nothing else uses it.
The generator
Install the dependency with npm install @solana/[email protected] and set "type": "module" in package.json. Node 24 strips the types on load. CARBIUM_KEY and WATCH_ADDRESS are required, and the script exits with a message when either is missing. CARBIUM_RPC_URL and MIN_SOL (default 1) are optional. The workflow JSON goes to standard output and the check line to standard error, so a redirect keeps them apart.
// I0015 · n8n RPC workflow// https://carbium.sh/library/integrate/n8n-rpc-workflow// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";const key = process.env.CARBIUM_KEY;const watched = process.env.WATCH_ADDRESS;if (!key || !watched) { console.error("Set CARBIUM_KEY and WATCH_ADDRESS (the account the workflow watches)."); process.exit(1);}const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const minSol = Number(process.env.MIN_SOL ?? 1);if (!Number.isFinite(minSol)) { console.error("MIN_SOL is not a number."); process.exit(1);}const commitment = "confirmed" as const;// Check the key and the address with the two methods the workflow will send.const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));try { const [slot, balance] = await Promise.all([ rpc.getSlot({ commitment }).send({ abortSignal: AbortSignal.timeout(10_000) }), rpc.getBalance(address(watched), { commitment }).send({ abortSignal: AbortSignal.timeout(10_000) }), ]); console.error(`check ok: slot ${slot}, ${watched} holds ${Number(balance.value) / 1e9} SOL`);} catch (err) { console.error("check failed:", err instanceof Error ? err.message : err); process.exit(1);}// The same two methods as one JSON-RPC batch, for the HTTP Request node.const batch = [ { jsonrpc: "2.0", id: "slot", method: "getSlot", params: [{ commitment }] }, { jsonrpc: "2.0", id: "balance", method: "getBalance", params: [watched, { commitment }] },];// The Code node: match answers by id, stop on any RPC error, flag a low balance.const jsCode = [ "const rows = $input.all().flatMap((i) => (Array.isArray(i.json) ? i.json : [i.json]));", "const bad = rows.find((r) => r.error);", "if (bad) throw new Error(`RPC error ${bad.error.code}: ${bad.error.message}`);", "const byId = Object.fromEntries(rows.map((r) => [r.id, r.result]));", "const sol = byId.balance.value / 1e9;", `return [{ json: { address: ${JSON.stringify(watched)}, slot: byId.slot, sol, low: sol < ${minSol} } }];`,].join("\n");const link = (node: string) => ({ main: [[{ node, type: "main", index: 0 }]] });const workflow = { name: "Carbium balance watch", nodes: [ { id: "n1", name: "Every 5 minutes", type: "n8n-nodes-base.scheduleTrigger", typeVersion: 1.2, position: [0, 0], parameters: { rule: { interval: [{ field: "minutes", minutesInterval: 5 }] } } }, { id: "n2", name: "Call Carbium", type: "n8n-nodes-base.httpRequest", typeVersion: 4.2, position: [240, 0], retryOnFail: true, waitBetweenTries: 5000, parameters: { method: "POST", url, authentication: "genericCredentialType", genericAuthType: "httpHeaderAuth", sendBody: true, specifyBody: "json", jsonBody: JSON.stringify(batch) } }, { id: "n3", name: "Read result", type: "n8n-nodes-base.code", typeVersion: 2, position: [480, 0], parameters: { jsCode } }, ], connections: { "Every 5 minutes": link("Call Carbium"), "Call Carbium": link("Read result") }, settings: {},};console.log(JSON.stringify(workflow, null, 2));
run: node main.ts > workflow.json
Import and run it
- Export CARBIUM_KEY and WATCH_ADDRESS, then run node main.ts > workflow.json. The terminal shows check ok: with the slot and the balance, or check failed: and a non-zero exit.
- In n8n, open the workflow menu and choose Import from File, or run n8n import:workflow --input=workflow.json on the host.
- Open Call Carbium and pick the Carbium key credential.
- Choose Execute workflow. The Read result output holds one item with address, slot, sol and low.
- To see low turn true, generate again with MIN_SOL above the balance, or edit the limit in the Code node.
- Add your notify nodes after Read result, then activate the workflow.
Importing a regenerated file creates a second workflow with the same name. Delete the old one, or edit the Code node by hand.
What it costs against your limits
getSlot is a cached read at 1 cell, and Free allows 5 req/s of that class. One batch every 5 minutes sits far under that. Look up what getBalance costs on your plan before you shorten the schedule or add addresses.
Limits are per account, so every key shares one budget, and the n8n credential draws on the same budget as your app. To watch many accounts, getMultipleAccounts takes up to 300 pubkeys (100 below Pro) and charges 10 cells per pubkey. To list recent activity, getSignaturesForAddress costs 50 cells and reaches back 30 days at most, because it reads Carbium's own address index. An empty page past that is the index's age limit.
Where it ends
- It polls. A balance that dips and recovers between two runs goes unseen. A push needs a WebSocket client, which the HTTP Request node is not. For a plain SOL wallet accountSubscribe stays silent, so a listener would use logsSubscribe with a mention filter plus getBalance, and post to an n8n Webhook node.
- The script checks the Carbium calls. It cannot import or run the workflow, so your first Execute workflow in n8n is the test of the n8n side.
- The node versions in the JSON match recent n8n releases. An older install may refuse a node on import; build that node by hand with the settings in the table.
- One address and one limit per workflow. More accounts mean a longer body and a longer Code node.
- It reads only. It signs and sends nothing and holds no private key.
- An inactive workflow, or an n8n that is down, sends no alert. Watch n8n itself from somewhere else.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The script prints check failed: HTTP error and exits. | The key is wrong, or CARBIUM_RPC_URL points somewhere else. Check that CARBIUM_KEY holds the key itself and that the endpoint variable is unset or is https://services.carbium.sh. The key goes in x-api-key. |
| Call Carbium fails in n8n with an HTTP authorization error after the import. | The credential is missing on the node or its header name is wrong. Create a Header Auth credential with the name x-api-key and the key as the value, with no Bearer prefix, then pick it in the node. |
| Read result stops the run with RPC error -32601. | The method name is misspelt or the method is not served. Do not retry. Fix the name in the Call Carbium body, with the exact case, and keep to methods Carbium serves. |
| Read result stops the run with RPC error -32602. | A parameter is invalid, most often an address that is not a base58 public key. Run the script again: it validates WATCH_ADDRESS before it writes anything and reports the bad value. |
| Call Carbium fails with a 429 and the retries fail too. | Your account's budget is spent. The limits are per account, so all of an account's keys share one budget. Lower the app's traffic, lengthen the schedule, or move to a plan with a higher rate. |
| low is true on the first run. | MIN_SOL is above the balance, or the watched address is the wrong one. Generate again with the right values, or edit the limit and the address in the Code node and the body in Call Carbium. |
Questions
Do I need a Solana community node in n8n?
Not for reads. Every Carbium read is a JSON-RPC POST, and the HTTP Request node sends it with a Header Auth credential.
Why a Header Auth credential and not `?api-key=` in the URL?
Both work. A URL with the key in it is saved in the node and shows up in workflow exports and logs. A credential keeps the key in one place.
Can I call other methods from the same node?
Yes. Change the method and params in the batch body. Each method has its own cost, and getSignaturesForAddress reaches back 30 days at most.
Does the generated JSON contain my key?
No. It holds the endpoint, the address, the limit and the batch body. The key lives in the n8n credential.