Ethereum Voting Dapp sign and verify
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
window.voteForCandidate = function(candidate) { | |
let candidateName = $("#candidate").val(); | |
let msgParams = [ | |
{ | |
type: 'string', // Any valid solidity type | |
name: 'Message', // Any string label you want | |
value: 'Vote for ' + candidateName // The value to sign | |
} | |
] | |
var from = web3.eth.accounts[0] | |
var params = [msgParams, from] | |
var method = 'eth_signTypedData' | |
console.log("Hash is "); | |
console.log(sigUtil.typedSignatureHash(msgParams)); | |
// Invoke the eth_signTypedData function and pass in the message and account address. | |
web3.currentProvider.sendAsync({ | |
method, | |
params, | |
from, | |
}, function (err, result) { | |
if (err) return console.dir(err) | |
if (result.error) { | |
alert(result.error.message) | |
} | |
if (result.error) return console.error(result) | |
$("#msg").html("User intends to vote for " + candidateName + ". Any one can now submit the vote to the blockchain on behalf of this user. Copy the values"); | |
$("#vote-for").html("Candidate: " + candidateName); | |
$("#addr").html("Address: " + from); | |
$("#signature").html("Signature: " + result.result); | |
console.log('PERSONAL SIGNED:' + JSON.stringify(result.result)) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment