Skip to main content
Watch a wallet without polling: a balance.changed webhook pushes the account’s new balance for an asset after every ledger that changes it. This recipe runs a small receiver that verifies each delivery with the Lumeus verifier and prints an alert when the XLM balance drops below a threshold. You need a webhook key (whk_..., from Webhooks > Webhook keys in the dashboard) and a public HTTPS URL for your receiver, such as a cloudflared tunnel to localhost:3000. Your first webhook shows the tunnel setup step by step.
The sample account is the Testnet Friendbot. Its balance changes in about 240 ledgers an hour, so a subscription to it uses the Free plan’s 1,000 deliveries a day in about 4 hours; the endpoint then pauses until 00:00 UTC. Point ACCOUNT at your own wallet for a quiet stream, and delete the subscription when you are done.

1. Subscribe

Create a subscription for one account’s balance changes. The response holds the signing secret (hmac_secret) only once. The command saves it to webhook-secret.txt on success and refuses to overwrite an existing file; to retry a failed create, run it again in the same shell so it reuses CREATE_KEY:
asset: "native" limits it to XLM; leave it out to get every asset the account holds. balance.changed leaves out changes caused only by transaction fees; use balance.changed.fees to include them. Deliveries start after the subscription is active (usually right away; see Lifecycle).

2. Run the receiver

The receiver verifies each delivery with the shared verifier: the body signature, the timestamp and the signed delivery context (event id, network, lane and body hash), with both secrets during a key rotation. It records the event under the unique key (network, id), checks the threshold and only then answers 204. Keep that work fast: deliveries to one endpoint go one at a time, so a slow answer delays the next event. In production, insert the event into your database and enqueue the alert instead of printing it. Download the verifier for your language next to the receiver:

3. What arrives

Each delivery body is one balance.changed event. This one, for the sample account, is built from Testnet ledger 5330999, where nine 10,000 XLM transfers left the account:
The receiver prints:
  • One event per holder, asset and ledger: several changes in one ledger arrive as one event with the balance after the ledger.
  • balance is the new absolute balance, so a missed or repeated delivery never leaves your view wrong after the next one. Keep the event with the highest ledger per holder and asset.
  • Deduplicate on (network, id): delivery is at least once. See Deduplicate.

Limits and credits

Each attempt must get a 2xx within 10 seconds; a failed delivery is tried up to 8 times. See Receive and verify and Webhooks overview.

Next