DePIN data plane
A data plane for a DePIN project's on-chain side: which Carbium call reads each part, a Node script that backfills and tails a device program into SQLite, and the numbers to size for a fleet.
Three reads behind a device fleet
A DePIN project keeps most of its data off chain. Sensor readings, coverage proofs and telemetry live in your own pipeline. The chain side is smaller and holds the parts other people must be able to check: device registration, proof or reward submissions, and token balances. Your backend needs three reads against it, and each one maps to a single Carbium call.
| Job | Call | What it costs |
|---|---|---|
| Device state: owner and status held in registry accounts | getMultipleAccounts | 10 cells per pubkey, up to 100 pubkeys per call below Pro and 300 on Pro |
| Live reports: each transaction that touches your program | logsSubscribe with a mentions filter | Opens at 25 credits, then 20 credits per MiB sent |
| History: audit and catch-up after downtime | getSignaturesForAddress | 50 cells per call, from an index that keeps up to 30 days |
All three go to one domain, and limits are per account, so every service you run shares the same budget.
Subscribe, then backfill, into one store
The script takes the address your devices report to, either a program id or a token mint when rewards are the signal, and optionally some device accounts. It opens a logsSubscribe with a mentions filter, waits for the reply (up to 3 seconds), and stores every notification. Then it reads the latest 100 signatures for the address and stores them, reads the device accounts with one getMultipleAccounts call, and keeps listening for LISTEN_MS milliseconds. The backfill and the account read each run in their own try, so a call that is refused prints what failed and the socket stays open.
// UC0014 · DePIN data plane// https://carbium.sh/library/usecase/depin-data-plane// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only DePIN ingest: tails a device program's logs, backfills its recent signatures, dedupes in SQLite.import { DatabaseSync } from "node:sqlite";import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } 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 rpcUrl = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const wsUrl = process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh";const program = process.argv[2] ?? "";const devices = process.argv.slice(3);if (!program) { console.error("Usage: node main.ts <program or mint address> [device account ...]"); process.exit(1); }const listenMs = Number(process.env.LISTEN_MS ?? 15000);// One row per signature: the live feed and the backfill can overlap without double counting.const db = new DatabaseSync(process.env.DEPIN_DB ?? ":memory:");db.exec("CREATE TABLE IF NOT EXISTS reports (signature TEXT PRIMARY KEY, slot INTEGER, failed INTEGER, source TEXT)");const put = db.prepare("INSERT OR IGNORE INTO reports VALUES (?, ?, ?, ?)");const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url: rpcUrl, headers: { "x-api-key": key } }));// Live first: one logsSubscribe on the address, key in the query string, live before the backfill starts.const url = new URL(wsUrl);url.searchParams.set("api-key", key);const ws = new WebSocket(url);let subscribed: (v?: unknown) => void = () => {};const subReply = new Promise((resolve) => { subscribed = resolve; });ws.addEventListener("message", (e) => { const m = JSON.parse(String(e.data)); // Reply to request 1: the subscription id, or the error when the subscription is refused. if (m.id === 1) { console.log(m.error ? `logsSubscribe refused: ${JSON.stringify(m.error)}` : `logsSubscribe id: ${m.result}`); subscribed(); } if (m.method !== "logsNotification") return; const { context, value } = m.params.result; put.run(value.signature, context.slot, value.err ? 1 : 0, "live");});ws.addEventListener("error", () => console.error("websocket error"));await new Promise((ready) => { ws.addEventListener("open", ready); ws.addEventListener("error", ready); });if (ws.readyState === 1) { ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "logsSubscribe", params: [{ mentions: [program] }, { commitment: "confirmed" }], })); // Wait for the reply (3 s at most for a socket that never answers) before the backfill reads. await Promise.race([subReply, new Promise((r) => setTimeout(r, 3000))]);}// History: the latest 100 signatures that touched the address (confirmed, the kit default).try { for (const s of await rpc.getSignaturesForAddress(address(program), { limit: 100 }).send()) { put.run(s.signature, Number(s.slot), s.err ? 1 : 0, "backfill"); }} catch (e) { console.error(`backfill failed: ${String(e)}`); }// Device state: one call for up to 100 accounts below Pro (300 on Pro), 10 cells per pubkey.if (devices.length) { try { const { value } = await rpc.getMultipleAccounts(devices.map((d) => address(d)), { encoding: "base64" }).send(); console.log(`device accounts found: ${value.filter(Boolean).length} of ${devices.length}`); } catch (e) { console.error(`getMultipleAccounts failed: ${String(e)}`); }}await new Promise((done) => { ws.addEventListener("close", done); setTimeout(() => { ws.close(); done(null); }, listenMs); });// One line per source, with zeros when a path stored nothing.const sql = "SELECT source, COUNT(*) AS reports, SUM(failed) AS failed, MIN(slot) AS first_slot, MAX(slot) AS last_slot FROM reports GROUP BY source";const rows = db.prepare(sql).all();for (const source of ["backfill", "live"]) { const row = rows.find((r) => r.source === source) ?? { source, reports: 0, failed: 0, first_slot: null, last_slot: null }; console.log(JSON.stringify(row));}db.close();
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts <program-or-mint-address> [device-account ...]
The primary key is the signature and every insert is INSERT OR IGNORE. Because the script waits for the subscription reply before the backfill, a transaction that lands between the two reads arrives on the live path, and one that shows up on both paths is stored once. The same property covers a reconnect, a restart and a replay after an outage. Each row records the source that stored it first, so the summary prints one line for backfill and one for live, with a count of zero when a path stored nothing.
Failed transactions arrive too. A log notification carries an err field and the script stores it as failed. Keep those rows. A device whose proofs keep failing says something about the device, and a reward program should not count that attempt as a report.
Set DEPIN_DB to a file path to keep the store between runs. The default is an in-memory database. The script prints the subscription reply, counts and slot ranges, never the key. A refused subscription shows up as its error in that first reply line. The script reads and stores. It signs nothing and sends nothing.
Sizing the budget for a fleet
A fleet makes the request budget a design input, and the rates per call set that budget.
| Call | Cells | Free req/s | Dev req/s | Business req/s | Pro req/s |
|---|---|---|---|---|---|
| getMultipleAccounts, per pubkey | 10 | 0.5 | 15 | 50 | 400 |
| getSignaturesForAddress | 50 | 0.24 | 1.2 | 100 | 500 |
| getSlot and other cached reads | 1 | 5 | 30 | 100 | 500 |
- Registry reads: the getMultipleAccounts req/s figures count pubkeys, so a 100-pubkey call uses 100 of them and costs 1000 cells. The 1024-cell burst caps a call at 100 pubkeys below Pro, and 300 per call is for Pro only. Read only the accounts of devices that appeared in the log feed.
- History: run getSignaturesForAddress at start-up and after a gap, and page only as far as the gap needs.
- Live feed: one logsSubscribe per program, with fan-out in your own code. A mentions filter opens at 25 credits, then costs 20 credits per MiB sent, and a refused subscription is free. Free carries 5 sockets.
- Heartbeat: compare your newest stored slot with getSlot, a cached read at 1 cell, to see how far behind the ingest is.
Credits per plan are Free at $0 with 500K once at sign-up, then per month Dev at $20 with 10M, Business at $250 with 50M and Pro at $500 with 200M. A log feed is metered by the MiB it sends, so the filter is your main lever. Mention the one account every device touches and your pipeline sees only that traffic.
Account changes and the gRPC stream
accountSubscribe reports account state on change for accounts Carbium streams. A plain SOL wallet stays silent, so a device wallet that only holds SOL needs logsSubscribe mentions plus a getBalance read.
For a larger pipeline the Carbon Stream over gRPC sits at services.carbium.sh:9443 and takes the key in the x-token header. Dev, Business and Pro open it on that port and Free is off. A stream opens at the same 5, 25 or 200 credit weights as a subscription and costs 20 credits per MiB sent. The SQLite table above works behind it with one change: gRPC transaction updates carry the signature as bytes, so base58-encode it before it matches the stored key.
Where it ends
- History: getSignaturesForAddress pages come from the address index, which keeps up to 30 days. An empty page past that is the index's age limit. Keep your own store, as the script does, for anything older.
- Off-chain data: sensor payloads, location and coverage evidence that your project keeps off chain belong to your pipeline. Carbium serves the chain side.
- Scans: getProgramAccountsV2 and getTokenLargestAccounts are two of the methods that are not served. They answer -32601: the method is not served, and a retry gets the same answer. Build the device registry from the log feed and read accounts by address.
- Sending: the script is read-only. If your devices or a relay submit reports through RPC, sendTransaction costs 20 cells without preflight and 70 with it. Signing stays in your software.
- The script itself: it does not reconnect, and a socket drop ends the run. In production wrap it in a loop that opens the subscription first and then runs the backfill. The backfill reads the latest 100 signatures, so a longer gap needs paging backwards within the 30 days. One process writes the store.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| A reward is paid twice after a reconnect. | Key every store on the signature and insert idempotently, as the script does. Act on a report once per signature. |
| A restart leaves a hole in the data. | On every start, subscribe first and then run the backfill, so nothing between the two reads is lost. For a gap longer than the latest 100 signatures, page getSignaturesForAddress backwards within the 30 days. |
| Failed transactions are counted as device reports. | Store err with each row and filter on it before any payout. |
| One socket per device exhausts the account's sockets. | Subscribe once per program with a mentions filter and fan out in your own code. Free carries 5 sockets. |
| Polling the whole registry returns 429s. | Each pubkey in getMultipleAccounts costs 10 cells. Read only the devices that appeared in the log feed. |
| accountSubscribe on a device wallet never fires. | A plain SOL wallet stays silent. Use logsSubscribe mentions plus getBalance. |
Questions
Does Carbium store my device data?
No. It serves the chain side: RPC reads, subscriptions and a 30-day address index. Sensor payloads and anything else held off chain stay in your own pipeline.
Can I list every device account with getProgramAccountsV2?
getProgramAccountsV2 is one of the methods not served and it answers -32601. Build the registry from the log feed, then read accounts with getMultipleAccounts, up to 100 pubkeys per call below Pro and 300 on Pro.
WebSocket or gRPC for the report feed?
Start with WebSocket logs on any plan. The gRPC stream opens on Dev, Business and Pro at port 9443 with the key in x-token, and Free is off.