Skip to content

feat(x402): support USDT payments on BNB Smart Chain#455

Merged
gulshngill merged 1 commit into
mainfrom
feat/x402-bsc-support
Jun 11, 2026
Merged

feat(x402): support USDT payments on BNB Smart Chain#455
gulshngill merged 1 commit into
mainfrom
feat/x402-bsc-support

Conversation

@gulshngill

Copy link
Copy Markdown
Contributor

What

The Nansen API now advertises USDT on BNB Smart Chain (eip155:56) as an x402 payment option. This PR adds BSC support to the CLI's x402 auto-payment flow.

Why almost everything already worked

Payment signing is network-generic: the chain id, token contract, recipient, amount, and EIP-712 domain (extra.name/extra.version) are all taken from the 402 accepts entry, and the fallback loop in api.js already tries each advertised network in order. So a wallet holding BSC USDT could already pay — but the post-payment balance check was wrong for BSC.

Changes

  • src/x402.js — the per-network EVM token map (now exported as EVM_X402_TOKENS) gains eip155:56 (BSC USDT 0x55d398…7955) and a per-token decimals field. BSC USDT uses 18 decimals, unlike the 6-decimal Base USDC / X Layer USDT0, so the previous hardcoded 1e6 divisor would have reported balances off by 10¹².
  • src/rpc-urls.js — add bsc to CHAIN_RPCS (default https://bsc-dataseed.binance.org, override with NANSEN_BSC_RPC), matching the existing per-chain pattern.
  • src/__tests__/x402-balance.test.js — registry tests: covered networks, decimals, pinned token contracts, RPC resolution.
  • Changeset (patch).

Testing

  • vitest run — x402 suites green (11/11 in the touched areas); full suite 1490 passed with one unrelated flake in update-check.test.js (passes in isolation, before and after this change).
  • Gas note: payers don't need BNB — x402 EVM payments are gasless authorizations; only a USDT balance on BSC is required.

🤖 Generated with Claude Code

The Nansen API now advertises USDT on BNB Smart Chain (eip155:56) as an
x402 payment option. Payment signing already handles any EVM network
generically (chain id, token contract, and EIP-712 domain all come from
the 402 accepts entry), so this wires up the remaining network-specific
piece: the post-payment balance check.

- Add eip155:56 to the EVM payment-token registry (now exported as
  EVM_X402_TOKENS) with the BSC USDT contract and 18-decimal precision —
  the existing tokens (Base USDC, X Layer USDT0) use 6 decimals, so the
  divisor is now per-token instead of a hardcoded 1e6.
- Add bsc to CHAIN_RPCS with a NANSEN_BSC_RPC override, matching the
  existing per-chain env-var pattern.
- Tests for the registry (networks, decimals, token contracts, RPCs).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gulshngill gulshngill requested a review from kome12 June 11, 2026 02:46
@gulshngill gulshngill merged commit 35f1113 into main Jun 11, 2026
7 checks passed
@gulshngill gulshngill deleted the feat/x402-bsc-support branch June 11, 2026 07:04
@github-actions github-actions Bot mentioned this pull request Jun 11, 2026
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.

2 participants