Custom Implementation Approach
Implement meta transactions your own way
There can be many ways to enable gasless transactions in your dApp. For example, DAI token has enabled gasless transactions by introducing a permit function that allows a user to give allowance to other users by just providing EIP-712 style signature from their account and anyone can submit that permit transaction and pay the gas fees. The permit function implementation is DAI's way of enabling gasless transactions.
We have written some standard contracts (Audited) that can be used to enable gasless transaction functionality in your smart contract itself. So you are able to interact with your smart contracts directly in a gasless way with no other smart contracts involved.
Note: You still need a relayer infrastructure like Biconomy to relay those gasless transactions.
In order to send gasless transactions in your dApp via Biconomy using custom meta transaction implementation, the following two integration steps will be required
- 1.Smart Contract Changes
- 2.Client Side Changes
In order to allow your Smart Contract to accept meta transactions, it needs to get rid of the dependency on
msg.value. The simple way to enable this is to inherit one of the below mentioned smart contracts based on your signature requirements:
After inheriting either one of the above smart contracts, you need to use
msgSender()method wherever you use
That's it!! You have enabled native meta transaction support in your smart contract.
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 Biconomy Dashboard and get your API Key.
EIP712MetaTransaction base contract is responsible for signature verification and replay protection and calls the generic method
executeMetaTransactionmethod on itself by appending the user address at the end of call data. The
msgSender()method in your smart contract (inherited by EIP712MetaTransaction) does the rest by returning the correct address for any context. Use
msgSender()wherever you use
When the method you need to make gasless already has user signature as parameter for example
permit(...r,s,v), you can register the contract as Custom and directly register method name itself. Another use case is gasless token approvals on certain chains like Polygon as these contracts already inherit from EIP712MetaTransaction specs and have
executeMetaTransactionmethod available. Also, custom approach can allow you to define your custom structured signatures.