Skip to content

fix(tron): use hex chain id in CAIP-2 network identifiers#78

Merged
roger-gan merged 3 commits into
mainfrom
fix/tron-caip2-chain-id
Jul 7, 2026
Merged

fix(tron): use hex chain id in CAIP-2 network identifiers#78
roger-gan merged 3 commits into
mainfrom
fix/tron-caip2-chain-id

Conversation

@roger-gan

Copy link
Copy Markdown
Contributor

Per upstream spec PR x402-foundation/x402#2076 review feedback, CAIP-2 network identifiers must use the hex chain id, not human-readable network names. Replaces all tron:mainnet/tron:nile/tron:shasta keys with tron:0x2b6653dc/tron:0xcd8690dc/tron:0x94a9059e across the codebase.

BREAKING CHANGE: network identifiers change from tron:mainnet/tron:nile to tron:0x2b6653dc/tron:0xcd8690dc. Clients and servers must be upgraded together — a mismatched pair will fail to interop. The tron: CAIP-2 namespace is still provisional pending CASA registration (ChainAgnostic/namespaces#170, #162).

Description

Tests

Checklist

  • I have formatted and linted my code
  • All new and existing tests pass
  • My commits are signed (required for merge) -- you may need to rebase if you initially pushed unsigned commits

roger-gan added 3 commits July 3, 2026 19:47
Per upstream spec PR x402-foundation/x402#2076 review feedback, CAIP-2
network identifiers must use the hex chain id, not human-readable network
names. Replaces all `tron:mainnet`/`tron:nile`/`tron:shasta` keys with
`tron:0x2b6653dc`/`tron:0xcd8690dc`/`tron:0x94a9059e` across the codebase.

BREAKING CHANGE: network identifiers change from `tron:mainnet`/`tron:nile`
to `tron:0x2b6653dc`/`tron:0xcd8690dc`. Clients and servers must be upgraded
together — a mismatched pair will fail to interop. The `tron:` CAIP-2
namespace is still provisional pending CASA registration
(ChainAgnostic/namespaces#170, #162).
…king changeset

Address PR review on hex CAIP-2 network id change:
- README/JSDoc/CLAUDE.md: replace residual tron:nile|shasta|mainnet with
  hex ids (tron:0xcd8690dc/0x94a9059e/0x2b6653dc) so docs match the
  implementation and no longer cause Unknown TRON network errors
- Export TRON_MAINNET/TRON_NILE/TRON_SHASTA from package entry so
  consumers can import canonical ids instead of copying opaque strings
- Init BofAI changeset baseline + add major changeset for
  @bankofai/x402-tron documenting the breaking CAIP-2 id change
- Update refund-network test mock to use the live Nile id
…ex chain ids

- changeset: drop createAuthorizerTronSigner from the list of factories
  that throw on old network ids — it takes only a wallet (offline signing),
  no network param
- .claude/rules/networks/tron.md: identifier is tron:<hexChainId>; update
  table to canonical constants + hex ids; clarify authorizer signer takes
  no network
- .claude/rules/common/conventions.md, rules/CLAUDE.md, agents/code-reviewer.md:
  replace tron:<name>/tron:nile with hex ids so code-gen and review agents
  stop emitting the broken values
- rpc.ts module doc: tron:<hexChainId>

@matrix-agent116 matrix-agent116 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Thanks for this — it's a clean, mechanical migration of the TRON CAIP-2 identifiers from human-readable names (tron:nile) to hex chain IDs (tron:0xcd8690dc), aligning with the upstream spec review feedback. I verified the source of truth (constants.ts, rpc.ts, utils.ts, shared/gasfree/config.ts, shared/tokens.ts, shared/batch-settlement/constants.ts) and every network-keyed map is updated consistently; all lookups are pure map lookups with no residual name-based parsing, so nothing breaks silently. The new TRON_MAINNET/TRON_NILE/TRON_SHASTA constants are defined and exported, the tron:* wildcard registration path still resolves the hex networks correctly, and a proper major changeset with a migration guide is included. Overall this looks correct and mergeable; a few minor points below.

Points

  1. (question) Old-ID error paths / tests. The changeset promises that passing a legacy ID (tron:nile) now throws Unknown TRON network / No TRON RPC configured. That behavior follows from the map changes, but I don't see a test asserting it. Consider adding a small regression test so the "fail loud on old IDs" contract is locked in — this is the main safety net for the breaking change.

  2. (suggestion) Cross-language / cross-repo interop. The identifiers are now hex-only in TypeScript. If any other component or downstream consumer (e.g. a Python facilitator, or the GasFree relayer proxy that keys on the network segment) still emits or expects tron:nile-style IDs, a mismatched pair will silently fail to interop — exactly the breakage called out in the PR body. Could you confirm there's no counterpart that still speaks the old identifiers? (I couldn't find a Python package in this repo, so this may be a non-issue here.)

  3. (nit) Unrelated formatting churn. A couple of files carry formatting-only reflows that aren't part of the rename (the @bankofai/x402-core/utils import wrap in exact/server/scheme.ts and upto/server/scheme.ts, the fee-type export in index.ts, and a few multi-line arg reflows in signer.ts/tests). These are harmless but add noise to a large diff — fine to keep if they're just the formatter running, just flagging.

  4. (note) Provisional namespace. As you note, tron: is still provisional pending CASA registration. No action needed for this PR; just worth tracking so we don't have to do a second breaking rename later if the final namespace differs.

Once the migration test is added (or you confirm it's covered elsewhere), I'm happy to approve.

reference (e.g. `tron:0xcd8690dc` for Nile) instead of the human-readable name
(`tron:nile` / `tron:shasta` / `tron:mainnet`). Passing the old string IDs to the
signer factories (`createClientTronSigner`, `createFacilitatorTronSigner`)
or to `getTronChainId` / RPC resolution now throws

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] The changeset states that passing old IDs to getTronChainId / RPC resolution now throws Unknown TRON network / No TRON RPC configured. This follows correctly from the map changes, but I don't see a regression test asserting it. Consider adding one so the "fail loud on legacy IDs" contract is protected against accidental future regressions.

MoneyParser,
} from "@bankofai/x402-core/types";
import { convertToTokenAmount, numberToDecimalString, parseMoneyString } from "@bankofai/x402-core/utils";
import {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This import reflow (single-line → multi-line) is formatting-only and unrelated to the CAIP-2 rename. Same pattern appears in upto/server/scheme.ts. Harmless if it's just the formatter, but it adds noise to an already large diff.

type FeeInfo,
type ExactTronFeeConfig,
} from "./shared/fee";
export { type FeeInfo, type ExactTronFeeConfig } from "./shared/fee";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This fee-type export reflow is a formatting-only change unrelated to the rename. Fine to keep, just flagging as churn.

@roger-gan roger-gan requested a review from matrix-agent116 July 7, 2026 06:03
@roger-gan roger-gan merged commit e158640 into main Jul 7, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants