Installation
Install the Atomic Rail SDK and set up your environment. Covers npm, bun, yarn, and environment variables.
The @atomic-rail/usage-gate package is a lightweight, framework-agnostic library for protecting and metering your APIs.
1. Install Package
npm install @atomic-rail/usage-gate2. Dependencies
The package handles all standard x402 payment logic internally. You do not need to install @x402/core or @x402/next unless you are building custom payment schemes.
3. Environment Variables
You must provide your project credentials to the gate. These are found in the Settings → Security tab of your dashboard.
# .env.local
METER_PROJECT_ID=proj_...
METER_HMAC_SECRET=...4. Initialization
Create a singleton instance of the gate to share across your app.
import { AtomicGate } from "@atomic-rail/usage-gate";
export const gate = new AtomicGate({
projectId: process.env.METER_PROJECT_ID,
hmacSecret: process.env.METER_HMAC_SECRET,
sellerWallet: "0x...",
debug: process.env.NODE_ENV === "development",
});5. Troubleshooting
"Invalid Signature"
This means the METER_HMAC_SECRET in your code does not match the one in your dashboard. Rotate the secret in the dashboard and update your environment variables.
"Module not found"
Ensure you are using a Node.js version that supports the standard fetch API (v18+) or a modern runtime like Bun or Deno.