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.
- Testnet ETH for gas if you are using Base Sepolia or Ethereum Sepolia.
- Collateral in ETH, USDC, or USDT, depending on the network and route.
- Node.js if you want to follow the example below.
eip155:84532) for development. Move to Base (eip155:8453) when you are ready for production traffic.
If you do not have these 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.
Add testnet gas from a Base Sepolia faucet or an Ethereum Sepolia faucet, then deposit a small amount of supported collateral into 4Mica. For stablecoin testing, use the token and network supported by the route you plan to call.
Register collateral
Deposit collateral into 4Mica before your first paid request. This registers the wallet and gives 4Mica a balance to secure future payment guarantees. During registration, choose the same network you plan to use in your x402 client. Follow the deposits and withdrawals guide for the collateral flow, then wait for the deposit to finalize before continuing.Install the packages
Install the 4Mica x402 client, the x402 fetch wrapper, and viem:Make your first paid request
Wrap your normalfetch client with the 4Mica scheme. When the API returns HTTP 402 payment requirements, the wrapper creates a unique request ID, signs the guarantee, retries the request, and returns the paid response.
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.
- 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.