I tried replicating the instructions in this article to implement EIP712 signing, however, it doesn't appear to work for web3 1.0 versions.


Here's the working signing example from the above article:


And here's the code from the example that works on earlier web3 versions:

const domain = [
  { name: "name", type: "string" },
  { name: "version", type: "string" },
  { name: "chainId", type: "uint256" },
  { name: "verifyingContract", type: "address" },
  { name: "salt", type: "bytes32" },

const bid = [
  { name: "amount", type: "uint256" },
  { name: "bidder", type: "Identity" },

const identity = [
  { name: "userId", type: "uint256" },
  { name: "wallet", type: "address" },

const chainId = parseInt(web3.version.network, 10);

const domainData = {
  name: "My amazing dApp",
  version: "2",
  chainId: chainId,
  verifyingContract: "0x1C56346CD2A2Bf3202F771f50d3D14a367B48070",
  salt: "0xf2d857f4a3edcb9b78b4d503bfe733db1e3f6cdc2b7971ee739626c97e86a558"

var message = {
  amount: 100,
  bidder: {
    userId: 323,
    wallet: "0x3333333333333333333333333333333333333333"

const data = JSON.stringify({
  types: {
    EIP712Domain: domain,
    Bid: bid,
    Identity: identity,
  domain: domainData,
  primaryType: "Bid",
  message: message

const signer = web3.toChecksumAddress(web3.eth.accounts[0]);

    method: "eth_signTypedData_v3",
    params: [signer, data],
    from: signer
  function(err, result) {
    if (err || result.error) {
      return console.error(result);

    const signature = parseSignature(result.result.substring(2));

    res.style.display = "block";
    res.value = genSolidityVerifier(signature, signer, chainId);

This works with maybe a few minor modifications, except for the last section, which I'm not sure how to update. If I simply update the sendAsync section to the below, I get a stringified version of the data to sign to show up in MetaMask, however, it's not very readable and the better solution would be to get the proper object format like the example.

web3.eth.personal.sign(data, props.address ,'');

Any ideas are appreciated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.