Skip to content

Conversation

@owenwahlgren
Copy link
Contributor

@owenwahlgren owenwahlgren commented Dec 10, 2025

Summary

  • Add avalancheLocal chain definition for local/tmpnet development
  • Fix HRP (Human Readable Part) determination in signXPTransaction to query the actual network ID from the node instead of relying on chain.testnet flag
  • Fix LOCAL_NETWORK_ID constant from 1337 to 12345 to match avalanchejs and tmpnet

Problem

When using the SDK with local networks (tmpnet), transactions failed with:

couldn't parse address "P-fuji...": expected hrp "local" but got "fuji"

The root cause was:

  1. signXPTransaction checked client.chain?.testnet and if true, assumed network ID 5 (Fuji)
  2. It then used isTestnet ? "fuji" : "avax" for HRP, never supporting "local"
  3. Local networks use network ID 12345 with HRP "local", but the code forced "fuji" for any testnet

Solution

  • Always fetch the actual network ID from the node via getContextFromURI()
  • Use getHRP(networkId) which properly maps network IDs to HRP strings including "local" for 12345
  • Update LOCAL_NETWORK_ID constant to 12345 for consistency with avalanchejs

Test plan

  • Verified subnet creation works on local tmpnet
  • Confirmed network ID 12345 maps to HRP "local"
  • Existing tests pass

@vercel
Copy link

vercel bot commented Dec 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
avalanche-sdk-typescript Ready Ready Preview Comment Dec 11, 2025 6:01pm

The SDK was incorrectly using the chain.testnet flag to determine HRP,
which mapped testnet=true to "fuji" and testnet=false to "avax". This
caused local networks (network ID 12345) to incorrectly use "fuji" HRP
instead of "local" HRP.

The fix:
- Always query the actual network ID from the node via getContextFromURI
- Use getHRP(networkId) to map network ID to correct HRP
- This properly supports all network IDs: mainnet (1), fuji (5), local (12345), etc.

Affected files:
- signXPTransaction.ts: Core signing/sending logic
- transferCtoPChain.ts: C-Chain to P-Chain transfers
- transferPtoCChain.ts: P-Chain to C-Chain transfers
- transferPtoPChain.ts: P-Chain to P-Chain transfers

🔺 Generated by DevRel swarm
The SDK had LOCAL_NETWORK_ID = 1337 but avalanchejs and tmpnet use
network ID 12345 for local networks. This inconsistency could cause
issues when using the exported constants.

🔺 Generated by DevRel swarm
@owenwahlgren owenwahlgren force-pushed the feat/add-avalanche-local-chain branch from 22067fd to 5e80966 Compare December 11, 2025 18:01
@SayanKar SayanKar merged commit 7f00182 into main Dec 11, 2025
8 checks passed
@SayanKar SayanKar deleted the feat/add-avalanche-local-chain branch December 11, 2025 18:57
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