Skip to content

Instantly share code, notes, and snippets.

@sogoiii
Created June 9, 2017 05:55
Show Gist options
  • Save sogoiii/05a2f9c0cc01c3f1dffc7296ab04591e to your computer and use it in GitHub Desktop.
Save sogoiii/05a2f9c0cc01c3f1dffc7296ab04591e to your computer and use it in GitHub Desktop.
Create Ethereum Signatures
const Web3 = require('web3')
const provider = new Web3.providers.HttpProvider('http://localhost:8545')
const web3 = new Web3(provider)
function toHex(str) {
var hex = ''
for(var i=0;i<str.length;i++) {
hex += ''+str.charCodeAt(i).toString(16)
}
return hex
}
let addr = web3.eth.accounts[0]
let msg = 'I really did make this message'
let signature = web3.eth.sign(addr, '0x' + toHex(msg))
console.log(signature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment