Skip to content

Instantly share code, notes, and snippets.

@fabdarice
Created May 10, 2018 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabdarice/9193d2b75edb846ff818ec086e8438be to your computer and use it in GitHub Desktop.
Save fabdarice/9193d2b75edb846ff818ec086e8438be to your computer and use it in GitHub Desktop.
event Debug(bytes32 message, uint8 v, bytes32 r, bytes32 s, address to, uint256 value);
function transferWithSignature(bytes32 _hashMessage, uint8 _v, bytes32 _r, bytes32 _s, address _to, uint256 _value) public onlyOwner {
Debug(_hashMessage, _v, _r, _s, _to, _value);
}
// This outputs :
Debug(message: 0x592fa743889fc7f92ac2a37bb1f5ba1daf2a5c84741ca0e0061d243a2e6707ba, v: 27, r: 0x410d09389efb07d5930183062324305b4891f48920d40afb1ea4c9f127f6c5c3, s: 0x5f5cff84353dbce91769da597b9e2314bf5a8140620f09ce1eb3e4bd25d3afa4, to: 0x0000000000000000000000000000000000000000, value: 1.117485660423987862439666034562377252282925994837e+48)
var msg = "HELLO"
var hashMsg = web3.utils.sha3(msg)
var signature = await web3.eth.sign(hashMsg, accounts[0])
signature = signature.substr(2, signature.length)
const r = '0x' + signature.substr(0, 64)
const s = '0x' + signature.substr(64, 128)
var v = web3.utils.toDecimal('0x' + signature.substr(128, 130))
v = v < 27 ? v + 27 : v
await instance.transferWithSignature(hashMsg, v, r, s, accounts[0], web3.utils.toWei("2", 'ether'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment