Giter Club home page Giter Club logo

mexa-sdk's Introduction

description
Enable meta transactions or gasless transactions in your DApp by integrating Mexa SDK in your DApp

Biconomy SDK (Mexa)

Introduction

Biconomy SDK (Mexa), enables meta transactions or gasless transactions in your DApp (Decentralized Application) out of the box without any change in your smart contracts and just a few lines of code in your DApp to integrate mexa.

By using Mexa, dapp users are able to use the dapp and send transactions free of cost while developer pays the gas fee on their behalf as a part of user acquisition cost.

Let’s Get Started

  1. Go to Mexa Dashboard to register your DApp and methods on which to enable meta transactions and copy your DApp ID and API Key.
  2. Install Biconomy SDK (Mexa)
npm install @biconomy/mexa

Import and initialize mexa and web3

import Biconomy from "@biconomy/mexa";
const biconomy = new Biconomy(<web3 provider>,{dappId: <DApp ID>, apiKey: <API Key>});
web3 = new Web3(biconomy);

Note: <web3 provider> could be window.ethereum for Metamask or portis.provider for Portis and so on.

Initialize your dapp after mexa initialization

biconomy.onEvent(biconomy.READY, () => {
 // Initialize your dapp here
}).onEvent(biconomy.ERROR, (error, message) => {
 // Handle error while initializing mexa
});

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 initiated from user (registered in mexa dashboard also), mexa will ask for user’s signature and handle the transaction rather than sending signed transaction directly to blockchain from user’s wallet.

User Login

Biconomy uses Contract Wallet to relay the user’s transaction to your dapp smart contract so msg.sender in your smart contracts will be user contract wallet address, so user first needs to login to biconomy to use meta transactions. We just need users signature and public address to login.

Mexa exposes a login method to let your users login to biconomy to have their contract wallet created if user comes for the first time or just return existing contract wallet address for existing users.

biconomy.login(<public wallet address>, (error, response) => {
 if(error) {
 // Error while user login to biconomy
 return;
 }

 if(response.transactionHash) {
 // First time user. Contract wallet transaction pending. Wait for confirmation.
 } else if(response.userContract) {
 // Existing user login successful
 }
});

Contract Wallet Confirmation

When user login for the first time, you’ll get the transaction hash for user’s contract wallet creation transaction. On transaction confirmation mexa will emit a confirmation event.

biconomy.onEvent(biconomy.LOGIN_CONFIRMATION, (log) => {
 // User's Contract Wallet creation successful
});

Configuration

Biconomy constructor takes 2 parameters

const biconomy = new Biconomy(<existing web3 provider>, options);

<existing web3 provider>

object required

Any web3 provider that supports personal_sign, eth_accounts, eth_sendTransaction, eth_call RPC methods and web3 subscriptions.

For example, it can be window.ethereum for Metamask or portis.provider for Portis and so on.

options

object required

A json object having configuration values for initializing mexa sdk.

Key Name Value Required? Description
dappId

type: string

DApp ID can be found on mexa dashboard.

true Unique id assigned to each DApp on mexa dashboard.
apiKey

type: string

API Key can be found on mexa dashboard.

true Unique id assigned to each DApp that used to authenticate requests coming from mexa sdk.
strictMode

type: boolean

default value: false

Value could be true or false.

false

If strict mode is on, and method/api called by user is not registered on mexa dashboard then no transaction will be initiated.

If strict mode is off, and method called by user is not registered on mexa dashboard then existing provider will be used to send user transaction but in this case, the user will have to pay the transaction fee.

#### Example:

For metamask biconomy initialization code would look like:

let options = {
 dappId: <DAPP ID>,
 apiKey: <API KEY>,
 strictMode: true
};
const biconomy = new Biconomy(window.ethereum, options);

mexa-sdk's People

Contributors

tomarsachin2271 avatar divyan73 avatar arcticfloyd1984 avatar tarun1475 avatar sanchaymittal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.