Skip to content

Instantly share code, notes, and snippets.

@marco-jardim
Last active April 11, 2022 15:09
Show Gist options
  • Select an option

  • Save marco-jardim/4b2721586145622ee9ce45a6f099a8d6 to your computer and use it in GitHub Desktop.

Select an option

Save marco-jardim/4b2721586145622ee9ce45a6f099a8d6 to your computer and use it in GitHub Desktop.
TypedData Example ethers.js
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