-
-
Notifications
You must be signed in to change notification settings - Fork 246
fix: improve transaction type detection when contract code lookup fails #6206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
} | ||
|
||
if (!isContractAddress) { | ||
if (!isContractAddress && !hasReadAddressAsContractFailed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Simple Send Misclassified as Contract Interaction
When eth_getCode
fails, the updated logic bypasses the simpleSend
classification. This causes plain native asset transfers (those with no transaction data) to be incorrectly categorized as contractInteraction
. This regresses behavior for simple sends, especially on providers where getCode
intermittently errors (e.g., BNB), affecting UI and downstream logic.
Explanation
The issue happens when users tries to send a token but provider returns an error when trying to identify if the address is a contract or not. It's an edge case identified on BNB.
This PR improves transaction type detection logic when interacting with an address that may or may not be a contract. Previously, if an error occurred while trying to determine whether an address was a contract (via eth_getCode), the logic would default to returning
simpleSend
, which could lead to incorrect transaction classification.Key Changes
Improved error handling in
readAddressAsContract
:This helper now returns an error field alongside
contractCode
andisContractAddress
, enabling downstream logic to make better-informed decisions.Enhanced
determineTransactionType
logic:If
eth_getCode
fails, we no longer assume asimpleSend
. Instead, we:Fallback to checking the presence of transaction data and attempt decoding via the 4-byte method selector.
References
Fixes MetaMask/metamask-mobile#16574
Changelog
Checklist