Last active
April 11, 2022 15:09
-
-
Save marco-jardim/4b2721586145622ee9ce45a6f099a8d6 to your computer and use it in GitHub Desktop.
TypedData Example ethers.js
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
| const { TypedDataUtils } = require('ethers-eip712'); | |
| // (lots of code) | |
| const typedData = { | |
| types: { | |
| EIP712Domain: [ | |
| {name: "name", type: "string"}, | |
| {name: "version", type: "string"}, | |
| {name: "chainId", type: "uint256"}, | |
| {name: "verifyingContract", type: "address"}, | |
| ], | |
| MintInfo: [ | |
| { name: "Gen1TokenId", type: "uint256" }, | |
| { name: "trainer", type: "address" }, | |
| { name: "deadline", type: "uint256" }, | |
| ], | |
| }, | |
| primaryType: 'MintInfo', | |
| domain: { | |
| name: 'Gen2Trainer', | |
| version: '1', | |
| chainId: 31337, | |
| verifyingContract: gen2Trainer.address | |
| }, | |
| message: { | |
| 'Gen1TokenId': gen1TokenId, | |
| 'trainer': minter.address, | |
| 'deadline': deadline | |
| } | |
| } | |
| const digest = TypedDataUtils.encodeDigest(typedData); | |
| const ethMessageHash = ethers.utils.hashMessage(digest); | |
| const signed = await owner.signMessage(digest); | |
| const sigs = utils.splitSignature(signed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment