web3.eth.sign signs the data to be sent with the specified account, the account needs to be unlocked.
transfer:
web3.eth.sign(address, dataToSign, [, callback])
parameter:
- address: String - the address to use for the signature
- dataToSign: String - the data to sign
- callback: Function - (optional) callback function used to support asynchronous execution 7.
return value:
- String - The signed data. The returned value corresponds to the string signed by ECDSA (Elliptic Curve Digital Signature Algorithm).
r = signature[0:64]
s = signature[64:128]
v = signature[128:130]
Note that if you use ecrecover, the v value here is 00 or 01, so if you want to use them, you need to convert the v value here to an integer and add 27. In the end the value you will use will be 27 or 2813.
Example:
var result = web3.eth.sign("0x135a7de83802408321b74c322f8558db1679ac20",
"0x9dd2c369a187b4e6b9c402f030e50743e619301ea62aa4c0737d4ef7e10a3d49"); // second argument is web3.sha3("xyz")
console.log(result); // "0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400"
If you want to learn Ethereum DApp development efficiently , you can visit the most popular online interactive tutorials provided by Huizhi.com:
More other content is also available on this Ethereum blog .