Develop Thorchain dApps

Transfer request

const { asset, from, recipient, amount, memo } = {
  asset: {
    chain: "THOR",
    symbol: "RUNE",
    ticker: "RUNE",
  },
  from: 'xxxx',
  recipient: 'yyyy',
  amount: {
    amount: 500,
    decimals: 8
  },
  memo: 'hint'
};
window.xfi.thorchain.request(
  {
    method: 'transfer',
    params: [
      {
        asset,
        from,
        recipient,
        amount,
        memo,
      },
    ],
  },
  (error, result) => {
    console.debug(error, result);
    this.lastResult = { error, result };
  }
);

Deposit request

const { asset, from, recipient, amount, memo } = {
  asset: {
    chain: "THOR",
    symbol: "RUNE",
    ticker: "RUNE",
  },
  from: 'xxxx',
  recipient: 'yyyy',
  amount: {
    amount: 500,
    decimals: 8
  },
  memo: 'hint'
};
window.xfi.thorchain.request(
  {
    method: 'deposit',
    params: [
      {
        asset,
        from,
        recipient,
        amount,
        memo,
      },
    ],
  },
  (error, result) => {
    console.debug(error, result);
    this.lastResult = { error, result };
  }
);

Accounts request

if (window.xfi && window.xfi.thorchain) {
  window.xfi.thorchain.request(
    {method: 'request_accounts'},
    (error, accounts) => console.log(`Thorchain accounts ${accounts}`)
  );
}

Result example

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

Events

chainChanged

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

accountsChanged

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