npm.io
0.10.1 • Published 6 years ago

muta-sdk

Licence
MIT
Version
0.10.1
Deps
17
Size
292 kB
Vulns
1
Weekly
0
Stars
5

Muta SDK(WIP)

The JS/TS SDK for Muta(a High performance Blockchain framework). Allow you interact with Muta node's GraphQL service.

Quick Start

npm install muta-sdk

Example

The following code will shows

  1. How to interact with #[read] service
  2. How to sign a transaction
  3. How to sendTransaction
async function main() {
  // get metadata from the chain
  const metadataResponse = await client.queryServiceDyn({
    method: 'get_metadata',
    payload: '',
    serviceName: 'metadata',
  });

  console.log(metadataResponse);

  // Accounts with permission to modify metadata
  const admin = Muta.accountFromPrivateKey('0x...');

  // Preparing transaction
  const tx = await client.composeTransaction({
    method: 'update_metadata',
    payload: {
      // ...
    },
    serviceName: 'metadata',
  });
  const signedTx = admin.signTransaction(tx);
  const txHash = await client.sendTransaction(signedTx);
  const receipt = await client.getReceipt(txHash);

  console.log(receipt);
}

Create Service Binding

Before we create our custom binding, learn about what is a service in Muta. We'll still use AssetService as an example.

Development

  • nodejs >= 10
  • typescript >= 3.7
  • yarn
git clone https://github.com/nervosnetwork/muta-sdk-js
cd muta-sdk-js
yarn
yarn start