Skip to content

Fixed the eth_signTypedData_v4 example - correct use of from and im…#2775

Open
evshank wants to merge 1 commit intoMetaMask:mainfrom
evshank:evshank-patch-1
Open

Fixed the eth_signTypedData_v4 example - correct use of from and im…#2775
evshank wants to merge 1 commit intoMetaMask:mainfrom
evshank:evshank-patch-1

Conversation

@evshank
Copy link

@evshank evshank commented Mar 18, 2026

Description

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.

Issue(s) fixed

Fixes #

Preview

Checklist

  • If this PR updates or adds documentation content that changes or adds technical meaning, it has received an approval from an engineer or DevRel from the relevant team.
  • If this PR updates or adds documentation content, it has received an approval from a technical writer.

External contributor checklist

  • I've read the contribution guidelines.
  • I've created a new issue (or assigned myself to an existing issue) describing what this PR addresses.

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_v4 guide example to be runnable by adding missing @metamask/eth-sig-util and ethereumjs-util imports.

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.

…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 evshank requested review from a team as code owners March 18, 2026 09:02
@vercel
Copy link

vercel bot commented Mar 18, 2026

@evshank is attempting to deploy a commit to the Consensys Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant