Fixed the eth_signTypedData_v4 example - correct use of from and im…#2775
Open
evshank wants to merge 1 commit intoMetaMask:mainfrom
Open
Fixed the eth_signTypedData_v4 example - correct use of from and im…#2775evshank wants to merge 1 commit intoMetaMask:mainfrom
from and im…#2775evshank wants to merge 1 commit intoMetaMask:mainfrom
Conversation
…ports The example using `eth_signTypedData_v4` contained errors: `from` was returned as an array (`web3.eth.getAccounts()`), but was used as an address string. The `sigUtil` and `ethUtil` imports were missing, which caused calls to `recoverTypedSignature_v4` and `toChecksumAddress` to fail. The alert messages and signature verification used an array instead of a single address. What has been fixed: The correct imports have been added: `import * as sigUtil from “@metamask/eth-sig-util”` and `import * as ethUtil from “ethereumjs-util”`. `from = accounts[0]` is used to pass a single address to RPC and for signature verification. The check `ethUtil.toChecksumAddress(recovered) === ethUtil.toChecksumAddress(from)` is now correct. `Alert` messages display a single address instead of an array. After these changes, the example is fully functional and complies with the recommended use of EIP-712 signatures with MetaMask.
|
@evshank is attempting to deploy a commit to the Consensys Team on Vercel. A member of the Team first needs to authorize it. |
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.
Description
The example using
eth_signTypedData_v4contained errors:fromwas returned as an array (web3.eth.getAccounts()), but was used as an address string.The
sigUtilandethUtilimports were missing, which caused calls torecoverTypedSignature_v4andtoChecksumAddressto fail.The alert messages and signature verification used an array instead of a single address.
What has been fixed:
The correct imports have been added:
import * as sigUtil from “@metamask/eth-sig-util”andimport * as ethUtil from “ethereumjs-util”.from = accounts[0]is used to pass a single address to RPC and for signature verification.The check
ethUtil.toChecksumAddress(recovered) === ethUtil.toChecksumAddress(from)is now correct.Alertmessages display a single address instead of an array.After these changes, the example is fully functional and complies with the recommended use of EIP-712 signatures with MetaMask.
Issue(s) fixed
Fixes #
Preview
Checklist
External contributor checklist
Note
Low Risk
Low risk documentation-only change that corrects sample code imports and address handling; no production logic affected.
Overview
Updates the
eth_signTypedData_v4guide example to be runnable by adding missing@metamask/eth-sig-utilandethereumjs-utilimports.Fixes account handling by selecting
from = accounts[0](instead of treating the full accounts array as an address) and uses that single address consistently for RPC params, checksum comparison, and error messaging during signature recovery/verification.Written by Cursor Bugbot for commit 704a557. This will update automatically on new commits. Configure here.