Skip to content

Instantly share code, notes, and snippets.

@bertolo1988
Created March 17, 2023 11:45
Show Gist options
  • Save bertolo1988/cc5e911bc2a995228ee7a3c818df635c to your computer and use it in GitHub Desktop.
Save bertolo1988/cc5e911bc2a995228ee7a3c818df635c to your computer and use it in GitHub Desktop.
Verify ethereum wallet ownership remotely.
/**
First install and run ganache.
> npm install ganache --global
> execute this code https://gist.github.com/bertolo1988/096d436f072d2513eb4ff1cd83201c47
**/
const Web3EthAccounts = require('web3-eth-accounts');
const PORT = 61063;
async function run() {
const accounts = new Web3EthAccounts(`ws://localhost:${PORT}`);
const account = accounts.create();
console.log(`Created account with address: ${account.address}`);
const message = `This is my address ${account.address}`;
const signatureObj = accounts.sign(message, account.privateKey);
const recovered = accounts.recover(message, signatureObj.signature);
console.log(`Address ownership is confirmed for address ${recovered}`);
}
run()
.then(() => {
console.log('done');
})
.catch((err) => {
console.error('failed', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment