@ngtchain/client
v1.1.1
Published
Client for one x402 v2 EIP-3009 stream call on NGT Chain. The caller signs locally. The facilitator pays Base gas.
Maintainers
Readme
@ngtchain/client
Client for one NGT stream call on Base. The caller signs an EIP-3009 authorization locally. The facilitator submits that transfer and pays the Base gas.
Installation
npm install @ngtchain/client viemQuickstart
import { executeNgtStream } from "@ngtchain/client";
const response = await executeNgtStream(process.env.AGENT_PRIVATE_KEY);
console.log(response.status, response.data);executeNgtStream reads the HTTP 402 challenge, signs TransferWithAuthorization with the domain name and nonce from that challenge, and retries with a base64 PAYMENT-SIGNATURE header. The default URL is https://www.ngtchain.com/v1/agent/stream. Pass a second argument to use another endpoint. Each successful call spends 0.001 NGT.
Paying any NGT-paywalled API
import { payAndFetch } from "@ngtchain/client";
const res = await payAndFetch(process.env.AGENT_PRIVATE_KEY, "https://api.example.com/v1/quote", {
maxAmount: "0.01", // NGT; required
});
console.log(res.data, res.payment); // { amount: "0.002", payTo: "0x…", transaction: "0x…" }payAndFetch signs only when the challenge is NGT on Base at or under maxAmount. It works with servers built on @ngtchain/paywall. executeNgtStream stays pinned to the NGT stream endpoint and treasury.
