Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Latest commit

 

History

History
64 lines (53 loc) · 1.43 KB

README.md

File metadata and controls

64 lines (53 loc) · 1.43 KB

@mutadev/client

Examples

Basic

async function getTransaction() {
  const client = new Client();

  const raw = await client.composeTransaction({
    serviceName: 'asset',
    method: 'create_asset',
    payload: {
      name: Math.random().toString(),
      supply: 10000,
      symbol: Math.random().toString(),
    },
  });

  const hash = client.sendTransaction(account.signTransaction(raw));
  const tx = await retry(() => client.getTransaction(hash));
  console.log(tx);
  const receipt = await retry(() => client.getReceipt(hash));
  console.log(receipt);
}

Batch

async function batch() {
  const client = new Client();

  const tx1 = await client.composeTransaction({
    serviceName: 'asset',
    method: 'create_asset',
    payload: {
      name: Math.random().toString(),
      supply: 10000,
      symbol: Math.random().toString(),
    },
  });

  const tx2 = await client.composeTransaction({
    serviceName: 'asset',
    method: 'create_asset',
    payload: {
      name: Math.random().toString(),
      supply: 10000,
      symbol: Math.random().toString(),
    },
  });

  const hashes = await Promise.all([
    client.sendTransaction(account.signTransaction(tx1)),
    client.sendTransaction(account.signTransaction(tx2)),
  ]);

  const batchClient = new BatchClient();
  const receipts = await retry(() => batchClient.getReceipts(hashes));
  expect(receipts.every((receipt) => receipt.txHash)).toBe(true);
}