Skip to content

fix: use TronGrid API to build approve tx with raw_data_hex#65

Open
Tristenyang wants to merge 2 commits intoBofAI:mainfrom
Tristenyang:fix/tron-signer-approve-raw-data-hex
Open

fix: use TronGrid API to build approve tx with raw_data_hex#65
Tristenyang wants to merge 2 commits intoBofAI:mainfrom
Tristenyang:fix/tron-signer-approve-raw-data-hex

Conversation

@Tristenyang
Copy link
Copy Markdown

Description

TronClientSigner.ensure_allowance() fails when approving token allowance on TRON networks.

The root cause is that tronpy's build() + to_json() produces a transaction dict without raw_data_hex, but
agent-wallet's TronSigner.sign_transaction() requires it:

InsufficientAllowanceError: Approval transaction failed: Tron sign_transaction failed:
Payload must be an unsigned transaction with {raw_data_hex}.

This PR switches from tronpy local transaction building to the TronGrid HTTP API (wallet/triggersmartcontract),
which returns the full transaction object including raw_data_hex. Also uses base58-decoded 41-prefixed hex
addresses for TronGrid API compatibility, and strips the 41 prefix for ABI-encoded parameters.

Closes #64

Tests

  • ruff check and ruff format --check pass with no issues
  • 189/190 existing tests pass; the 1 failure (test_evm_address_converter_normalizes_to_checksum) is pre-existing on
    main and unrelated to this change
  • Manually verified on Tron Nile testnet with bankofai-x402==0.5.8 and bankofai-agent-wallet==2.4.0: token approve
  • x402 payment flow completed successfully

Checklist

  • I have formatted and linted my code
  • All new and existing tests pass
  • My commits are signed (required for merge)

@boboliu-1010
Copy link
Copy Markdown
Collaborator

Thanks for the contribution. I checked this against the issue and it does address the immediate raw_data_hex problem, but we’re going with a smaller internal fix instead.

The main reason is that this PR changes the approval success semantics: it treats wallet/broadcasttransaction acceptance as success, while the current implementation waits for the receipt and checks the final execution result on-chain. We want to preserve that behavior to avoid reporting successful approvals for transactions that were only broadcast but later failed during execution.

We’ve opened #66, which fixes the signer payload compatibility issue without changing the existing transaction lifecycle semantics.

Appreciate you identifying the right failure point.

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.

TronClientSigner.ensure_allowance fails: tronpy build() missing raw_data_hex

2 participants