Guest User

Untitled

a guest
Apr 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. window.voteForCandidate = function(candidate) {
  2. let candidateName = $("#candidate").val();
  3.  
  4. let msgParams = [
  5. {
  6. type: 'string', // Any valid solidity type
  7. name: 'Message', // Any string label you want
  8. value: 'Vote for ' + candidateName // The value to sign
  9. }
  10. ]
  11.  
  12. var from = web3.eth.accounts[0]
  13.  
  14. var params = [msgParams, from]
  15. var method = 'eth_signTypedData'
  16.  
  17. console.log("Hash is ");
  18. console.log(sigUtil.typedSignatureHash(msgParams));
  19.  
  20. // Invoke the eth_signTypedData function and pass in the message and account address.
  21. web3.currentProvider.sendAsync({
  22. method,
  23. params,
  24. from,
  25. }, function (err, result) {
  26. if (err) return console.dir(err)
  27. if (result.error) {
  28. alert(result.error.message)
  29. }
  30. if (result.error) return console.error(result)
  31. $("#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");
  32. $("#vote-for").html("Candidate: " + candidateName);
  33. $("#addr").html("Address: " + from);
  34. $("#signature").html("Signature: " + result.result);
  35. console.log('PERSONAL SIGNED:' + JSON.stringify(result.result))
  36. })
  37. }
Add Comment
Please, Sign In to add comment