Reference
JavaScript SDK
A small client for the gateway, receipts, and webhooks.
The SDK is one JavaScript module with no dependencies. It runs anywhere with WebCrypto and fetch, including Node, browsers, and Workers.
bash
curl -O https://dapp.covergate.app/sdk/covergate.mjsRun a decision#
js
import { CoverGate } from "./covergate.mjs";
const gate = new CoverGate();
const agent = await gate.createAgent({
name: "Invoice Agent",
operator: "Your team",
template: "payments",
destinations: ["0xVendor"],
});
await gate.testCertificate(agent.id);
const decision = await gate.spend({
agentId: agent.id,
action: "transfer",
asset: "USDC",
amount: 100,
destination: "0xVendor",
});Methods#
| Method | Purpose |
|---|---|
spend(request) | Run a transaction through both gates |
dryRun(request) | Get the full decision without executing |
status(slug) | Counterparty check |
agents() | List agents |
createAgent(agent) | Create an agent from a mandate template |
testCertificate(agentId) | Get a sandbox test certificate |
freeze(agentId, frozen) | Freeze or unfreeze |
receiptKey() | The public key that signs receipts |
addWebhook(agentId, url) | Add a webhook |
Check a receipt offline#
js
import { verifyDecision } from "./covergate.mjs";
const valid = await verifyDecision(decision, await gate.receiptKey());Keep a copy of the public key, and this check needs no call to CoverGate. See Decision receipts.