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.
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:
GET /core/tokens on the network’s core API lists every accepted token.
Put the key in an environment variable:
Install the SDK
Deposit and make your first paid request
Connect a session, deposit collateral, then call the paid API withclient.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.
depositresolves once core counts the collateral (status: "spendable"). If that takes longer than 60 seconds it returnsstatus: "pending"instead of throwing: the money has moved, andawait deposit.spendable()waits again. You only need to deposit once; later runs can skip it.fetchhas the same signature as the globalfetch. It pays only up to1 USDCper request unless you setspendlimits; see Make paid requests automatically.await usingcloses the session whenclientgoes 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.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.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.