Skip to main content
After you complete this guide, you will have deposited collateral into 4Mica and made a paid request with a client that handles HTTP 402 responses automatically.

Before you begin

4Mica’s approach is to deposit collateral once, sign payment guarantees as requests happen, and settle net positions through clearing cycles instead of sending an on-chain transaction for every paid request. To start, you need:
  • A wallet private key or supported signer for your agent or service.
  • Collateral in a token core accepts on the network: on Base Sepolia, Aave’s test USDC or USDT.
  • Node.js and TypeScript 5.2 or later if you want to follow the example below.
On Base Sepolia the deposit is gasless through the hosted facilitator, so the wallet needs no ETH for it. Use Base Sepolia (eip155:84532) for development. Base (eip155:8453) still runs the previous protocol version; see supported networks. If you do not have a wallet yet, start with a test wallet. Create a new wallet in MetaMask, Coinbase Wallet, Rabby, or another EVM wallet, then export the private key for that wallet only. Use this key for development and keep your main wallet separate. Get test collateral from Aave’s faucet contract on Base Sepolia. The USDC core accepts there is Aave’s test token, 0xba50Cd2A20f6DA35D788639E581bca8d0B5d4D5f, not Circle’s, and anyone can mint it:
That is 10 USDC (six decimals). The same mint is available on the Aave app’s testnet faucet page. GET /core/tokens on the network’s core API lists every accepted token. Put the key in an environment variable:
Keep private keys in environment variables instead of committing them to your code.
For production, use a dedicated service wallet, hardware-backed signer, MPC wallet, or hosted key management system. Rotate keys regularly and limit how much collateral any one wallet can control.

Install the SDK

Deposit and make your first paid request

Connect a session, deposit collateral, then call the paid API with client.fetch. When the API returns HTTP 402 payment requirements, client.fetch signs a guarantee within your spend limits, retries the request once, and returns the paid response.
  • deposit resolves once core counts the collateral (status: "spendable"). If that takes longer than 60 seconds it returns status: "pending" instead of throwing: the money has moved, and await deposit.spendable() waits again. You only need to deposit once; later runs can skip it.
  • fetch has the same signature as the global fetch. It pays only up to 1 USDC per request unless you set spend limits; see Make paid requests automatically.
  • await using closes the session when client goes out of scope, even if a call throws.
await using needs TypeScript 5.2 or later. Plain JavaScript needs a runtime with native await using (Node 24 or later); otherwise call await client.close() in a finally block.
If the request succeeds, your client received the protected response and the seller received a settled payment guarantee. For the full setup, see the Buyer Quick Start.

Already using @x402/fetch?

If your client is already built on @x402/fetch, register the 4Mica scheme with it instead. Deposit collateral first, as above.
@x402/fetch only pays in assets its scheme client recognises. FourMicaEvmScheme recognises whatever 4Mica core lists for the network, so the seller’s advertised USDC passes the client’s spend controls and the default $1 per-payment cap applies. Pass spendControls to raise the cap or allow other assets.

Protect a route

If you are building the seller side, protect one route with the 4Mica payment middleware. Start with a small test price.
The middleware returns HTTP 402 responses, verifies payment payloads, settles guarantees, and serves the protected route after payment succeeds. For the full setup, see the Seller Quick Start.

Confirm it worked

A successful first run should end with:
  • The buyer receiving a normal HTTP response from the protected route.
  • client.paymentFor(response) reporting what was paid.
  • The seller receiving a settled guarantee for the request amount.
  • A payable guarantee that can enter a clearing cycle.

See it in action

Use a demo app or the REPL to see the full payment loop before wiring 4Mica into your own product. Start with testnet collateral, a small protected route, and a buyer client that can handle HTTP 402 retries.

Demo apps

Explore example product flows that show buyers, sellers, guarantees, clearing, and settlement together.

REPL

Run the full 4Mica payment flow in an interactive environment.