Maya Protocol

Develop Maya dApps

Transfer request

const { asset, from, recipient, amount, memo, gasLimit } = {
  asset: {
    chain: "MAYA",
    symbol: "CACAO",
    ticker: "CACAO",
  },
  from: 'xxxx',
  recipient: 'yyyy',
  amount: {
    amount: 500,
    decimals: 10
  },
  memo: 'hint',
  gasLimit: '10000000', // optional
};
window.xfi.mayachain.request(
  {
    method: 'transfer',
    params: [
      {
        asset,
        from,
        recipient,
        amount,
        memo,
        gasLimit,
      },
    ],
  },
  (error, result) => {
    console.debug(error, result);
    this.lastResult = { error, result };
  }
);

Deposit request

const { asset, from, recipient, amount, memo, gasLimit } = {
  asset: {
    chain: "MAYA",
    symbol: "CACAO",
    ticker: "CACAO",
  },
  from: 'xxxx',
  recipient: 'yyyy',
  amount: {
    amount: 500,
    decimals: 10
  },
  memo: 'hint',
  gasLimit: '10000000', // optional
};
window.xfi.mayachain.request(
  {
    method: 'deposit',
    params: [
      {
        asset,
        from,
        recipient,
        amount,
        memo,
        gasLimit,
      },
    ],
  },
  (error, result) => {
    console.debug(error, result);
    this.lastResult = { error, result };
  }
);

Accounts request

if (window.xfi && window.xfi.mayachain) {
  window.xfi.mayachain.request(
    {method: 'request_accounts', params: []},
    (error, accounts) => console.log(`MayaChain accounts ${accounts}`)
  );
}

Result example

{
  "error": null,
  "result": [ "maya1h0n0vegjfcrwt9rrxvhuhl83k400lcgt6r3525" ]
}

Events

chainChanged

if (window.xfi && window.xfi.mayachain) {
  const provider = window.xfi.mayachain;
  provider.on("chainChanged", (obj) => {
    console.log(`chainChanged::${obj.chainId}`, obj);
  });
}

accountsChanged

if (window.xfi && window.xfi.mayachain) {
  const provider = window.xfi.mayachain
  provider.on("accountsChanged", (obj) => {
      console.log(`accountsChanged::${obj.chainId}`, obj);
  });
}

Last updated

XDEFI Technologies 2024