Skip to content

About

x402 payment examples for Mailgent — AI agents paying for APIs in USDC on Base (Node + Python buyers).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

mailgent-x402-examples

Reference code for paying x402-priced URLs with Mailgent — an AI agent paying for APIs in USDC on Base.

Folder Language What it shows
payment-agent/ Node Pays any x402 URL via mailgent.payments.pay({ url }) from @mailgent-dev/sdk. ~50 lines.
payment-agent-python/ Python Same as the Node buyer, using mailgent-sdk.

Each folder is self-contained: copy .env.example to .env, fill in your Mailgent API key, install, run.

How it works

Your agent calls an x402-priced URL → gets 402 Payment Required → Mailgent pays the seller in USDC under your mandate caps → you get the content plus an on-chain txHash.

  payment-agent  ──1. GET /resource──▶  seller
                 ◀─2. 402 ($0.05)──────
  mailgent.payments.pay({ url })  ──▶  Mailgent  ──pays──▶  seller
                 ◀─3. content + txHash─

The buyer's wallet is set up by Mailgent automatically the first time you configure spending limits.

Run it

  1. Sign in at https://console.mailgent.dev, create a project, copy the loid-… API key, and top up the wallet shown on the Identity page with a few cents of USDC on Base.
  2. Pick a language:
    • Node: cd payment-agent && cp .env.example .env, paste the key + a target URL, then npm install && npm start.
    • Python: cd payment-agent-python && cp .env.example .env, then pip install -r requirements.txt && python main.py.

SDK surface used

  • mailgent.payments.mandates.list() / create({ maxPerCallUsdc, dailyCapUsdc }) — set the wallet's spend caps once.
  • mailgent.payments.pay({ url }) — pay any x402 URL within those caps; returns { ok, content, txHash, cost, ... }.

Full reference: https://docs.mailgent.dev/docs/sdk-reference/payments/pay.

Selling / accepting x402 payments is a separate product — see loomal.ai.

Network

Mailgent Pay runs on Base mainnet (real USDC) only. No testnet.

Support

Open an issue, or reach us at https://mailgent.dev.

About

x402 payment examples for Mailgent — AI agents paying for APIs in USDC on Base (Node + Python buyers).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages