Skip to content

How do I use the _TypedDataEncoder hash function for EIP712? #2738

Answered by ricmoo
gperezalba asked this question in Q&A
Discussion options

You must be logged in to vote

I found the issue. There are two separate APIs, one that operates on an instance and one that is static. You are using the static API on an instance; passing too many parameters in (the instance method .hash only access one parameter, value), so it is trying to evaluate the domain as the value.

You likely want just this:

// Remove this line:
// const typedDataEncoder = ...

// And use the static method directly; no new, no instance
const structHash = ethers.utils._TypedDataEncoder.hash(domain, types, value)

The instance APIs are designed for more low-level modifications to the encoding process, for debugging and for reusing parts of the encoding.

Let me know if that helps. :)

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@gperezalba
Comment options

Answer selected by gperezalba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2736 on February 24, 2022 09:11.