Reference
Agent integration
Run the example agent, or call the guard from your own bot with viem.
#examples/agent.mjs
A small agent in the repository (Node.js and viem). It reads its mandate, asks the guard's check view, and sends a transaction only when the answer is 0. Run it from the project folder after npm install.
shell · environment
export GUARD=0x57dd851d840b1f0a2896dc1524c398c4574ff3c1
export AGENT_KEY=… # the AGENT's private key, set in your own terminal only
export RPC_URL=https://rpc.mainnet.chain.robinhood.com # optional, this is the default
export MANDATE=1 # optional, default: newest mandate naming this agentshell · commands
node examples/agent.mjs status
node examples/agent.mjs pay 0x5fc5360d0400a0fd4f2af552add042d716f1d168 <recipient> 8
node examples/agent.mjs swap <tokenIn> <tokenOut> 100 <amountIn> <minOut>output (sample)
mandate #1 owner 0xA… agent 0xB… active until 2026-12-24T…
USDG: per tx 10, per UTC day 25, spent today 0, left 25
EXECUTED pay 8 USDG to 0xC… · action #1 · spent today 8 · tx 0x…
REFUSED by the check (bits 512): OVER_PER_TX. Nothing sent.| Exit code | Meaning |
|---|---|
| 0 | Executed (or status printed). |
| 3 | Refused by the check: the reasons are printed, nothing was sent. |
| 1 | Error (missing variables, RPC failure, a revert in simulation). |
#Minimal viem integration
The ABI lines below are generated from the compiled contract; a test parses them and compares every selector with the artifact.
javascript
import { createPublicClient, createWalletClient, defineChain, http, parseAbi, parseUnits, stringToHex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
const robinhood = defineChain({
id: 4663,
name: "Robinhood Chain",
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
rpcUrls: { default: { http: ["https://rpc.mainnet.chain.robinhood.com"] } },
});
const GUARD = "0x57dd851d840b1f0a2896dc1524c398c4574ff3c1";
const USDG = "0x5fc5360d0400a0fd4f2af552add042d716f1d168"; // 6 decimals
const abi = parseAbi([
"function mandatesOfAgent(address agent) view returns (uint256[])",
"function getMandate(uint256 id) view returns ((address owner, address agent, uint64 validFrom, uint64 expiry, uint32 maxActionsPerDay, uint32 version, bool paused, bool revoked, bytes32 label, uint64 createdAt, uint64 actions))",
"function spentToday(uint256 id, address token) view returns (uint256 spent, uint256 left)",
"function checkTransfer(uint256 id, address caller, address token, address to, uint256 amount) view returns (uint256)",
"function executeTransfer(uint256 id, address token, address to, uint256 amount, bytes32 ref) returns (uint64 actionNo)",
]);
const agent = privateKeyToAccount(process.env.AGENT_KEY); // the agent's key, from its own machine
const pub = createPublicClient({ chain: robinhood, transport: http() });
const wallet = createWalletClient({ account: agent, chain: robinhood, transport: http() });
// 1. Read the mandate that names this agent.
const ids = await pub.readContract({ address: GUARD, abi, functionName: "mandatesOfAgent", args: [agent.address] });
const id = ids[ids.length - 1];
const mandate = await pub.readContract({ address: GUARD, abi, functionName: "getMandate", args: [id] });
const [spent, left] = await pub.readContract({ address: GUARD, abi, functionName: "spentToday", args: [id, USDG] });
// 2. Ask the guard before sending anything. 0 = inside the mandate.
const to = "0x…"; // an allowlisted recipient
const amount = parseUnits("8", 6);
const reasons = await pub.readContract({ address: GUARD, abi, functionName: "checkTransfer", args: [id, agent.address, USDG, to, amount] });
if (reasons !== 0n) throw new Error(`refused, reason bits ${reasons}`);
// 3. Execute. The tokens go from the owner's wallet straight to the recipient.
const ref = stringToHex("invoice-118", { size: 32 }); // free reference, only logged
const { request } = await pub.simulateContract({ account: agent, address: GUARD, abi, functionName: "executeTransfer", args: [id, USDG, to, amount, ref] });
const hash = await wallet.writeContract(request);
await pub.waitForTransactionReceipt({ hash });For swaps call checkSwap(id, caller, order) and executeSwapV3(id, order) with a SwapOrder. The guard forces the output to the owner; set minOut from your own quote.
#Keys
Never paste a private key into a website
Not this one, not any other. Deleq never asks for one: the owner signs in their own wallet, and a bot keeps the agent key on its own machine (an environment variable set in its own terminal). Use a separate agent key with only a little ETH for gas.