Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
- })
- }
Add Comment
Please, Sign In to add comment