Integration Guide
Aegis is published on npm and works with any Express app. Three real use cases, complete code, copy and paste.
Turn any Express endpoint into a paid service. One middleware line adds x402 micropayments — agents pay per call, you earn per call.
npm install aegis-ows-gate expressimport express from "express";
import { aegisGate } from "aegis-ows-gate";
const app = express();
// Your API is now paid — $0.001 SOL per call
app.get("/api/data",
aegisGate({ price: "0.001", token: "SOL", agentId: "my-service" }),
(req, res) => {
res.json({ result: "your data here" });
}
);
app.listen(3000, () => {
console.log("Paid API running on http://localhost:3000");
});# Without payment → 402 Payment Required
curl http://localhost:3000/api/data
# Returns: { "error": "Payment Required", "x402": { "price": "0.001", "token": "SOL", ... } }
# With payment → 200 OK
curl http://localhost:3000/api/data \
-H 'X-PAYMENT: {"fromAgent":"buyer","txHash":"sig-123456789012345678","timestamp":"2026-04-04T00:00:00Z","deadline":9999999999}'
# Returns: { "result": "your data here" }One agent pays another for a service. payAndFetch handles the full x402 handshake — discover the price, sign the payment through OWS, get the content.
npm install aegis-ows-gateimport { payAndFetch } from "aegis-ows-gate";
// Agent discovers and pays for a service — one line
const result = await payAndFetch(
"http://data-service:3000/api/data",
"buyer-agent"
);
console.log(result); // The paid content
// What happened under the hood:
// 1. payAndFetch called the URL, got a 402 response
// 2. Read the price from the x402 payment details
// 3. Signed the payment through OWS (all policies checked)
// 4. Re-sent the request with the payment proof
// 5. Returned the 200 response bodyControl how much your agent can spend, which addresses it can pay, and kill it if it goes silent. Three policy executables plug directly into OWS.
npm install aegis-ows-shared{
"limits": [
{
"chainId": "solana:devnet",
"token": "SOL",
"daily": "1.00",
"weekly": "5.00",
"monthly": "15.00"
},
{
"chainId": "eip155:1",
"token": "USDC",
"daily": "10.00",
"weekly": "50.00"
}
]
}# Register policies with OWS
ows policy create \
--name aegis-budget \
--executable ./node_modules/.bin/aegis-budget \
--config ./budget-policy.json
# Or use the Aegis CLI for guided setup
npx aegis-ows-cli installAegis is open source and published on npm. Use it in your hackathon project, or build on top of it.