services
Get a key

library / Integrations / Chat and notifications / I0119

Discord prize payout feed

A small Node watcher follows your payout wallet every 10 seconds, reads each new transaction for token and SOL payouts, and posts one Discord message per paying transaction with each amount, token and receiving address.

By Carbium · Chat and notifications · I0119 · updated 2026-11-23

01

What lands in the channel

The watcher follows one payout wallet, the account your game or tournament pays prizes from. Every 10 seconds it asks Carbium for the wallet's new signatures, reads each successful transaction, and posts one Discord message per transaction that paid someone. Players see the amount, the token and the recipient address in the channel shortly after the transfer lands.

A transaction is read as a payout only when the wallet gives something up and another account receives it.

Movement in the transactionCountedLine in the message
The wallet's balance of a mint falls and another owner's balance of that mint risesYes, one line per receiving owner25 of mint <mint> to <owner>
The wallet's SOL falls and another account's SOL risesYes, one line per receiving account0.5 SOL to <account>
The wallet only receives fundsNoDeposits stay out of the feed
The transaction failedNoA failed transaction still pays its fee but moves nothing else, so it is skipped

The first line of every message names the transaction signature, so a player or a moderator can look the payout up on any explorer.

02

Reading a payout off the chain

A token transfer instruction lists token accounts and the sender's authority, never the receiving wallet. So the watcher reads balances. getTransaction returns preTokenBalances and postTokenBalances, and each entry carries an owner, a mint and a raw amount in uiTokenAmount.amount. The watcher subtracts pre from post for every owner and mint pair. A wallet can own more than one token account for one mint, so amounts are summed per owner before the comparison.

SOL prizes show up in preBalances and postBalances, which line up with the account keys. With the jsonParsed encoding each key is an object holding the address as pubkey. Token accounts created for a new recipient are paid for in SOL by the wallet, so the watcher skips any account index that also appears in the token balances. Without that filter every first-time recipient would add a SOL line naming their token account.

Mainnet carries v1 transactions, and getTransaction called with maxSupportedTransactionVersion absent or 0 answers -32015 for them. The watcher sends 1. Both calls read at confirmed commitment.

The signature list comes from an address index that keeps up to 30 days, and its pages reach below the validator's ledger floor. For an older signature getTransaction can answer null. The watcher logs the signature, skips it and carries on. It reads only the newest signatures at start, so a null is rare.

03

The Discord side

In the channel's settings open Integrations, then Webhooks, and create a webhook. Copy its URL into DISCORD_WEBHOOK_URL and treat it as a secret: whoever holds it can post to the channel.

The watcher POSTs a JSON body with content holding the message and allowed_mentions set to {"parse": []}, so an address or a signature can never ping anyone. Discord limits content to 2000 characters, and the code cuts a message at 1900.

The cursor, the newest signature already handled, moves only after Discord has answered with a success status. If Discord is down or the URL is wrong, the next poll sends the same transactions again. With DISCORD_WEBHOOK_URL unset the watcher prints each message to the console, which is the quickest way to see what a wallet would post before a channel exists.

04

The watcher

Install the one dependency with npm install @solana/[email protected] and set "type": "module" in package.json. Node 24 strips the types on load. The first argument is the payout wallet. With no argument the file takes the newest transaction that touched the Token program and follows its fee payer, which gives a busy wallet to try. CARBIUM_KEY is required and the file exits with a message when it is missing. DISCORD_WEBHOOK_URL and CARBIUM_RPC_URL are optional.

main.ts
// I0119 · Discord prize payout feed// https://carbium.sh/library/integrate/discord-prize-payout-feed// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, type Signature } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY."); process.exit(1); }const hook = process.env.DISCORD_WEBHOOK_URL; // unset: messages print onlyconst rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);const config = { maxSupportedTransactionVersion: 1, encoding: "jsonParsed", commitment: "confirmed" } as const;const TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";type Bal = { owner?: string; mint: string; accountIndex: number; uiTokenAmount: { amount: string; decimals: number } };const fmt = (raw: bigint, dec: number) => {  if (!dec) return raw.toString();  const s = raw.toString().padStart(dec + 1, "0");  return `${s.slice(0, -dec)}.${s.slice(-dec)}`.replace(/\.?0+$/, "");};// No argument: follow the fee payer of the newest Token program transaction.async function pickWallet(): Promise<string> {  const [s] = await rpc.getSignaturesForAddress(address(TOKEN_PROGRAM), { limit: 1, commitment: "confirmed" }).send();  const tx = s ? await rpc.getTransaction(s.signature, config).send() : null;  const payer = tx?.transaction.message.accountKeys[0]?.pubkey;  if (!payer) throw new Error("no wallet found; pass one as the first argument");  return String(payer);}async function payouts(sig: Signature, wallet: string): Promise<string[]> {  const tx = await rpc.getTransaction(sig, config).send();  if (!tx?.meta) { console.log(`${sig}: no transaction body served, skipped`); return []; }  const { meta } = tx;  const delta = new Map<string, { owner: string; mint: string; raw: bigint; dec: number }>();  const add = (list: readonly Bal[] | null | undefined, sign: bigint) => {    for (const b of list ?? []) {      if (!b.owner) continue;      const k = `${b.owner}|${b.mint}`;      const d = delta.get(k) ?? { owner: b.owner, mint: b.mint, raw: 0n, dec: b.uiTokenAmount.decimals };      d.raw += sign * BigInt(b.uiTokenAmount.amount);      delta.set(k, d);    }  };  add(meta.preTokenBalances, -1n); add(meta.postTokenBalances, 1n);  const all = [...delta.values()]; const lines: string[] = [];  for (const out of all.filter((d) => d.owner === wallet && d.raw < 0n))    for (const r of all.filter((d) => d.mint === out.mint && d.owner !== wallet && d.raw > 0n))      lines.push(`${fmt(r.raw, r.dec)} of mint ${r.mint} to ${r.owner}`);  const keys = tx.transaction.message.accountKeys.map((k) => String(k.pubkey)); const me = keys.indexOf(wallet);  const change = (i: number): bigint => BigInt(meta.postBalances[i]) - BigInt(meta.preBalances[i]);  const tokenAccounts = new Set([...(meta.preTokenBalances ?? []), ...(meta.postTokenBalances ?? [])].map((b) => b.accountIndex));  if (me >= 0 && change(me) < 0n)    keys.forEach((k, i) => { if (i !== me && !tokenAccounts.has(i) && change(i) > 0n) lines.push(`${fmt(change(i), 9)} SOL to ${k}`); });  return lines;}async function announce(sig: string, lines: string[]) {  const content = [`Prize payout in ${sig}`, ...lines].join("\n").slice(0, 1900);  console.log(content);  if (!hook) return;  const res = await fetch(hook, {    method: "POST",    headers: { "content-type": "application/json" },    body: JSON.stringify({ content, allowed_mentions: { parse: [] } }),    signal: AbortSignal.timeout(5_000),  });  if (!res.ok) throw new Error(`Discord answered ${res.status}`);}let newest: Signature | undefined; // cursor: moves only after a message went outasync function poll(wallet: string) {  const sigs = await rpc.getSignaturesForAddress(address(wallet), { limit: newest ? 1000 : 5, until: newest, commitment: "confirmed" }).send();  if (!newest) console.log(`watching ${wallet}: ${sigs.length} recent signatures read`);  for (const s of [...sigs].reverse()) {    if (!s.err) {      const lines = await payouts(s.signature, wallet);      if (lines.length) await announce(s.signature, lines);    }    newest = s.signature;  }}const wallet = process.argv[2] ?? (await pickWallet());for (;;) {  try {    await poll(wallet);  } catch (e) {    console.error("poll failed:", e instanceof Error ? e.message : e);  }  await new Promise((r) => setTimeout(r, 10_000));}

run: node main.ts

05

Run it

Start it with node main.ts <wallet>. The first poll reads the wallet's newest 5 signatures, so a wallet that paid someone recently produces a message at once. Later polls ask only for signatures newer than the cursor, up to the 1000 a page allows.

Run it under a supervisor such as a systemd unit so it survives a crash or a reboot. The cursor lives in memory. After a restart the first poll reads the newest 5 signatures again, and any payout among them posts a second time.

06

What it costs against your limits

getSignaturesForAddress costs 50 cells, and Free allows 0.24 req/s of it where Dev allows 1.2. One poll every 10 seconds is 0.1 req/s. getTransaction also costs 50 cells and has the same Free rate of 0.24 req/s, so a Free key keeps up with a new transaction about every 4 seconds sustained.

A rate class absorbs a burst of up to 1,024 cells, so the start of a run is safe: one signature page and 5 transactions come to 300 cells, and the default wallet lookup adds 100. Limits are per account, so all your keys share one budget. A call that stays over its rate fails with a 429, the poll stops with the cursor unmoved, and the next poll retries.

07

Where it ends

  • It reports balance changes, so a payout that a program moves out of a vault shows no loss on the wallet. Follow the vault address in that case.
  • It does not know who won or what was owed. Matching payouts to a winners list is a job for your own records; Game prize pool tracker covers the pool side.
  • A poll every 10 seconds means the message trails the transfer by up to that long, and it is not a live subscription.
  • A restart reposts payouts among the newest 5 signatures, because the cursor is not stored.
  • A tip transfer to another account in the same transaction shows as a SOL line.
  • History stops at 30 days, so a wallet's older payouts cannot be backfilled.
08

When it goes wrong

what goes wrongwhat to do
The log shows poll failed: Discord answered 404 and the same transactions are retried every 10 seconds.The webhook was deleted or the URL was cut short. Create a new webhook, copy the whole URL into DISCORD_WEBHOOK_URL and restart.
The log shows Discord answered 429 during a busy payout round.Discord rate limits each webhook. The cursor stays on the last message that went out, so the remaining payouts post on later polls. For large rounds, post fewer messages by paying in fewer transactions or adding a delay between posts.
A signature prints no transaction body served, skipped.getTransaction answered null for a signature older than the validator's ledger floor, which the 30-day address index can still list. Nothing is wrong with the key. Run against a wallet with recent activity.
Calls fail with an HTTP 401 and no payouts appear.An unknown key is refused at the door. Check that CARBIUM_KEY holds the whole key and that CARBIUM_RPC_URL, when set, points at https://services.carbium.sh.
The wallet paid players and the channel stays empty.The funds left through a program or another authority, so the wallet's own balances did not fall. Run the watcher on the vault or authority address that the funds leave from.
The log shows poll failed with a 429 from Carbium on a Free key.Transactions arrived faster than Free's getTransaction rate. The cursor has not moved and the next poll retries. Spread payouts over time or move to a plan with a higher rate.
09

Questions

Why poll instead of subscribing to logs?

A logs subscription with a mention filter streams the wallet's transactions as they land and opens at 25 credits. Polling is simpler for one wallet and has a cursor, so a dropped connection loses nothing. A subscription needs a reconnect and a gap fill of its own.

Does it handle prizes paid in SOL?

Yes. It compares lamport balances for the wallet and the other accounts in the transaction, and it posts a SOL line when the wallet's balance falls and another account's rises.

Can one process follow several payout wallets?

The file follows one wallet. Run one copy per wallet. They share the account's budget, so add up their polls against your plan's rate.

Where do I get the webhook URL?

Open the channel's settings in Discord, choose Integrations, then Webhooks, and create one. The URL it shows goes into DISCORD_WEBHOOK_URL.