Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 0 ๐Ÿ“– 4 min read

How to Verify an x402 Refund on Base

When an agent asks for a refund, it needs to know whether the money reached the wallet that paid. In our eSIM test, the supplier cancelled the profile, the seller reported a refund, and Base recorded 0.31 USDC moving bac

How to Verify an x402 Refund on Base

When an agent asks for a refund, it needs to know whether the money reached the wallet that paid. In our eSIM test, the supplier cancelled the profile, the seller reported a refund, and Base recorded 0.31 USDC moving back to the agent. Each step told us something different.

ReloadPi published three transfers from a different path: a carrier rejected a mobile top-up, and the seller refunded it. Comparing those public receipts with our eSIM run gives us a concrete way to check a payout when an order API and a payment rail report state independently. ReloadPi implementation report

What the receipts show

Case What triggered the refund What we checked on Base
ModelMarket eSIM Kit The buyer asked to cancel an uninstalled eSIM in a controlled mainnet test. A 0.31 USDC payment and a 0.31 USDC return between the same wallets in reverse.
ReloadPi ReloadPi reports three separate top-ups rejected by the carrier. Three transfers of 1.61 USDC each. All three reverse the direction of the payment shown in the public report.

The eSIM Kit case has a full order timeline. The kit checked the profile at the wholesale provider, cancelled it, and signed a separate USDC transfer back to ARGUS, about 34 minutes after the purchase. Test record ยท Payment receipt ยท Refund receipt

For ReloadPi, the carrier outcome comes from the operator's report. A USDC receipt has wallet addresses, an amount, and a block, so these examples alone leave the per-order mapping and retry behavior unverified. The same wallets and amounts can recur in several real orders. ReloadPi ยท Public transfers and context

A consumed nonce can mean cancellation

The kit sends its refund with a new EIP-3009 authorization. The refund wallet signs it and the facilitator submits the transaction. If the RPC call times out after submission, the operator can reconcile the original authorization using its saved wallet and nonce.

Circle's USDC contract sets authorizationState(authorizer, nonce) to true when the authorization is used or cancelled. A reconciler checks the event for that wallet and nonce. AuthorizationCanceled closes the authorization. AuthorizationUsed calls for a second check in the same receipt, for the USDC Transfer from the refund wallet to the original payer with the expected amount. EIP-3009 ยท Circle's contract implementation

After an uncertain refund submission, inspect the saved wallet and nonce. A finalized cancellation closes the authorization. A finalized use with a matching USDC transfer confirms the refund. Unresolved submissions stay pending.

The diagram follows one EIP-3009 authorization. A cancellation resolves that authorization. Order-level reconciliation still needs the record of any later payout.

Check the published eSIM refund

This Python 3.11+ example makes four read-only Base RPC requests. It uses the expected refund wallet, original payer, nonce, and amount from our test. In an integration, save those values from the purchase and signed refund before submission. The two event hashes below identify the USDC AuthorizationUsed and ERC-20 Transfer events. For this Circle USDC payout, the transfer event immediately follows the authorization event.

import json
import os
from urllib.request import Request, urlopen

RPC = os.environ.get("BASE_RPC_URL", "https://mainnet.base.org")
USDC = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"
REFUND = "0x6dcfb7f075ad7fb6308064ac53e310dfb6adfd9b65d9f44b3c9a6dd39ca9ed4b"
SENDER = "0xf47161fbb56d0d910a17e503c8292903f41bbae2"
PAYER = "0x428f2be4327908948e3b1915c55ddf8fa6bf73cc"
NONCE = "0x0448848973abded30d55a7b7f9881458370359ecc651b88ecb3e3afbb98528f7"
USED = "0x98de503528ee59b575ef0c0a2576a82497bfc029a5685b209e9ec333479b10a5"
TRANSFER = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
AMOUNT = 310_000  # 0.31 USDC in six-decimal units


def rpc(method, *params):
    request = Request(
        RPC,
        data=json.dumps({"jsonrpc": "2.0", "id": 1, "method": method,
                         "params": params}).encode(),
        headers={"Content-Type": "application/json", "User-Agent": "refund-check/1.0"},
    )
    with urlopen(request, timeout=15) as response:
        result = json.load(response)
    if "error" in result:
        raise RuntimeError(result["error"])
    return result["result"]


def address_topic(address):
    return "0x" + address[2:].zfill(64)


if int(rpc("eth_chainId"), 16) != 8453:
    raise SystemExit("Expected Base mainnet")

receipt = rpc("eth_getTransactionReceipt", REFUND)
finalized = rpc("eth_getBlockByNumber", "finalized", False)
if (receipt is None or receipt["status"] != "0x1" or finalized is None
        or int(receipt["blockNumber"], 16) > int(finalized["number"], 16)):
    raise SystemExit("No successful finalized receipt")

block = rpc("eth_getBlockByNumber", receipt["blockNumber"], False)
if block is None or block["hash"] != receipt["blockHash"]:
    raise SystemExit("Receipt block is outside the canonical chain")

authorization_topics = [USED, address_topic(SENDER), NONCE]
transfer_topics = [TRANSFER, address_topic(SENDER), address_topic(PAYER)]
logs = [log for log in receipt["logs"] if log["address"].lower() == USDC]
used_indices = {
    int(log["logIndex"], 16)
    for log in logs
    if log["topics"] == authorization_topics
}
transfers = [
    log for log in logs
    if log["topics"] == transfer_topics and int(log["data"], 16) == AMOUNT
    and int(log["logIndex"], 16) - 1 in used_indices
]
if len(transfers) != 1:
    raise SystemExit("Expected one matching USDC transfer after AuthorizationUsed")

print("Verified 0.31 USDC returned to the original payer on Base")

Run python3 verify-refund.py after saving the block above. Set BASE_RPC_URL if your Base mainnet provider uses a different endpoint. The expected output is Verified 0.31 USDC returned to the original payer on Base.

Handle an uncertain send without paying twice

Persist an attempt against the order before sending, together with the signer, nonce, recipient, and amount. Keep the attempt pending while the outcome is unresolved. With an EIP-3009 transfer, repeating the same valid signed authorization preserves its nonce. Once the token contract consumes that nonce, another submission with it cannot execute another transfer. Generating a fresh authorization for the same order introduces a new nonce, so the application still needs order-level idempotency.

The kit reserves the refund against a stable reference before it calls the facilitator and stops automatic retries after an ambiguous response. An operator can use the receipt check above to investigate. The current refund path leaves that reconciliation with the operator.

Thanks to Cross at ReloadPi for publishing the top-up examples and discussing where a refund attempt can get stuck.

AI assistance was used to draft and edit this article, prepare the illustrations, and help run the read-only receipt checks.

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.