library / Blockchain ideas / Consumer and social / BI0119
Mutual wallet connections
You get a script that reads one wallet's newest transactions, sorts its counterparties into sent, received and both ways, and prints the mutual ones. A social app can turn that into friend suggestions with no follow button.
What a mutual connection is
A follow button asks one person to declare interest. A mutual connection is something the chain already recorded: wallet A sent SOL to wallet B, and B sent SOL to A. Neither side pressed anything, and neither can fake the other's half, because each half is a signed transaction that anyone can read.
Social apps use this shape for friend suggestions, trust badges and invite-only groups. The app shows a person the wallets that paid them and were paid back, ranked by how recent the exchange is. A wallet that only ever sends to you, such as a mass sender or a spammer, never qualifies, because the return half is missing.
| Pair state | What the chain shows | What an app does with it |
|---|---|---|
| Sent only | You paid them, they never paid you back | Show as someone you pay, no badge |
| Received only | They paid you, you never replied | Ignore by default, because anyone can send to any address |
| Both ways | Each wallet sent SOL to the other | Suggest as a connection and rank by recency |
Who uses it
The code only reads, so a team can show it working on live data with no deployed program and no test funds.
- A hackathon team builds a friends tab for a wallet app. The user connects an address and sees the wallets they already trade favours with, such as splitting a bill or repaying a loan.
- A community site marks members who have paid each other and uses that as a light trust signal next to a username.
- A group-chat or event app suggests invitees from the wallets the host has settled up with before.
The build
One file that needs @solana/kit and what Node 24 ships. It never signs or sends. Run it with a wallet address, or with no argument and it picks a recent sender from the System Program's newest signatures.
- Create one RPC client for https://services.carbium.sh and reuse it for every call.
- Call getSignaturesForAddress for the wallet with limit: 10 and drop the signatures whose err is set, since a failed transaction moved nothing.
- Fetch each remaining signature with getTransaction using encoding: "jsonParsed" and maxSupportedTransactionVersion: 1. All calls go out together, and Promise.allSettled keeps one failure from ending the run.
- Read the top-level instructions. A System Program transfer of at least 1,000,000 lamports (0.001 SOL) becomes a hop from source to destination. Smaller sends count as dust.
- Put the destinations of the wallet's own sends in one set and the sources of what it received in another. The overlap is the mutual list.
- Print the three groups, then the count of null transactions and failed calls so a thin result is explained.
// BI0119 · Mutual wallet connections// https://carbium.sh/library/blockchainideas/mutual-wallet-connections// 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;if (!key) { console.error("Set CARBIUM_KEY to your Carbium key first."); process.exit(1);}const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key }, }),);const MIN_LAMPORTS = 1_000_000; // 0.001 SOL: below this a send counts as dusttype Ix = { program?: string; parsed?: { type?: string; info?: { source?: string; destination?: string; lamports?: number } } };type Hop = { from: string; to: string };async function hops(who: string, limit: number) { const page = await rpc.getSignaturesForAddress(address(who), { limit }).send(); const sigs = page.filter((s) => !s.err).map((s) => s.signature); const reads = await Promise.allSettled( sigs.map((s) => rpc.getTransaction(s, { encoding: "jsonParsed", maxSupportedTransactionVersion: 1 }).send()), ); const list: Hop[] = []; let nulls = 0; let failed = 0; for (const r of reads) { if (r.status === "rejected") { if (failed++ === 0) console.error("first failed call:", String(r.reason).slice(0, 120)); continue; } if (!r.value) { nulls++; continue; } for (const ix of r.value.transaction.message.instructions as unknown as Ix[]) { const info = ix.parsed?.info; if (ix.program === "system" && ix.parsed?.type === "transfer" && info?.source && info.destination && (info.lamports ?? 0) >= MIN_LAMPORTS) { list.push({ from: info.source, to: info.destination }); } } } return { list, nulls, failed };}let wallet = process.argv[2];if (!wallet) { const seed = await hops("11111111111111111111111111111111", 20); wallet = seed.list[0]?.from; if (!wallet) { console.error("No transfer found to seed from; run again or pass a wallet."); process.exit(1); } console.log("no wallet given, seeded from a recent sender");}const { list, nulls, failed } = await hops(wallet, 10);const sent = new Set(list.filter((h) => h.from === wallet).map((h) => h.to));const received = new Set(list.filter((h) => h.to === wallet).map((h) => h.from));const mutual = [...sent].filter((a) => received.has(a));console.log(`wallet ${wallet}`);console.log(`mutual (${mutual.length}) ${mutual.join(" ") || "none in this window"}`);console.log(`sent only (${sent.size - mutual.length}) ${[...sent].filter((a) => !received.has(a)).join(" ")}`);console.log(`received only (${received.size - mutual.length}) ${[...received].filter((a) => !sent.has(a)).join(" ")}`);console.log(`transfers read ${list.length}, null ${nulls}, failed ${failed}`);
run: CARBIUM_KEY=<YOUR_KEY> node main.ts [<wallet>]
The code sets no commitment, so @solana/kit sends confirmed on both reads. That is fresh enough for a list that changes over days.
Reading the output
A run prints the wallet, then one line per group. The numbers on the last line tell you how much to trust the groups above it.
| Line | Meaning | Typical cause of a surprise |
|---|---|---|
| mutual | Addresses the wallet sent to and received from | Often empty after only 10 signatures |
| sent only | Addresses it paid and never saw pay back | A shop, an exchange deposit or a one-way gift |
| received only | Addresses that paid it | Unsolicited sends, which anyone can make |
| null | Signatures the index listed but getTransaction could not return | Transactions older than the validator ledger |
| failed | Calls that raised an error | Rate limits or a network error |
An empty mutual line after ten signatures is a common result, since most wallets pay a handful of addresses once. Raise limit or scan a wallet that settles up with friends often, and the line fills.
What it costs
One wallet check is one getSignaturesForAddress call at 50 cells plus up to ten getTransaction calls at 50 cells each, so 550 cells at most. The ten transaction reads, 500 cells, sit under the 1,024-cell burst a rate class absorbs, so one check clears at once on every plan. A run with no argument first reads 20 System Program transactions to find a wallet, 1,000 more cells in the same class, so on plans below Pro some of the wallet's own reads that follow can wait and come back 429. Deeper scans are limited by the getTransaction rate.
| Plan | getTransaction rate | 100 getTransaction calls past the burst |
|---|---|---|
| Free ($0) | 0.24 req/s | about 417 s |
| Dev ($20) | 1.2 req/s | about 83 s |
| Business ($250) | 5 req/s | about 20 s |
| Pro ($500) | 25 req/s | about 4 s |
For a friends tab, run the scan when a user opens the tab, store the result in your own table with the slot you read it at, and refresh a wallet at most every few minutes. A connection list changes slowly, so a cache of minutes loses nothing the user would notice. Limits are shared by every key on the account, so a background refresh job and the live app draw on one budget.
What to add next
- Scan a second wallet and join the results, so you can show the friends two users have in common. Pair it with the follow list in Wallet social feed.
- Page back through older signatures with the cursor logic in Signature history pagination, and stop at the 30-day index limit.
- Weight a connection by the number of exchanges and the sum of lamports in each direction, then sort the suggestions by that score.
- Read SPL token transfers as well. They list token accounts, so map each destination account to its owner through the owner field in the transaction's postTokenBalances before you add the pair.
- Store each mutual pair in node:sqlite with the signature that proved each half, so a user can tap a badge and see the evidence.
Where it ends
- History is the 30-day address index at most. A connection that was made earlier is invisible, and an empty page past that limit says nothing about older transactions.
- The index can list a signature that getTransaction cannot return, because its pages reach below the validator's ledger floor. The code counts those as null and moves on, so a result built on old signatures is thin.
- Only top-level System Program transfers count. A send made through a program, a swap, or an inner instruction does not show, and neither does any SPL token send.
- Anyone can send SOL to any address, so a received-only line proves nothing about the sender. Requiring both directions is the filter, and the dust floor stops a single lamport from counting as the return half.
- Two wallets can belong to one person, and exchange or payment wallets pay thousands of addresses. Mutual means two wallets moved SOL to each other. It does not prove two people know each other.
- The code reads only ten signatures. A wallet with heavy traffic pushes its older counterparties out of the window, so a real app pages deeper or keeps its own history from the day a user joins.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| getTransaction returns null for some signatures. | The address index lists signatures below the validator's ledger floor, so an older one can answer null. The code counts them in the null total and skips them. Prove the code on a wallet with recent activity and keep the scan window short. |
| getTransaction answers -32015. | The call left out maxSupportedTransactionVersion, or set it to 0, and the transaction is a v1 transaction. Keep maxSupportedTransactionVersion: 1 on the call. @solana/kit 8.6.0 accepts 1 without a cast, and a config object held in a variable needs as const. |
| The failed count is high and the lists are short. | Some calls came back 429. Ten transaction reads fit in one burst. A larger limit, or the no-argument run's 20 extra seed reads, does not fit on a plan below Pro. Pass a wallet, space the calls to your plan's getTransaction rate, or rerun the failed signatures after the retry-after hint. |
| The mutual line is empty for a wallet you know has friends. | Ten signatures can all belong to one busy program. Raise the limit and page back, or pass a wallet that mostly moves SOL between people. |
| A mutual pair turns out to be an exchange or a payment service. | Count each counterparty's distinct partners and drop any address that pays or is paid by many wallets, or keep a list of known service addresses. A real friend has a small circle. |
| The no-argument run finds no transfer to start from. | The newest signatures held no transfer above the dust floor. Run it again, or pass a wallet address on the command line. |
Questions
Why only SOL transfers?
A System Program transfer names its source and destination in plain fields, so the pair is read straight from the instruction. Token sends list token accounts and the sender's authority, never the receiving wallet, so they need an extra step to find owners.
Does a mutual connection mean two different people?
No. One person with two wallets creates the same pattern. Treat it as a hint for a suggestion list and let the user confirm the person.
How many signatures should I scan?
Start with ten for a live demo, then raise it to what your plan's getTransaction rate allows at the moment a user opens the page. For a full picture, store each wallet's rows yourself as you read them.
Can I find connections older than 30 days?
Not through getSignaturesForAddress, whose index keeps 30 days at most. Keep the pairs you find in your own table from the day a user joins, and the history grows from there.
Why jsonParsed and not raw transactions?
The jsonParsed encoding decodes System Program instructions into type and info fields, so the code reads source and destination directly. Raw data would need a byte-layout decoder for the same result.