Created
June 12, 2020 06:47
-
-
Save miguelmota/f75be1de350a0196db4a90cc96a5505f to your computer and use it in GitHub Desktop.
Web3.js eth_sign vs personal_sign
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') | |
const PrivateKeyProvider = require('truffle-privatekey-provider') | |
async function main() { | |
const address = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1' | |
const privateKey = '4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d' | |
const provider = new PrivateKeyProvider(privateKey, 'https://mainnet.infura.com') | |
const web3 = new Web3(provider) | |
const message = 'Hello world' | |
const sig1 = await web3.eth.personal.sign(message, address) | |
const sig2 = await web3.eth.sign(message, address) | |
console.log(sig1) | |
console.log(sig2) | |
console.log(sig1 === sig2) // true | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great snippet,
web3.eth.personal.sign()
now requires a password argument as the last argument