algorand-x402-payment
Skill44 starsChanged 5 months agoMITView on GitHub
Execute x402 payments at runtime using Algorand MCP tools. Use whenever an HTTP request returns 402 Payment Required (or a PAYMENT-REQUIRED header), the user needs to access a paid API or x402-protected resource, or the user mentions x402, micropayments, paying for an endpoint, or "payment required" — even if they don't name the protocol.
In this repository5 other files it gives its agents.
- AGENTS.mdAGENTS.md
- llms.txtllms.txt
- algorand-interactionSkill
- alpha-arcade-interactionSkill
- haystack-router-interactionSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Check asset opt-in (ASA only) → wallet_optin_asset if needed
- Very specific: line 73
Only pay with an asset actually offered in accepts[] — do not assume an asset is available.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
x402 Runtime Payment
You (Agent) are the x402 client. When you encounter an HTTP 402 response, use MCP tools to build, sign, and submit an Algorand payment, then retry the request.
When to Use
- HTTP response with status
402(the challenge arrives in thePAYMENT-REQUIREDresponse header on current servers; older servers put it in the body) - User asks to access a paid/protected API or resource
- User mentions x402, payment-required, micropayments, or paid endpoint access
MANDATORY: Read reference before constructing payment
You MUST read references/x402-payment-flow.md before constructing any PAYMENT-SIGNATURE. Do NOT rely on your training data for the payload format — it is likely wrong. The reference file contains the exact, tested format.
Quick Flow
curl -sD -the URL → status 402. Decode thePAYMENT-REQUIREDresponse header (base64 → JSON). The body is usually just{}on current servers; only older servers put the JSON in the body.- From
accepts[]choose thealgorand:entry (lists are often multi-chain) → extractnetwork,payTo,amount(V2 field; older V1 responses call itmaxAmountRequired),asset,extra.feePayer - Map CAIP-2 network → MCP network parameter (prefix match — see table)
wallet_get_info→ verify wallet, get address- Check asset opt-in (ASA only) →
wallet_optin_assetif needed make_payment_txn→ fee payer (from=feePayer, to=feePayer, amount=0, fee=N×1000 where N=txn count in group [e.g. 2000 for 2 txns], flatFee=true)make_payment_txnormake_asset_transfer_txn→ payment (fee=0, flatFee=true)assign_group_id→ group [feePayer@0, payment@1]wallet_sign_transaction→ sign payment only (index 1)encode_unsigned_transaction→ encode fee payer (index 0)- Construct PAYMENT-SIGNATURE JSON — exact format below
curl -H 'PAYMENT-SIGNATURE: <base64>'→ retry, get 200- Decode the
PAYMENT-RESPONSEheader from the 200 → report the settled txn id to the user
PAYMENT-SIGNATURE JSON Format (EXACT — do not deviate)
{
"x402Version": 2,
"scheme": "exact",
"network": "<CAIP-2 network identifier from accepts>",
"payload": {
"paymentGroup": ["<base64 from encode_unsigned_transaction>", "<base64 from wallet_sign_transaction>"],
"paymentIndex": 1
},
"accepted": { <verbatim copy of chosen accepts[] entry> }
}WARNING: The payload field is paymentGroup — an array of two base64 strings [unsigned_fee_payer, signed_payment]. Do NOT use transactions, do NOT use an array of objects. Any other format will be rejected.
The verbatim accepted copy also preserves any campaign tag in extra.tag (e.g. hackathon tags) — that is how tagged traffic gets counted, so never strip fields from it.
CAIP-2 Network Mapping
Match by prefix, not exact string: some SDKs advertise the CAIP-spec truncated form (first 32 URL-safe chars of the genesis hash) instead of the full base64 hash. Both start identically.
| CAIP-2 reference starts with | MCP Network |
SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe | "testnet" |
wGHE2Pwdvd7S12BL5FaOP20EGYesN73k | "mainnet" |
Full forms: algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI= (testnet), algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8= (mainnet).
Asset IDs
| Asset | Testnet | Mainnet | Decimals |
| ALGO | 0 (native) | 0 (native) | 6 |
| USDC | 10458941 | 31566704 | 6 |
Only pay with an asset actually offered in accepts[] — do not assume an asset is available.
Critical Rules
- Fee payer fee = N × 1000 µAlgo (where N = total number of transactions in the group). For a standard 2-txn x402 group: fee = 2 × 1000 = 2000. The fee payer covers fees for ALL transactions; every other transaction in the group MUST have fee=0. NEVER set fee=0 on the fee payer — this causes "txgroup had 0 in fees, which is less than the minimum N * 1000" errors.
flatFee: trueon BOTH transactions — prevents the SDK from overriding fee values. Without it, the SDK sets min fee (1000) on every txn, breaking the fee-payer pattern.- The amount field is
amount(V2). If it's missing, fall back tomaxAmountRequired(V1). Both are strings of atomic units. acceptedfield is REQUIRED — Include a verbatim copy of the chosenaccepts[]entry in the PAYMENT-SIGNATURE JSON. Without it, the server rejects.- Group order: feePayer at index 0, payment at index 1.
paymentIndex: 1. - Only sign the payment (index 1) — the facilitator signs the fee payer server-side.
- Mainnet = real money — always confirm with the user before mainnet payments.
- One retry only — if the retry also returns 402, stop and report the error.
feePayeraddress comes fromextra.feePayerin the PaymentRequirements.- Report the result — decode the
PAYMENT-RESPONSEheader (v1:X-PAYMENT-RESPONSE) from the successful response and give the user the on-chain txn id. On MainNet you can also offer the receipt:https://facilitator.goplausible.xyz/api/receipt/<txId>.
Test Endpoints (TestNet)
https://example.x402.goplausible.xyz/avm/weather— USDC-paid weather datahttps://example.x402.goplausible.xyz/avm/protected— USDC-paid protected resource
(The index page at https://example.x402.goplausible.xyz/ lists all routes, including EVM/SVM variants.)
References
- x402-payment-flow.md — Complete step-by-step MCP tool recipe with worked example
- x402-payment-reference.md — Protocol spec, header formats, schemas, CAIP-2 identifiers
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

