Skip to content

Documentation

Quickstart

Five minutes, end to end: get testnet ETH, register an agent, give it a signing key, sign and publish a record, verify it — then tamper with it and watch verification fail.

Before you start

  • Node 22 or newer and pnpm, and a checkout of the AgentID monorepo.
  • A throwaway wallet key for Robinhood Chain Testnet (it will own the agent and pay gas).
  • @agentid/sdk is not published to npm. Build and pack it from the monorepo as below. Inside the monorepo, any workspace package can depend on "@agentid/sdk": "workspace:*" instead (its exports then point at the TypeScript sources).
setup
# @agentid/sdk is not on npm yet — build it from the AgentID monorepo (Node 22+, pnpm)
pnpm install
pnpm --filter @agentid/sdk build                     # → packages/sdk/dist (ESM, CJS, .d.ts)
cd packages/sdk && pnpm pack --pack-destination /tmp  # → /tmp/agentid-sdk-0.1.0.tgz

# A fresh project for this tutorial
mkdir agentid-quickstart && cd agentid-quickstart
npm init -y && npm pkg set type=module
npm install /tmp/agentid-sdk-0.1.0.tgz viem
npm install -D tsx                                    # run the files below with: npx tsx register.ts
client.ts
// client.ts — shared by the steps below
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { AgentID, robinhoodTestnet } from "@agentid/sdk";

export const agentid = new AgentID({
  chainId: 46630,
  apiUrl: "https://agentid-beryl.vercel.app/api/v1",
  // If your SDK build predates AgentID's testnet deployment, pass the extension addresses from /status:
  // keyRegistry: "0x…", activityAnchor: "0x…",
});

// The owner wallet that pays gas and owns the identity (a throwaway testnet key, kept in your environment).
export const owner = createWalletClient({
  account: privateKeyToAccount(process.env.OWNER_PRIVATE_KEY as `0x${string}`),
  chain: robinhoodTestnet,
  transport: http(),
});

Tutorial

  1. 1. Get testnet ETH

    Request testnet ETH for your owner address from the Robinhood Chain Testnet faucet. Gas is cheap (around 0.01 gwei), so a small amount covers every step. Wallet settings: chain id 46630, RPC https://rpc.testnet.chain.robinhood.com, currency ETH.

  2. 2. Register an agent

    registerAgent builds an ERC-8004 registration file, simulates register(agentURI) to predict your id, sends the transaction, waits for the receipt and reads the real id from the Registered event. You can do the same in the app at Register an agent.

    register.ts
    import { agentid, owner } from "./client";
    
    const { agentId, txHash, agentURI } = await agentid.registerAgent({
      walletClient: owner,
      input: {
        name: "Atlas",
        description: "Research agent that summarises public filings.",
        category: "research",
        capabilities: ["web-research", "data-analysis"],
      },
      onStatus: (s) => console.log(s.stage), // preparing → awaiting-signature → pending → confirmed
    });
    
    console.log(`agent #${agentId} registered in ${txHash}`);
    console.log(agentURI.slice(0, 48) + "…"); // data:application/json;base64,… (stored onchain)

    The agent is in the registry as soon as the transaction confirms. The AgentID index picks it up on the worker's next pass; to index it immediately:

    terminal
    # Optional: index the transaction now instead of waiting for the worker's next pass
    curl -X POST https://agentid-beryl.vercel.app/api/v1/index/tx \
      -H 'content-type: application/json' \
      -d '{"chainId":46630,"txHash":"0x…"}'
  3. 3. Generate a signing key in your own runtime

    The signing key is an operational key, separate from the owner wallet. Generate it where the agent runs. AgentID never asks for it and the website never handles it.

    keygen.ts
    import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
    
    // Run this where the agent runs. Store the key in that runtime's secret manager — never in a browser,
    // never in AgentID. Only its address goes onchain.
    const signingKey = generatePrivateKey();
    const signer = privateKeyToAccount(signingKey);
    console.log("signing key address:", signer.address);
  4. 4. Authorize the key

    Authorization takes two signatures: the key signs an EIP-712 KeyAuthorization (proof of possession) and the owner submits it with authorizeKey. The contract verifies the key's signature onchain (EOA or ERC-1271).

    authorize.ts
    import { signKeyAuthorization } from "@agentid/sdk";
    import { privateKeyToAccount } from "viem/accounts";
    import { agentid, owner } from "./client";
    
    const agentId = 42n; // your agent id from step 2
    const signer = privateKeyToAccount(process.env.AGENT_SIGNING_KEY as `0x${string}`);
    
    // 1) The signing key proves possession by signing an EIP-712 KeyAuthorization (in the agent runtime).
    const typedData = await agentid.buildKeyAuthorization({ agentId, key: signer.address });
    const signature = await signKeyAuthorization({ signer, typedData });
    
    // 2) The owner submits the proof onchain (deadline ≤ 1 day; the default is chain time + 30 min).
    const tx = await agentid.authorizeSigningKey({
      walletClient: owner,
      agentId,
      key: signer.address,
      deadline: typedData.message.deadline,
      signature,
    });
    console.log("authorized in", tx.txHash);
    console.log(await agentid.isAuthorizedSigner(agentId, signer.address)); // true
    Needs the AgentKeyRegistry
    Steps 4–7 require AgentID's AgentKeyRegistry on the network (the SDK throws NOT_CONFIGURED otherwise). Check Network status. Until it is deployed on testnet, run the same steps on the local devnet — see Network configuration.
  5. 5. Sign and publish a record

    Records are EIP-712 typed data bound to the chain, the registry, the agent, a payload hash, a timestamp and a nonce. Signing is local — no RPC call. Publishing sends the record to the AgentID API, which checks the signature and that the key is authorized right now.

    sign.ts
    import { privateKeyToAccount } from "viem/accounts";
    import { agentid } from "./client";
    
    const signer = privateKeyToAccount(process.env.AGENT_SIGNING_KEY as `0x${string}`);
    const payload = { task: "weekly-filings-summary", status: "completed", items: 14 };
    
    const record = await agentid.signActivity({
      signer,
      agentId: "42",
      activityType: "REPORT_GENERATED",
      payload, // only keccak256(canonical JSON) is signed; the payload stays with you
    });
    
    // Publish it to AgentID (checks signature + key authorization, rejects duplicates).
    const published = await agentid.publishActivity(record, { payload });
    console.log("record id:", published.record.id); // the EIP-712 digest
  6. 6. Verify it

    Anyone can verify the record — with the SDK, with POST /api/v1/verify/signature, or in the browser at Verify. The report has one result per check, pinned to one block.

    verify.ts
    const report = await agentid.verifyActivity(record, { payload });
    
    console.log(report.overall); // "PASS" when every required check passed
    for (const c of report.checks) console.log(c.status.padEnd(12), c.label);
    A valid signature proves that an authorized signing key signed this record. It does not prove that the underlying task actually occurred.
  7. 7. Tamper and watch it fail

    Modify the disclosed payload: its hash no longer matches the signed payloadHash, so record.payload is FAIL and the report is FAIL. Modify the record and the signature no longer recovers to the declared signer.

    tamper.ts
    // Change one field of the disclosed payload and verify again.
    const tampered = { ...payload, items: 15 };
    const bad = await agentid.verifyActivity(record, { payload: tampered });
    
    console.log(bad.overall); // "FAIL"
    console.log(bad.checks.find((c) => c.id === "record.payload")?.detail);
    // "The disclosed payload hashes to 0x…, not the signed payloadHash 0x…"
    
    // Changing the record itself breaks the signature instead:
    const forged = { ...record, activityType: "TASK_COMPLETED" as const };
    const bad2 = await agentid.verifyActivity(forged);
    console.log(bad2.checks.find((c) => c.id === "record.signature")?.status); // "FAIL"

Where next