fix: include sender address in gas estimation for ERC-20 compatibility#10
Closed
ryanRfox wants to merge 2 commits intoradiustechsystems:mainfrom
Closed
fix: include sender address in gas estimation for ERC-20 compatibility#10ryanRfox wants to merge 2 commits intoradiustechsystems:mainfrom
ryanRfox wants to merge 2 commits intoradiustechsystems:mainfrom
Conversation
The estimateGas() method was not including the 'from' address when calling eth_estimateGas RPC. This caused ERC-20 token transfers to fail with "ERC20: transfer from the zero address" because Ethereum nodes default to address(0) when from is not provided. Changes: - Add optional 'from' parameter to estimateGas() method - Pass signer's address from prepareTx() when available - Add tests for ERC-20 transfers and gas estimation This fix aligns with how other EVM SDKs handle gas estimation: - ethers.js v6: automatically includes from when using a Signer - viem: requires account parameter explicitly for estimateGas The fix is backward compatible - existing code without 'from' continues to work for operations that don't depend on msg.sender.
c8af555 to
80c74bb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical bug where ERC-20 token transfers fail with
ERC20: transfer from the zero addressduring gas estimation. The fix adds proper sender address handling to theestimateGas()method.Fixes #9
Changes
from?: Addressparameter toestimateGas()methodprepareTx()to pass the signer's address toestimateGas()when availablefromis requiredProblem
When calling
eth_estimateGaswithout afromaddress, Ethereum nodes default toaddress(0). This causes any contract that validatesmsg.senderto fail during gas estimation.Before (Broken)
After (Fixed)
How Other SDKs Handle This
fromwhen transaction is connected to a Signeraccountparameter forestimateGasOur fix aligns with ethers.js behavior - automatically including the sender when available while maintaining backward compatibility.
Testing
New Tests Added (6 tests in
test/gas-estimation.test.ts)estimateGaswith explicitfromparameter returns valid estimateestimateGaswithfromparameter works for contract callsestimateGaswithoutfromworks for native transfersestimateGaswithoutfromworks for contract deploymentsContract.executecorrectly estimates gas for ERC-20 transfersTest Results
Manual Verification
Successfully transferred SBC/ISB tokens on Radius testnet after applying the fix.
Breaking Changes
None - This fix is fully backward compatible:
estimateGas(tx)continues to work (from defaults to undefined)fromparameter is optionalChecklist