Created
November 15, 2023 21:33
-
-
Save bonustrack/2ac78803500c07fd99b2300c3f0ef943 to your computer and use it in GitHub Desktop.
Generate offchain votes for Snapshot X
This file contains 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 { Wallet } = require('@ethersproject/wallet'); | |
const space = '0x1a9fdebf62ed1312354394979c2000d4e7912f9a'; | |
const proposalId = 1; | |
const choice = 1; // 1: Approve, 2: Reject, 3: Abstain | |
const chainId = 5; // Goerli | |
const signer = new Wallet.createRandom(); // Or new Wallet(PRIVATE_KEY); | |
const voter = signer.address; | |
const domain = { | |
name: 'snapshot-x', | |
version: '1.0.0', | |
chainId, | |
verifyingContract: space | |
}; | |
const voteTypes = { | |
Vote: [ | |
{ name: 'space', type: 'address' }, | |
{ name: 'voter', type: 'address' }, | |
{ name: 'proposalId', type: 'uint256' }, | |
{ name: 'choice', type: 'uint8' } | |
] | |
}; | |
const message = { | |
space, | |
voter, | |
proposalId, | |
choice | |
}; | |
signer._signTypedData(domain, voteTypes, message).then(sig => { | |
console.log('Message', message); | |
console.log('Signature', sig); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment