TypeScript SDK
@4mica/sdk is the official TypeScript SDK for the 4Mica payment network. Use it to deposit collateral, sign payment guarantees, verify and settle them, run the x402 HTTP flow, and gate your own routes behind a payment.
The SDK exposes five capabilities:
- User client (
client.user) — deposit collateral, sign payments, and manage withdrawals in ETH or ERC20 tokens. - Recipient client (
client.recipient) — issue and verify payment guarantees, and claim net credit from cleared settlement cycles. - X402 flow helper (
X402Flow) — turn a402 Payment Requiredresponse into a signed payment header. - Server paywall (
@4mica/sdk/server) — an edge-safe primitive that gates a route behind an x402 payment. - Admin RPCs (
client.rpc) — manage user suspension and admin API keys when authorized.
Runtime-neutral
@4mica/sdk runs on Node, Bun, Deno, and edge runtimes. HTTP uses the global fetch, and the @4mica/sdk/server subpath is Buffer-free so it runs on the edge.
Prefer a runtime or framework adapter for idiomatic wiring:
@4mica/sdk-node,
@4mica/sdk-bun, and @4mica/sdk-deno for env-driven client and paywall
factories, and @4mica/sdk-next, @4mica/sdk-express, and @4mica/sdk-hono
for thin x402 middleware.Install
Node.js 18 or later is required.Networks
The default network is Ethereum Sepolia. Select a network with.network() or the 4MICA_NETWORK environment variable.
| Shorthand | CAIP-2 | Core API URL |
|---|---|---|
base | eip155:8453 | https://base.api.4mica.xyz/ |
base-sepolia | eip155:84532 | https://base.sepolia.api.4mica.xyz/ |
ethereum-sepolia | eip155:11155111 | https://ethereum.sepolia.api.4mica.xyz/ |
NETWORKS constant:
Your first client
Build a config, create aClient, and always close it when you are done. Start on Base Sepolia (eip155:84532) with a test wallet.
Client.new connects to the core service, fetches public parameters, and wires up the on-chain gateway. From the client you reach the three entry points:
client.user— payer-side operations (collateral, signing, withdrawals, net-debit settlement).client.recipient— recipient-side operations (guarantees, net-credit settlement).X402Flow— the helper for402-protected HTTP resources.
Next steps
Configuration
Initialize a client with
ConfigBuilder, environment variables, or a custom signer.Client operations
Deposit collateral, sign payments, issue guarantees, and settle cleared cycles.
X402 flow
Turn a
402 Payment Required response into a signed payment header.Server paywall
Gate any route behind an x402 payment with the edge-safe primitive.