Integrate Mexa SDK

Integrate Mexa on our client side to enable gasless transactions

Mexa can be installed either via npm repository or using standalone javascript file using html <script/> tag

Install Mexa via npm

npm install @biconomy/mexa

Import and Initialize Mexa

import { Biconomy } from "@biconomy/mexa";
const biconomy = new Biconomy(window.ethereum,{apiKey: "q9oEztJM8.e8ed08a7-5b38-48e3-b4c0-f66e6b66f407"});
web3 = new Web3(biconomy);

Initialize DApp after Mexa initialization

biconomy.onEvent(biconomy.READY, () => {
// Initialize your dapp here like getting user accounts etc
await window.ethereum.enable();
contract = new web3.eth.Contract(config.contract.abi, config.contract.address);
startApp();
}).onEvent(biconomy.ERROR, (error, message) => {
// Handle error while initializing mexa
console.log(error)
});

Congratulations πŸ‘

You have now enabled meta transactions in your DApp. Interact with web3 the way you have been doing it.

Now whenever there is a write transaction action(registered in mexa dashboard also) initiated from the user , Mexa will ask for user’s signature in an EIP-712 format and handle the transaction rather than sending signed transaction directly to blockchain from user’s wallet.

Check out the full code here https://github.com/bcnmy/dapp-demo​