Skip to content
onchain-engineeringusdcstablecoin-billing
Joshua C.

Programmatic Cancellation and Update of Onchain USDC Billing Caps

Learn how to programmatically let customers update or cancel recurring USDC billing caps onchain for stablecoin subscriptions, with a worked example and code.

Programmatic Cancellation and Update of Onchain USDC Billing Caps

Recurring billing with stablecoins gives your customers granular control over what they spend. The cap they approve is visible, onchain, and enforced by the protocol. But sometimes, a customer needs to cancel an approval, or update the cap upward or downward. As a developer, you need to support these flows in your product, and handle them cleanly onchain.

Key Concepts: ERC-20 Approvals and Bounded Authorizations

Recurring payments with USDC use the ERC-20 approve() function. The customer, from their wallet, approves a capped amount spendable by a merchant contract. That cap is the maximum that can be pulled until the customer changes it. No unlimited approvals are used. Each approval is an explicit transaction, visible onchain.

When a customer wants to stop future billing, they revoke the approval. To raise or lower the cap, they submit a new approval for the new amount. These are standard ERC-20 flows. The Reclack API and UI guide the customer through the process. Your backend, and your subscription logic, need to watch for these changes and adapt.

Cancelling a Recurring USDC Billing Cap: Mechanics and Signals

To cancel, the customer sets the allowance for your merchant contract to zero. This is a transaction from their wallet. Once mined, your contract can no longer pull USDC from the customer’s balance.

The signals you need to watch for:

  • Onchain: The ERC-20 Approval event, showing a new allowance of zero for your contract
  • Offchain: A webhook or polling job that syncs onchain allowances with your billing state

If you attempt a transfer after allowance is zero, the transaction reverts. The payment fails, and your app should not retry until a new approval is in place.

Example: Cancel a USDC Approval on Ethereum

Suppose your contract address is 0xMerchant0123..., and the customer wallet is 0xUser4567.... The process is:

  1. Customer submits a transaction via their wallet:
IERC20(USDC_ADDRESS).approve(0xMerchant0123..., 0);
  1. The USDC contract emits:

    Approval(owner=0xUser4567..., spender=0xMerchant0123..., value=0)
    
  2. Your backend sees this event. You update the subscription to cancelled, and stop future charges.

Updating a USDC Billing Cap: Mechanics and User Flow

To increase or decrease the billing cap, the customer signs another approve() transaction, setting a new maximum. The new cap replaces the old one. Only this new amount is available for future recurring charges.

A customer may want to reduce risk by lowering the cap. Or they may want to increase it to cover higher usage. Your UI should explain the consequences: after a lower cap, any attempt to pull more than the new maximum will revert, causing the payment to fail. After a higher cap, the new upper bound applies, but only up to that explicit limit.

Example: Update a USDC Recurring Cap from $500 to $200

Assume USDC has 6 decimals. $500 is 500000000. $200 is 200000000. The approval must match those units.

  1. Current allowance: 500000000 (for your contract)
  2. Customer wants to lower the cap to $200
  3. Customer submits:
IERC20(USDC_ADDRESS).approve(0xMerchant0123..., 200000000);
  1. USDC contract emits:

    Approval(owner=0xUser4567..., spender=0xMerchant0123..., value=200000000)
    
  2. Your backend receives this event, updates the subscription cap to $200, and reflects this in the customer portal.

Monitoring and Surfacing Cap Changes in Your Product

You need to sync onchain state with your billing engine. There are two ways:

  • Subscribe to ERC-20 Approval events for your merchant contract, filtered by customer address
  • Poll the USDC allowance using allowance(owner, spender)

If a customer cancels or updates the cap, your backend should:

  • Mark the subscription as cancelled, paused or capped
  • Notify the customer and merchant in the UI or via webhook
  • Prevent future billing attempts that exceed the new cap

Sample Code: Checking Allowance Before Billing

Before attempting a transfer, make sure the allowance is still sufficient. Example in JavaScript (ethers.js):

const usdc = new ethers.Contract(USDC_ADDRESS, ERC20_ABI, provider);
const allowance = await usdc.allowance(customerAddress, merchantContractAddress);
if (allowance.gte(requestedAmount)) {
  // Proceed with charge
} else {
  // Pause subscription, notify customer
}

Handling Failed Charges and Customer Support

If a charge fails due to a revoked or lowered cap, your product should:

  • Surface a clear status in the customer portal: “Approval revoked” or “Cap too low”
  • Send a notification to the customer and merchant
  • Offer a flow to reauthorize or update the cap

Do not attempt further charges until a new approval is signed and mined.

Revocation and Update Patterns: Best Practices

  • Always show customers the current cap before they sign
  • Make it easy to cancel or lower the cap, and explain what this means for service
  • After an update, fetch the latest allowance and update UI and backend state
  • Do not store or infer approval state offchain without syncing onchain events
  • Never attempt charges above the onchain allowance

Worked Example: End-to-End Flow

A SaaS customer has a $100 monthly USDC subscription using Reclack. They want to pause service for a month.

  1. Customer navigates to the portal and clicks “Pause subscription”
  2. Portal presents the cancel approval flow
  3. Customer signs an approve() to set the allowance to zero
  4. The Approval event is picked up by your backend
  5. Reclack marks the subscription as paused. No further charges are attempted
  6. Next month, customer resumes service. They sign a new capped approval, for $100
  7. Subscription resumes with the new cap in place

All state changes are visible to both customer and merchant, and are enforced by the onchain allowance. No funds ever touch Reclack custody. No unlimited approvals are used. Each cap is explicit, signed, and visible.

How We Handle Cap Updates and Cancellations at Reclack

We built Reclack to help you manage recurring USDC billing caps safely. Every recurring authorization is capped by design. Customers can cancel or update at any time, and our API and portal reflect onchain state in real time. We never ask for custody or private keys, and all approvals are explicit and bounded. If you want to see how this works in your own product, visit us at https://reclack.com.

onchain-engineeringusdcstablecoin-billing