Building Webhooks for Onchain USDC Subscription Events
Learn how to build webhooks that track onchain USDC subscription renewals and failures. Includes sample payloads, event mapping, and error handling patterns.
Tracking onchain USDC subscription renewals and failures in real time is critical for SaaS, marketplaces, and any crypto business relying on non-custodial billing. Webhooks are the bridge between settled blockchain payments and your internal systems. This guide walks through mapping onchain events to webhook payloads, handling renewals, detecting failures, and integrating the flow with your product.
Webhooks and Onchain Subscription Billing
When a customer pays a USDC subscription onchain, their wallet initiates a transfer each renewal. Each payment is a regular ERC-20 transfer, not a pull from the merchant. Your system needs to know when these renewals settle, and when they fail. Webhooks provide the notification layer, delivering payment status events to your backend as soon as the chain confirms them.
What Makes Onchain Payment Events Unique
With USDC on Base, Ethereum, or Polygon, every renewal is a signed transaction from the customer’s wallet. There is no concept of chargeback or reversal after confirmation. Failures show up as missing payments or onchain errors, not as a reversal post-settlement. Webhook design must handle this difference.
Core Events: Renewal and Failure
Your system should map at least two key events for every subscription:
- Subscription Renewal: Onchain settlement of a USDC transfer for the correct amount, within the expected renewal window.
- Subscription Payment Failure: No payment received by the due date, or a failed transaction (for example, out of gas, insufficient funds, cap reached).
Event Sources
Event triggers come from monitoring the chain for transfers to your settlement address, with filters for sender, amount, and timing. You can use a node, a third-party indexer, or a service like Reclack to surface these events.
Designing the Webhook Payload
A good webhook payload includes all the data your backend needs to attribute the payment. At minimum, include:
event_type:subscription_renewalorsubscription_failuresubscription_id: your internal identifiercustomer_wallet: wallet address payingamount: USDC amount paid or expectedchain:ethereum,polygon, orbasetx_hash: transaction hash (for renewals)block_number: settlement block (for renewals)timestamp: event timestampfailure_reason: code or message (for failures)
Example: Renewal Webhook Payload
{
"event_type": "subscription_renewal",
"subscription_id": "sub_0012A",
"customer_wallet": "0x3cab1d7eA9dC1e476D7bE5Dd5B5C4B6A6E5C1F4B",
"amount": "100.00",
"chain": "polygon",
"tx_hash": "0x12f3c4ad6f...",
"block_number": 5432123,
"timestamp": "2024-06-14T09:32:12Z"
}
Example: Failure Webhook Payload
{
"event_type": "subscription_failure",
"subscription_id": "sub_0012A",
"customer_wallet": "0x3cab1d7eA9dC1e476D7bE5Dd5B5C4B6A6E5C1F4B",
"amount": "100.00",
"chain": "polygon",
"failure_reason": "insufficient_funds",
"timestamp": "2024-06-15T09:32:12Z"
}
Monitoring Onchain Events
Tracking Renewals
To detect a renewal, listen for a USDC transfer to your settlement address that matches:
- The expected token contract (USDC address on each chain)
- The sender wallet bound to the subscription
- The amount and timing window for the period
You can use a tool like ethers.js, web3.py, or a service to scan for these events. Here’s an example with ethers.js:
const { ethers } = require("ethers");
const usdcAbi = [
"event Transfer(address indexed from, address indexed to, uint256 value)"
];
const usdcAddress = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; // Polygon USDC
const provider = new ethers.JsonRpcProvider("https://polygon-rpc.com");
const contract = new ethers.Contract(usdcAddress, usdcAbi, provider);
contract.on("Transfer", (from, to, value, event) => {
if (to.toLowerCase() === merchantAddress &&
from.toLowerCase() === customerAddress &&
value.eq(ethers.parseUnits("100", 6))) {
// Fire your webhook for subscription_renewal
sendWebhook({
event_type: "subscription_renewal",
subscription_id: "sub_0012A",
customer_wallet: from,
amount: "100.00",
chain: "polygon",
tx_hash: event.transactionHash,
block_number: event.blockNumber,
timestamp: new Date().toISOString()
});
}
});
You can batch this with periodic checks, or listen for real-time events. For large scale, index events and scan block ranges for matches.
Detecting Failures
Failures are not always onchain events. Often, they are the absence of a renewal by a deadline. Your backend should track the subscription schedule and trigger a failure event if no payment arrives by the end of the grace period.
For example, if a renewal is due by 2024-06-15T09:32:12Z, and you have seen no matching transfer, fire a subscription_failure webhook. Reasons can include:
- No funds in the customer wallet
- ERC-20 cap reached (approval exhausted)
- The customer cancels approval
- Transaction failed (reverted, out of gas)
Some errors, like a reverted transaction, may be visible if you monitor the mempool or failed tx receipts, but most failures are detected by schedule.
Handling Webhook Delivery and Idempotency
Onchain events are final once confirmed, but webhook delivery is not. Always include an idempotency key, such as the tx hash or a composite key of event_type + subscription_id + timestamp. Your backend should de-duplicate repeated payloads.
If your webhook endpoint is temporarily unavailable, queue and retry delivery. Do not rely on a single notification for critical events.
Worked Example: Billing a Customer and Tracking Outcomes
Suppose you bill a customer 100 USDC monthly on Polygon. The settlement address is 0xaabb...ccdd. Your backend expects a payment each month by the 10th.
- On June 8th, you detect a USDC transfer of 100 USDC from
0x3cab...f4bto0xaabb...ccddin block 5432123. You trigger asubscription_renewalwebhook. - On July 10th, no matching transfer is detected. The customer’s USDC balance is 72. No transaction is seen in the mempool or onchain. You trigger a
subscription_failurewebhook, with reasoninsufficient_funds.
This lets your product unlock or suspend access based on confirmed, irreversible onchain outcomes.
Mapping Subscription States to Internal Systems
Webhooks should update your ledger and user state. On renewal, mark the period as paid and extend access. On failure, set the subscription as delinquent or paused. Always reconcile against onchain settlement, not intent or mempool activity.
Security and Customer Impact
Never trigger business actions on mempool intent alone. Only confirmed onchain events should update your product. Chargebacks are not possible, and once the webhook is fired, the payment is final. Communicate this to customers to set expectations.
Reclack and Onchain Webhooks
We built Reclack so you do not have to monitor the chain or parse ERC-20 events directly. Reclack tracks renewals and failures for USDC subscriptions on Base, Ethereum and Polygon, and delivers webhooks to your endpoints with all the fields in these examples. Our webhooks are idempotent and reflect only confirmed onchain activity. We never hold funds or ask for private keys. See https://reclack.com for API details and event schema.


