Skip to content

Instantly share code, notes, and snippets.

@PhABC
Last active September 1, 2018 18:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhABC/3ed4642d90591e7752461addd0201264 to your computer and use it in GitHub Desktop.
Save PhABC/3ed4642d90591e7752461addd0201264 to your computer and use it in GitHub Desktop.
// Addresses
var contractAddress = "0xContractAddress";
var userAddress = "0xUserAddress";
// Message to sign : contract address + address to give access
var message = web3.sha3(contractAddress.substr(2) + userAddress.substr(2), {encoding: 'hex'})
// Signing message (with "\x19Ethereum Signed Message:\n32" as prefix by default)
web3.personal.sign(message, web3.eth.defaultAccount, (err, res) => sign = res)
//Extracting ECDSA variables
var r = sign.substr(0, 66);
var s = '0x' + sign.substr(66, 64);
var v = '0x' + sign.substr(130,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment