@fangorn-network/sdk 2026.10.21-dev → 2026.10.23-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -56,8 +56,8 @@ You can also configure via environment variables (these take precedence over the
56
56
  ETH_PRIVATE_KEY=0x...
57
57
  PINATA_JWT=...
58
58
  PINATA_GATEWAY=https://your-gateway.mypinata.cloud
59
- CHAIN_NAME=arbitrumSepolia # or baseSepolia
60
- SIGNED_URL_WORKER_URL=https://pinata-url-provider.your-subdomain.workers.dev # optional
59
+ CHAIN_NAME=baseSepolia # the default; or arbitrumSepolia
60
+ SIGNED_URL_WORKER_URL=https://pinata-url-provider.your-subdomain.workers.dev # optional; defaults to the network's hosted worker
61
61
  ```
62
62
 
63
63
  > The **access worker** and the **presigned-URL worker** are two different services: the first gates reads of sealed fields, the second hands out Pinata upload URLs. Don't conflate them.
@@ -94,8 +94,8 @@ be transferred). `fangorn app claim` pays one period of the subscription fee in
94
94
  USDC (the client approves exactly the fee for you), and `fangorn app renew` pays
95
95
  the next once less than a period is left. An expired app stores and presents nothing
96
96
  until it is renewed. **Apps provide storage**: you upload relative to
97
- an app, and hosted uploads (`storage: { signedUrl: {} }`) are billed to the
98
- client's app, which must have accepted you. There is no app-less hosted upload — with no
97
+ an app, and hosted uploads (`storage: { signedUrl: {} }`, through the network's
98
+ hosted worker, `config.signedUrlWorker`) are billed to the client's app, which must have accepted you. There is no app-less hosted upload — with no
99
99
  app, bring your own Pinata (`{ pinata }`) and pin your own data. A publisher that
100
100
  pays for its own storage claims a one-member app.
101
101
 
@@ -274,7 +274,7 @@ const fangorn = Fangorn.create({
274
274
  gateway: process.env.PINATA_GATEWAY!,
275
275
  },
276
276
  },
277
- config: FangornConfig, // defaults to Arbitrum Sepolia
277
+ config: FangornConfig, // the default, Base Sepolia; or ArbitrumSepoliaConfig
278
278
  appId: "my-app", // optional for reads (no app: each publisher's latest head); hosted uploads need one
279
279
  });
280
280
 
@@ -590,32 +590,35 @@ gadget_ behind the same handle shape, so committed data doesn't change form.
590
590
 
591
591
  ## Contracts
592
592
 
593
- ### Arbitrum Sepolia
593
+ ### Base Sepolia (the default)
594
594
 
595
595
  | Contract | Address | What it owns |
596
596
  | -------------------- | -------------------------------------------- | --------------------------------------------------- |
597
- | DataRegistry | `0x72B5f83526F3893aF9f1eE0f32A27218EA09f8aE` | Every repo's head, and the update log |
598
- | AppRegistry | `0x55e6209ea1833ceD900989a3b3b22466934E04A5` | Apps: owner, accepted publishers, bans, storage subscription (ERC-5643, USDC); what each app excludes |
599
- | MembershipRegistry | `0xDF17030Cd65435C86eb043F31DDACa99E819E347` | Time-limited, unlinkable access to an app's paid records (USDC + Semaphore) |
597
+ | DataRegistry | `0xE9183f768865dd2Cde5f1B71F8446F0Cd798ebe0` | Every repo's head, and the update log |
598
+ | AppRegistry | `0x0D3e98399df41b558048Cdd7D71723c37A3A9D6F` | Apps: owner, accepted publishers, bans, storage subscription (ERC-5643, USDC); what each app excludes |
599
+ | MembershipRegistry | `0x0e96C012b5c53622EcDAA82F342E31C2623A04f5` | Time-limited, unlinkable access to an app's paid records (USDC + Semaphore) |
600
+
601
+ `Fangorn.create` uses it when given no `config`, and the CLI when `CHAIN_NAME` is unset.
600
602
 
601
- ### Base Sepolia
603
+ ### Arbitrum Sepolia
602
604
 
603
605
  | Contract | Address |
604
606
  | -------------------- | -------------------------------------------- |
605
- | DataRegistry | `0xE9183f768865dd2Cde5f1B71F8446F0Cd798ebe0` |
606
- | AppRegistry | `0x0D3e98399df41b558048Cdd7D71723c37A3A9D6F` |
607
- | MembershipRegistry | `0x0e96C012b5c53622EcDAA82F342E31C2623A04f5` |
607
+ | DataRegistry | `0x72B5f83526F3893aF9f1eE0f32A27218EA09f8aE` |
608
+ | AppRegistry | `0x55e6209ea1833ceD900989a3b3b22466934E04A5` |
609
+ | MembershipRegistry | `0xDF17030Cd65435C86eb043F31DDACa99E819E347` |
608
610
 
609
- Use it from the SDK with `Fangorn.create({ config: BaseSepoliaConfig, ... })`, or
610
- from the CLI with `CHAIN_NAME=baseSepolia` (or pick it in `fangorn init`).
611
+ Still runs an older version of the contracts, which this SDK's ABIs do not match.
612
+ Select it with `Fangorn.create({ config: ArbitrumSepoliaConfig, ... })`, or from the
613
+ CLI with `CHAIN_NAME=arbitrumSepolia` (or pick it in `fangorn init`).
611
614
 
612
615
  Its default RPC is `base-sepolia-rpc.publicnode.com`, not `sepolia.base.org`: the
613
616
  official endpoint caps `eth_getLogs` at 200 blocks, too narrow to scan the registry's
614
617
  history. Each config's `logWindow` is the most blocks one log query spans on its RPC
615
618
  (Base 10,000, Arbitrum 100,000); `FANGORN_LOG_WINDOW` overrides it for a private RPC.
616
619
 
617
- `FangornConfig` (Arbitrum Sepolia) and `BaseSepoliaConfig` in `src/config.ts` are the authoritative list and what the SDK
618
- uses by default — prefer it over any address copied out of a document,
620
+ `BaseSepoliaConfig` (also exported as `FangornConfig`, the default) and `ArbitrumSepoliaConfig` in `src/config.ts` are the authoritative list and what the SDK
621
+ uses — prefer it over any address copied out of a document,
619
622
  including this table. The sources are `fangorn-network/contracts`
620
623
  (`solidity/script/Deployments.sol`); regenerate the ABIs with `pnpm abis`.
621
624
 
@@ -648,7 +651,7 @@ pnpm test:e2e
648
651
  | `src/e2e/sdk.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
649
652
  | `src/e2e/apps.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
650
653
  | `src/e2e/admin.e2e.test.ts` | the contracts on anvil | `anvil`, `forge` |
651
- | `src/e2e/live.e2e.test.ts` | Arbitrum Sepolia, read-only | nothing |
654
+ | `src/e2e/live.e2e.test.ts` | Base Sepolia, read-only | nothing |
652
655
 
653
656
  Without `anvil`, `forge` or the contracts checkout the anvil suites are skipped
654
657
  (in CI they fail). The deployer is the protocol admin, so the admin suite needs
package/lib/cli/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import getNetwork, { nonBlank, toAppId } from "../config.js";
3
+ import { agentCardUrl, parseAgentId } from "../erc8004.js";
3
4
  import { PublisherStatus } from "../contracts/types.js";
4
5
  import "../contracts/index.js";
5
6
  import { Fangorn } from "../fangorn.js";
6
7
  import { handleCancel, selectChain } from "./index.js";
7
- import { agentCardUrl, mcpTools, mintAgent, parseAgentId, registrationFile, setAgentFile } from "./erc8004.js";
8
- import { createPublicClient, createWalletClient, formatEther, formatUnits, http } from "viem";
8
+ import { createPublicClient, formatEther, formatUnits, http } from "viem";
9
9
  import { privateKeyToAccount } from "viem/accounts";
10
10
  import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
11
11
  import { dirname, join } from "path";
@@ -53,7 +53,7 @@ function loadConfig() {
53
53
  if (!privateKey) throw new Error("Incomplete environment configuration. Missing: ETH_PRIVATE_KEY\nSet it or run `fangorn init` to use a config file.");
54
54
  _config = {
55
55
  privateKey,
56
- cfg: getNetwork(envChain ?? "arbitrumSepolia"),
56
+ cfg: getNetwork(envChain ?? "baseSepolia"),
57
57
  appId: envAppId,
58
58
  pinataJwt: pinataJwt ?? "",
59
59
  pinataGateway: pinataGateway ?? "",
@@ -287,91 +287,29 @@ appCmd.command("claim").description("Claim the configured app on-chain (first co
287
287
  process.exit(1);
288
288
  }
289
289
  });
290
- async function retryNonce(f, tries = 4) {
291
- for (let i = 0;; i++) try {
292
- return await f();
293
- } catch (e) {
294
- if (i >= tries - 1 || !/underpriced|nonce too low|nonce has already been used|already known/i.test(e.message)) throw e;
295
- await new Promise((ok) => setTimeout(ok, 3e3 * (i + 1)));
296
- }
297
- }
298
290
  appCmd.command("agent").description("Register this app's gateway as an ERC-8004 agent and point the app at its card (owner only)").argument("[cardUrl]", "The agent card URL; or pass --access-worker to use its /.well-known/agent-card.json").option("--access-worker <url>", "The access worker serving the agent card").option("--mcp <url>", "An MCP endpoint to index alongside the card").option("--skip-register", "Only set agent_uri on-chain — for a gateway already registered with ERC-8004").option("--update <agentId>", "Update an agent already registered (e.g. 84532:10323) from the card as it is now: a new registration file, pointed to by setAgentURI; mints nothing").action(async (cardUrl, opts) => {
299
291
  try {
300
292
  const cfg = loadConfig();
301
293
  const url = agentCardUrl(cardUrl, opts.accessWorker);
302
294
  const s = spinner();
303
- s.start(`Reading ${url}`);
304
- const res = await fetch(url);
305
- if (!res.ok) {
306
- s.stop();
307
- throw new Error(`card at ${url} returned ${String(res.status)}`);
308
- }
309
- const card = await res.json();
310
- s.stop(`Card: ${card.name ?? "(unnamed)"}`);
311
- if (!card.name || !card.description) throw new Error("card is missing `name` or `description`");
312
- let agentId;
313
- if (!opts.skipRegister) {
314
- if (!cfg.pinataJwt) throw new Error("ERC-8004 registration pins the registration file to IPFS — set PINATA_JWT, or pass --skip-register.");
315
- const c = {
316
- chain: cfg.cfg.chain,
317
- publicClient: createPublicClient({
318
- chain: cfg.cfg.chain,
319
- transport: http(cfg.cfg.rpcUrl)
320
- }),
321
- walletClient: createWalletClient({
322
- account: getAccount(),
323
- chain: cfg.cfg.chain,
324
- transport: http(cfg.cfg.rpcUrl)
325
- }),
326
- pinataJwt: cfg.pinataJwt
327
- };
328
- const chainId = cfg.cfg.caip2;
329
- const named = {
330
- ...card,
331
- name: card.name,
332
- description: card.description
333
- };
334
- s.start("Indexing skills and capabilities from the card");
335
- const mcp = opts.mcp ? {
336
- endpoint: opts.mcp,
337
- tools: await mcpTools(opts.mcp)
338
- } : void 0;
339
- s.stop();
340
- const file = (id) => registrationFile({
341
- cardUrl: url,
342
- card: named,
343
- chainId,
344
- agentId: id,
345
- mcp
295
+ const chainId = cfg.cfg.caip2;
296
+ const update = opts.update ? parseAgentId(opts.update, chainId) : void 0;
297
+ s.start(opts.skipRegister ? "Pointing the app at its card" : update !== void 0 ? `Updating ERC-8004 agent ${opts.update ?? ""}` : "Registering with the ERC-8004 identity registry");
298
+ let result;
299
+ try {
300
+ result = await getFangorn().registerAgent(url, {
301
+ mcp: opts.mcp,
302
+ update,
303
+ skipRegister: opts.skipRegister
346
304
  });
347
- if (opts.update) {
348
- const id = parseAgentId(opts.update, chainId);
349
- s.start(`Updating ERC-8004 agent ${opts.update}`);
350
- await retryNonce(() => setAgentFile(c, id, file(id)));
351
- s.stop();
352
- agentId = `${String(chainId)}:${String(id)}`;
353
- } else {
354
- s.start("Registering with the ERC-8004 identity registry");
355
- const id = await mintAgent(c);
356
- agentId = `${String(chainId)}:${String(id)}`;
357
- s.message(`Minted ${agentId}; pinning its registration file`);
358
- try {
359
- await retryNonce(() => setAgentFile(c, id, file(id)));
360
- } catch (e) {
361
- s.stop();
362
- throw new Error(`agent ${agentId} was minted but its registration file was not set (${e.message}). Finish it with: fangorn app agent ${url} --update ${agentId}`);
363
- }
364
- s.stop();
365
- }
366
- }
367
- const apps = getFangorn().getAppRegistry();
368
- const bound = opts.update ? await apps.appAgentUri().catch(() => "") : "";
369
- let txHash = "(already bound)";
370
- if (bound !== url) {
371
- s.start("Pointing the app at its card");
372
- txHash = await retryNonce(() => apps.setAppAgentUri(url));
305
+ } catch (e) {
373
306
  s.stop();
307
+ const minted = e.agentId;
308
+ throw minted !== void 0 ? /* @__PURE__ */ new Error(`${e.message.replace(/; finish it with .*/, "")}. Finish it with: fangorn app agent ${url} --update ${String(chainId)}:${String(minted)}`) : e;
374
309
  }
310
+ s.stop();
311
+ const agentId = result.agentId !== void 0 ? `${String(chainId)}:${String(result.agentId)}` : void 0;
312
+ const txHash = result.txHash ?? "(already bound)";
375
313
  if (agentId) console.log(`Agent ID: ${agentId}`);
376
314
  console.log(`Card: ${url}`);
377
315
  console.log(`Tx: ${txHash}`);
@@ -1,8 +1,8 @@
1
1
  import "./cli.js";
2
- import * as viem5575 from "viem";
2
+ import * as viem129 from "viem";
3
3
 
4
4
  //#region src/cli/index.d.ts
5
- declare const getChain: (chainStr: string) => viem5575.Chain;
5
+ declare const getChain: (chainStr: string) => viem129.Chain;
6
6
  declare const handleCancel: (value: unknown) => void;
7
7
  declare const selectChain: () => Promise<string>;
8
8
  declare function parseGadgetArg(raw: string): {
package/lib/cli/index.js CHANGED
@@ -13,11 +13,11 @@ const selectChain = async () => {
13
13
  const chainChoice = await select({
14
14
  message: "Pick your chain.",
15
15
  options: [{
16
- value: "arbitrumSepolia",
17
- label: "Arbitrum Sepolia"
18
- }, {
19
16
  value: "baseSepolia",
20
17
  label: "Base Sepolia"
18
+ }, {
19
+ value: "arbitrumSepolia",
20
+ label: "Arbitrum Sepolia"
21
21
  }]
22
22
  });
23
23
  handleCancel(chainChoice);