services
Get a key

library / Use cases / UC0018

Wallet profiles and feeds

A wallet address doubles as a profile id. Read a wallet's balance, token accounts and newest transactions, keep the transactions in SQLite as a feed, and leave follows, names, posts and reactions in your own database.

By Carbium · Social, messaging and identity · UC0018 · updated 2026-11-22

01

A profile is a wallet address

A social product on Solana starts with an identity every user already has. The wallet address needs no sign-up form and no password reset, and its owner proves control by signing. A profile page is a lookup by address. A display name, a bio and an avatar go in your own table keyed by that address, together with the follow list and the mute list, because those change often and users expect to delete them.

The chain supplies what nobody can fake: the SOL a wallet holds, the tokens it holds and the transactions it signed or was named in. Read those three for each followed wallet and keep the newest transactions in a local SQLite file. A feed page is then one SELECT, and the RPC is called only to catch up.

02

Profile fields and their source

FieldCallNote
SOL balancegetBalanceLamports, 1,000,000,000 to the SOL
Token accountsgetTokenAccountsByOwnerOne read per token program, original and Token-2022
Feed rowsgetSignaturesForAddressNewest first, with blockTime, err and the signature
Row detailgetTransactionFee, fee payer and instructions; null for some old signatures
Names, bios, followsYour databaseNothing on chain to read

For the token side in depth, see Wallet token holdings.

03

The script

Run it with one or more wallet addresses. With none, it takes the newest signatures of the original Token program, which sees transactions all the time, reads the first transaction it can, and uses that transaction's fee payer as the wallet to show. For each wallet it prints the SOL balance and the token account counts under both token programs, refreshes the feed table, and prints the ten newest rows across all wallets. It exits with a message when CARBIUM_KEY is unset and sends nothing.

main.ts
// UC0018 · Wallet profiles and feeds// https://carbium.sh/library/usecase/wallet-profiles-and-feeds// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: a wallet profile (balance, token accounts) plus a feed of its newest transactions, cached in SQLite.import { DatabaseSync } from "node:sqlite";import { address, signature, 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 url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";// One client, reused for every call.const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const commitment = "confirmed" as const;const TOKEN = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";type Tx = { meta: { fee: bigint | number } | null; transaction: { message: {  accountKeys: { pubkey: string }[]; instructions: { program?: string; parsed?: unknown }[] } } };// maxSupportedTransactionVersion 1 keeps a v1 transaction from answering -32015.const getTx = async (sig: string) => (await rpc  .getTransaction(signature(sig), { commitment, encoding: "jsonParsed", maxSupportedTransactionVersion: 1 })  .send()) as unknown as Tx | null;const show = <T>(p: Promise<T>, f: (v: T) => string) => p.then(f, (e: unknown) => `failed (${e})`);const db = new DatabaseSync("feed.db");db.exec(`CREATE TABLE IF NOT EXISTS follows (wallet TEXT PRIMARY KEY, newest TEXT);CREATE TABLE IF NOT EXISTS posts (sig TEXT PRIMARY KEY, wallet TEXT, block_time INTEGER, ok INTEGER, payer INTEGER, fee INTEGER, memo TEXT);`);async function findWallet(): Promise<string> {  const sigs = await rpc.getSignaturesForAddress(address(TOKEN), { commitment, limit: 10 }).send();  for (const s of sigs) {    const payer = (await getTx(s.signature).catch(() => null))?.transaction.message.accountKeys[0]?.pubkey;    if (payer) return payer;  }  throw new Error("no recent transaction could be read");}async function profile(wallet: string) {  const a = address(wallet);  const count = (programId: string) => show(    rpc.getTokenAccountsByOwner(a, { programId: address(programId) }, { commitment, encoding: "jsonParsed" }).send(),    (r) => String(r.value.length));  const [sol, tokens, tokens22] = await Promise.all([    show(rpc.getBalance(a, { commitment }).send(), (r) => `${Number(r.value) / 1e9} SOL`),    count(TOKEN), count(TOKEN_2022)]);  console.log(`${wallet}: ${sol}, ${tokens} Token accounts, ${tokens22} Token-2022 accounts`);}async function refresh(wallet: string): Promise<number> {  const row = db.prepare("SELECT newest FROM follows WHERE wallet = ?").get(wallet) as { newest: string } | undefined;  // Only signatures newer than the stored one, newest first.  const sigs = await rpc.getSignaturesForAddress(address(wallet), {    commitment, limit: 5, ...(row ? { until: signature(row.newest) } : {}) }).send();  const txs = await Promise.allSettled(sigs.map((s) => getTx(s.signature)));  const put = db.prepare("INSERT OR REPLACE INTO posts VALUES (?, ?, ?, ?, ?, ?, ?)");  sigs.forEach((s, i) => {    const r = txs[i];    if (r.status === "rejected") console.error(`getTransaction ${s.signature.slice(0, 8)} failed: ${r.reason}`);    const tx = r.status === "fulfilled" ? r.value : null; // null: below the ledger floor    const memo = tx?.transaction.message.instructions.find((ix) => ix.program === "spl-memo")?.parsed;    put.run(s.signature, wallet, s.blockTime === null ? null : Number(s.blockTime), s.err === null ? 1 : 0,      tx ? Number(tx.transaction.message.accountKeys[0]?.pubkey === wallet) : null,      tx?.meta ? Number(tx.meta.fee) : null, typeof memo === "string" ? memo : null);  });  if (sigs[0]) db.prepare("INSERT OR REPLACE INTO follows VALUES (?, ?)").run(wallet, sigs[0].signature);  return sigs.length;}const wallets = process.argv.slice(2);try { if (wallets.length === 0) wallets.push(await findWallet()); }catch (e) { console.error(`Could not pick a wallet: ${e}`); process.exit(1); }for (const w of wallets) {  await profile(w);  const added = await refresh(w).catch((e: unknown) => { console.error(`${w}: feed refresh failed: ${e}`); return 0; });  console.log(`  ${added} new transactions stored`);}const feed = db.prepare("SELECT sig, wallet, block_time, ok, payer, fee, memo FROM posts ORDER BY block_time DESC LIMIT 10").all();for (const r of feed) {  const when = r.block_time === null ? "time unknown" : new Date(Number(r.block_time) * 1000).toISOString();  console.log(`${when}  ${String(r.wallet).slice(0, 8)}  ${r.payer === 1 ? "paid" : "mention"}  ${r.ok === 1 ? "ok" : "failed"}  fee ${r.fee ?? "?"}  ${String(r.sig).slice(0, 12)}  ${r.memo ?? ""}`);}

run: CARBIUM_KEY=$CARBIUM_KEY node main.ts [<wallet> ...]

Each call settles on its own, so a failed read prints one line and the run goes on. A failed getTransaction still stores its row with the fee and payer empty, and the signature is not asked for again. The posts table is keyed by signature, so a repeat insert replaces the row.

getTransaction runs with jsonParsed encoding and maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and a call that omits the field answers -32015, uncharged, for a v1 transaction.

04

Catching up instead of rereading

The follows table keeps the newest signature seen for each wallet. The next refresh passes it as until, so getSignaturesForAddress returns only newer signatures, and an idle wallet costs one call that returns an empty list. Each new transaction then costs one getTransaction.

Both calls cost 50 cells. Refreshing three wallets with five new transactions each is 18 calls, or 900 cells. A rate class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger, which is about 20 calls of 50 cells on Free and Dev. The signatures call runs at 0.24 req/s on Free and 1.2 on Dev, so a Free key follows a handful of wallets and spaces out the rest.

When more than five signatures are new, the call returns the newest five and the older ones sit in a gap. A catch-up job pages with before until it reaches the stored signature.

05

Posts, payers and mentions

A row is a transaction that names the wallet, which is wider than what the wallet did. The script stores four columns to tell the cases apart.

  • payer: 1 when the wallet is the first account key, the fee payer, so the wallet chose to send it. A transaction from someone else that lists the wallet is a mention, and anyone can create one. A wallet that co-signs without paying shows 0, so read the signer flags when that matters.
  • memo: the text of a Memo program instruction. It writes a UTF-8 string into the transaction, so it works as a post with no program of your own. The script reads memos other wallets wrote; writing one needs a signature, and this code never signs. A memo is public and permanent, so a delete button in your UI only hides it.
  • ok: 1 when err is null. A failed transaction still pays its fee, and it is still a row.
  • fee: the lamports paid, from meta.fee, or empty when the transaction could not be read.
06

When the feed must move

Polling on page load or on a timer fits most products. For push, logsSubscribe with a mentions filter fires on any transaction that lists the address, while a plain SOL wallet sends no accountSubscribe notifications. A logs-mentions subscription opens at 25 credits and then costs 20 credits per MiB sent. Free carries 5 sockets, so open one socket on your server and subscribe only to wallets someone is looking at now. On each notification, run the same refresh for that wallet, so one code path fills the table. Wallet social feed wires the stream end to end.

07

Where it ends

  • History stops at 30 days. getSignaturesForAddress reads an address index that keeps up to 30 days, and an empty page past that is the index's age limit. A user who follows an old wallet sees a month, and the wallet may have more. Store rows from the day a user joins if you promise longer. Some older signatures the index lists answer null from getTransaction, which the script stores as a bare row.
  • Incoming token transfers are missing. A token transfer to an existing token account lists the token accounts and the sender's authority, and the receiving wallet's address is absent. The wallet's own signature list does not show it. Reading each token account's signatures covers it at 50 cells a call.
  • Names, avatars, bios and follows are yours to store. The chain holds none of them.
  • The script never signs, so there are no on-chain posts, likes or tips written by this code. A write path is yours to build and test.
  • A row says what happened in one line of fields. Turning a swap or a transfer into a sentence needs the instruction data, and jsonParsed decodes only the programs the node knows.
  • Balance and token counts are the state at the moment of the read.
08

When it goes wrong

what goes wrongwhat to do
getTransaction answers -32015.Send maxSupportedTransactionVersion: 1 with an encoding. Without it, mainnet answers -32015, uncharged, for a v1 transaction or a block holding one.
A listed signature has no detail and the row shows an empty fee.Older signatures from the address index can sit below the validator's ledger floor and answer null. Keep the bare row and test the code on the newest signatures.
The feed shows rows the wallet never sent.Filter on payer = 1 or keep a mute list. Anyone can name your wallet in a transaction, and it lands in the wallet's signature list.
A refresh after a busy spell skips transactions.The call returns the newest five. Page with before until you reach the stored signature, then move the stored value forward.
Refreshing many wallets answers 429.Space the calls to your plan's rate. Limits are per account, so every key on the account draws on one budget.
A plain SOL wallet gets no push updates from accountSubscribe.Subscribe with logsSubscribe and a mentions filter, then run the wallet's refresh on each notification.
09

Questions

Where do posts and likes live?

Likes, comments, names and follows go in your own database, where an edit or a delete stays possible. A post that must be public and permanent can be a Memo transaction signed by the wallet, and this script only reads those.

Why store the feed in SQLite at all?

A page load then costs no RPC call, and the stored rows outlive the 30 days the address index keeps. The follow list and the feed share one file and one query.

Can I refresh many wallets in one request?

A JSON-RPC post can carry a batch of up to 100 calls with no added envelope. The kit client sends one call per request, so post the batch yourself with the same x-api-key header. Each call still costs its own cells.