fix: include sender address in gas estimation for ERC-20 compatibility #10
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