Moralis Gasless Transaction Tutorial

This is a thread to discuss the Moralis Gasless Transaction Repository (https://github.com/YosephKS/moralis-biconomy-metatransactions) we covered on YouTube.

We are here to help! If you have any questions about how to use it or how to set it up you can ask here!

3 Likes

Thanks for the tutorial. Can you create another one to demonstrate gasless wallet transfers using the biconomy gas tank?

Hey @spacoin, thanks for watching the video, gasless wallet transfer is impossible unfortunately because the only person that have access to the wallet fund (native token ETH/BNB/MATIC/AVAX/FTM) is the wallet itself. Therefore any transfer of funds to other address will only possible to be executed by the wallet itself.

On the other hand, gasless transaction that is executed to an EIP-2771 compliant smart contract can give access to relayer (such as Biconomy) to execute transaction on the user behalf, which ultimately enable the gasless transaction.

REMEMBER: gasless does not mean free (no gas fees paid)

However, if you want to transfer tokens such as ERC20/721/1155, it might be possible to do gasless transaction on it by defining a simple smart contract that you must approve first then transfer it on behalf of the user wallet.

1 Like

@YosephKS Thanks for the detailed reply. So I can create a relayer and smart contract to transfer a specific type of token from wallet A to wallet B that will always tap a designated wallet C to pay the gas fee? (The tx would fail if wallet C is empty.) I take it I would have to own wallets A+C or B+C

yess, well you don’t need to own any wallet, probably in this case wallet C is the Biconomy Relayer that will hold the native token in their Gas tank. But A and B can be any arbitrary wallet. However keep in mind since you are asking a smart contract to access other wallet’s fund, the user need to approve the transfer first from their wallet

That’s right. Only the sender needs to approve the tx… Can a single smart contract template be built for everyone to use?

Yeah sure thing that’s possible, basically you are creating like a library of smart contracts, then you can publish it to like npm where anyone can use it. Kinda like how OpenZeppelin library works

1 Like

I’m sure someone has built a smart contract like this. Let me see if I can find it… Thanks!

1 Like

Is there a way to extend the Moralis.transfer function to include a relayer object? Or, are there too many dependencies to support this type of a meta transaction?

I don’t think you can do that, Moralis.transfer is just regular transfer here, it does not interact with any smart contract and thus you can’t do metatransaction this way.

To do metatransaction, you need interaction with an EIP2771 smart contract, which then you can sign the transaction instead of making the transaction, giving access for the relayer to make the transaction on your behalf.

1 Like

Thanks! We’re working on a Biconomy / Gnosis implementation now. It would have been handy to have a Moralis Gasless Transfer function or plug-in.

so you’re trying to create a smart contract wallet that have gasless feature? actually that sounds amazing and possible!

Just make sure your Gnosis smart contract wallet to be EIP2771 compliant, otherwise you won’t be able to do that.

I’m fairly new and everything was good up until connecting the smart contract on Bsc mainnet. How do I get the ABI for Biconomy? thanks!

Hey @dash, thank you for watching the video :raised_hands: you can get the ABI for Biconomy here under src/contracts https://github.com/YosephKS/moralis-biconomy-metatransactions/tree/main/src/contracts, since we’re registering the SimpleStorage contract, you’ll need to copy the ABI from SimpleStorage.json.

Remember you don’t need to fetch the whole JSON file, just the abi field

Hi currently having issues trying to implement this in an existing project, have everything set up but get this error apiKey is required in options object when creating Biconomy object.

did you get the biconomy API key and put it in the environment variables?

Yes my ENV variables are currently not working but will look into that later as its more than likely a separate issues with my project itself. However I now get an Uncaught (in promise) TypeError: web3.setProvider is not a function when trying to set Biconomy as the provider.

1 Like

Hello Everyone,
I followed the steps and made made few modification to make it work on BSC Mainnet,
now the balance and network are showing correctly but the storage don’t show up only the button edit storage the part where i write the message end select the method seems to keep loading.
any idea ?

I have the same problem

Use the following line, after enableWeb3, to solve the problem

const web3 = new Web3(Moralis.provider);
1 Like