> ## Documentation Index
> Fetch the complete documentation index at: https://docs.4mica.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Make your first 4Mica-powered x402 request in minutes.

After you complete this guide, you will have a wallet ready to pay with 4Mica credit and a client that can handle 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.
* 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](https://nodejs.org/) if you want to follow the example below.

Use Base Sepolia (`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](https://metamask.io/), [Coinbase Wallet](https://www.coinbase.com/wallet/downloads), [Rabby](https://rabby.io/), 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](https://docs.base.org/base-chain/network-information/network-faucets) or an [Ethereum Sepolia faucet](https://cloud.google.com/application/web3/faucet/ethereum/sepolia), then [deposit a small amount of supported collateral](/core-concepts/deposits-and-withdrawals) into 4Mica. For stablecoin testing, use the token and network supported by the route you plan to call.

```bash theme={null}
PRIVATE_KEY=0xYourPrivateKey
```

<Warning>Keep private keys in environment variables instead of committing them to your code.</Warning>

<Tip>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.</Tip>

## 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](/core-concepts/deposits-and-withdrawals) 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:

```bash theme={null}
pnpm install @4mica/x402 @x402/fetch viem
```

## Make your first paid request

Wrap your normal `fetch` 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.

```ts theme={null}
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { FourMicaEvmScheme } from "@4mica/x402/client";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.PRIVATE_KEY);
const scheme = await FourMicaEvmScheme.create(account);

const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "eip155:84532", client: scheme }],
});

const response = await fetchWithPayment("https://api.example.com/data");
const data = await response.json();
```

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](/buyer/quick-start).

## Protect a route

If you are building the seller side, protect one route with the 4Mica payment middleware. Start with a small test price.

```ts theme={null}
app.use(paymentMiddlewareFromConfig({
  "GET /premium-content": {
    accepts: {
      scheme: "4mica-credit",
      price: "$0.10",
      network: "eip155:84532",
      payTo: "0xYourAddress",
    },
  },
}));
```

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](/seller/quick-start).

## 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.

<Columns cols={2}>
  <Card title="Demo apps" icon="play" href="/recipes/demo-apps">
    Explore example product flows that show buyers, sellers, guarantees, clearing, and settlement together.
  </Card>

  <Card title="REPL" icon="terminal" href="/recipes/repl">
    Run the full 4Mica payment flow in an interactive environment.
  </Card>
</Columns>
