Define Data To Sign

Lets structure everything together

Now we have designed our data structure and data types, let's bring everything together now to make it work and initialize our data with the real values to be signed as per our DApp.

Fetch user's nonce from the smart contract

const nonce = await contract.methods.getNonce(userAddress).call();

Create message object to include in the signing data

let message = {};
message.nonce = parseInt(nonce);
message.from = userAddress;

Prepare Data to Sign

const dataToSign = JSON.stringify({
    types: {
        EIP712Domain: domainType,
        MetaTransaction: metaTransactionType
      },
      domain: domainData,
      primaryType: "MetaTransaction",
      message: message
    });

Complete Code Snippet

const nonce = await contract.methods.getNonce(userAddress).call();

let message = {};
message.nonce = parseInt(nonce);
message.from = userAddress;

const dataToSign = JSON.stringify({
    types: {
        EIP712Domain: domainType,
        MetaTransaction: metaTransactionType
      },
      domain: domainData,
      primaryType: "MetaTransaction",
      message: message
    });

Last updated