Standard EIP 2771 Approach
Secure Protocol For Native Meta Transactions
Last updated
Was this helpful?
Secure Protocol For Native Meta Transactions
Last updated
Was this helpful?
approach is a standardised way of sending Gasless transactions. Meta transaction aware recipient contracts only rely on a small trusted forwarder contract for their security. This contract verifies the signature and nonce of the original sender. Biconomy provides a default implementation of Forwarder which verifies the signature and forwards the call to the recipient smart contract.
In order to send gasless transactions in your dApp via Biconomy using standard meta transaction approach, the following two integration steps will be required
Smart Contract Changes (Making Contract Meta Transaction Compliant)
Client Side Changes
After inheriting above smart contract, you need to use _msgSender() method wherever you use msg.sender
Do add setTrustedForwarder(address _forwarder) method in your smart contract to change the address in future in case new implementations are introduced, as it's not a part of EIP-2771. You can add onlyOwner modifier to this function.
That's it!! You have now enabled native meta transaction support in your smart contract.
The Trusted Forwarder is responsible for signature verification and replay protection and forwards the transaction to your smart contract by appending the user address at the end of call data. The _msgSender() method in your smart contract (inherited by BaseRelayRecipient) does the rest by returning the correct address for any context. Use _msgSender() wherever you use msg.sender.
Your contract can be easily modified to securely accept meta-transactions whilst giving you the flexibility to change the meta transaction approach your dApp uses if your needs change. In the next section, we'll see the steps to start using EIP-2771 enabled gasless transactions.
Client Side Changes
Check out the next section on how to register your dApp on the dashboard.
With adherence to to enable native meta transactions in your contract, you can just inherit a simple contract and set the trusted forwarder address.
You can also use OpenZeppelin's as a base contract which allows you to set the trusted forwarder in the constructor and provides msgSender(). Note if any of your contracts have Context.sol as base then you need to override from both and use ERC2771Context.msgSender()
List of trusted forwarder addresses* per network can be found here
The next step is Biconomy's integration on the client side. This can either be done via SDK integration or API integration. For both cases, first, you need to register your dApp on and get your API Key.