Skip to content
Docs

Requests and responses

Polling for updates

Use webhooks for address activity, and poll receipts and balances on a sensible interval when you need to.

Overview

For activity on wallet addresses, use Webhooks: Gray3 pushes a signed message to your server when a watched address sends or receives funds on a supported EVM network. Polling is still the right tool for transaction receipts right after broadcast, for chains webhooks do not cover, and for refreshing balances while a user is looking at them. The read endpoints are cheap, cacheable, and cursor-based.

What to poll

  • Transaction confirmation (EVM chains): poll GET /v1/transactions/receipt after broadcast until the status is success or failed.
  • Incoming and outgoing transfers: poll GET /v1/activity and stop paging when you reach an item you have already stored.
  • Balances: refresh GET /v1/portfolio/multi when the user opens the wallet and after their own transactions confirm, rather than on a tight loop.
  • Swaps and bridges: poll GET /v1/routes/status with the transaction hash until the route is done or failed.

Example: wait for a receipt

javascript
async function waitForReceipt(gray, { chainId, hash }) {
  for (let attempt = 0; attempt < 40; attempt++) {
    const receipt = await gray.transactions.getReceipt({ chainId, hash });
    if (receipt.status === "success" || receipt.status === "failed") {
      return receipt;
    }
    // 1.5 to 2 seconds, with jitter so many clients do not poll in lockstep
    await new Promise((r) => setTimeout(r, 1500 + Math.random() * 500));
  }
  throw new Error("Timed out waiting for the receipt");
}

Choosing intervals

  • Poll receipts every few seconds for a short window after broadcast, then fall back to activity.
  • Poll activity and balances only while a user is actively viewing the wallet.
  • Add jitter and back off on 429. See Bursts and steady load.
  • Every poll costs credits. See Designing for cost.

On EVM and Bitcoin-family networks, a webhook on the address replaces most activity polling. See the Webhooks quickstart.