Search code examples
web3jsethers.js

How to implement SIWE using web3js


Is there a way to implement the client part of SIWE (Sign In With Ethereum) using Web3.js instead of ethers.js?

In SIWE's example they do:

const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const signature = await signer.signMessage(message)

But I can't figure out how to do something similar in my dapp which is build using web3.js


Solution

  • ethers.js signer.signMessage() takes a binary message, prepends it with the standardized prefix, and then requests the signer to sign the message.

    You can achieve the same with web3js eth.sign() method.

    const signature = await web3.eth.sign(message, signerAddress);