Skip to content

fix(forge): add deposit address format validation - #220

Merged
Gaubee merged 1 commit into
mainfrom
fix/forge-deposit-address
Jan 11, 2026
Merged

Gaubee merged 1 commit into
mainfrom
fix/forge-deposit-address

Conversation

@Gaubee

@Gaubee Gaubee commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

Problem

When using TRON chain in the Forge miniapp, the "确认锻造" step fails with error:

Invalid base58 character: 0

This happens because:

  1. TRON requires base58 address format (starts with T, 34 chars)
  2. The API may return EVM format (0x...) or hex format (41...)
  3. The transaction creation fails when passing wrong address format

Solution

1. Add address validation utilities (lib/chain.ts)

  • isValidTronBase58Address() - validate T... format
  • isTronHexAddress() - detect 41... format
  • isEvmAddress() - detect 0x... format
  • validateDepositAddress(chain, address) - returns error message if invalid

2. Validate before transaction (useForge.ts)

const addressError = validateDepositAddress(externalChain, depositAddress)
if (addressError) {
  setState({ step: 'error', orderId: null, error: addressError })
  return
}

3. Helpful error messages

  • Invalid TRON address: received EVM format (0x...), expected base58 format (T...)
  • Invalid TRON address: received hex format (41...), expected base58 format (T...)

Tests

File Tests
chain.test.ts 19 new tests for address validation
useForge.test.ts 2 new tests for TRON handling
Total 59 tests passing

Root Cause Note

The actual fix requires the backend API to return TRON addresses in base58 format. This PR adds client-side validation to catch the error early with a helpful message, rather than failing deep in the transaction signing flow.

Problem:
- TRON chain requires base58 address format (T...), but API may return
  EVM format (0x...) causing 'Invalid base58 character: 0' error

Solution:
- Add validateDepositAddress() to validate address format per chain
- Add isValidTronBase58Address(), isTronHexAddress(), isEvmAddress()
- Validate deposit address before creating transaction in useForge
- Show descriptive error if address format is wrong

Tests:
- 19 new tests for chain utilities
- 2 new tests for TRON address handling in useForge
- All 59 tests passing
@Gaubee
Gaubee merged commit b47d425 into main Jan 11, 2026
5 checks passed
@Gaubee
Gaubee deleted the fix/forge-deposit-address branch January 11, 2026 15:24
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.

1 participant