Generate Signatures

Generate a typed signature using new rpc calls

In order to generate EIP-712 compatible signatures we will use rpc method eth_signTypedData_v4 The method parallels eth_sign

There are other rpc methods too namely eth_signTypedData, eth_signTypedData_v2, eth_signTypedData_v3 but latest version of this rpc method is eth_signTypedData_v4

web3.currentProvider.sendAsync(
{
   jsonrpc: "2.0",
   id: 999999999999,
   method: "eth_signTypedData_v4",
   params: [userAddress, dataToSign]
},
function(err, result) {
    if (err) {
        return console.error(err);
    }
    const signature = result.result.substring(2);
    const r = "0x" + signature.substring(0, 64);
    const s = "0x" + signature.substring(64, 128);
    const v = parseInt(signature.substring(128, 130), 16);
    }
    
    await myContract.methods
          .setQuoteMeta(userAddress, "A DApp is cooler with Meta Transactions", r, s, v)
          .send({
            from: userAddress
          });
);

To understand Ethereum signatures in detail, refer to this article

Checkout the full working code here https://github.com/bcnmy/dapp-demo

Watch the demo in Action at https://dapp.biconomy.io/

Now we have enabled native meta transactions in our DApp, let's integrate Biconomy for making our DApp gasless so uses can interact with it without having any ether in their wallet.

Last updated