Modify Respective Function
Make a method which supports native meta transactions
Now using all the information from previous sections, let's make a new method that sets the quote from the user but this time we do it with native meta transaction support.
Create a new function to include the following params
userAddress
newQuote
sigR
sigS
sigV
function setQuoteMeta(address userAddress,string memory newQuote, bytes32 sigR, bytes32 sigS, uint8 sigV) public {
}Add an instance of the struct
// Make an instance of the predefined struct
MetaTransaction memory metaTx = MetaTransaction({
nonce: nonces[userAddress],
from: userAddress
});Hash message in EIP712 compatible form
// Hash the mandatory fields of EIP712
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(META_TRANSACTION_TYPEHASH, metaTx.nonce, metaTx.from))
)
);Verify the Signatures On Chain
Add the Necessary Logic
Increment Nonce for Replay Protection
Complete Code Snippet
Checkout the full working code here https://github.com/bcnmy/dapp-demo
Congratulations! You have successfully integrated meta transactions in your Smart Contracts
In the next section, Let's see what changes we need to do on the Client side.
Last updated
Was this helpful?