0.10.1 • Published 4 years ago
muta-sdk v0.10.1
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@next
Example
Suppose the AssetService is in use, the bellow code shows how to create UDT(user define token) and how to transfer
- create an UDT call BTC
- check the balance
- transfer to another account
- check the balance again
import { Muta, utils } from './src';
import { AssetService } from './src/builtin';
const muta = new Muta({
endpoint: 'http://127.0.0.1:8000/graphql',
chainId: '0xb6a4d7da21443f5e816e8700eea87610e6d769657d6b8ec73028457bf2ca4036'
});
const client = muta.client;
const account = muta.accountFromPrivateKey(
'0x10000000000000000000000000000000000000000000000000000000000000000'
);
const service = new AssetService(client, account);
async function main() {
const supply = 22000000;
/* create an UDT call BTC */
const txHash = await service.createAsset({
name: 'BitCoin',
supply,
symbol: 'BTC'
});
const receipt = await client.getReceipt(toHex(txHash));
const createdAsset = JSON.parse(receipt);
console.log(utils.toHex(createdAsset.owner) === utils.toHex(account.address));
/* check the balance */
await client.waitForNextNEpoch(2);
const assetId = createdAsset.id;
const balance = await service.getBalance(assetId, account.address);
console.log(balance === supply);
/* transfer to another account */
const to = '0x2000000000000000000000000000000000000000';
const transferHash = await service.transfer({
asset_id: assetId,
to,
value: 500
});
await client.getReceipt(transferHash);
/* check the balance again */
await client.waitForNextNEpoch(1);
const balance2 = await service.getBalance(assetId, to);
console.log(balance2 === 500);
}
Links
Development
- nodejs >= 10
- typescript >= 3.7
- yarn
git clone https://github.com/nervosnetwork/muta-sdk-js
cd muta-sdk-js
yarn
yarn start
0.11.0-dev.4
4 years ago
0.11.3-dev.0
4 years ago
0.11.2-dev.0
4 years ago
0.11.1-dev.2
4 years ago
0.11.1-dev.1
4 years ago
0.11.1-dev.0
4 years ago
0.11.0-dev.3
4 years ago
0.11.0-next.feature.1816be9
4 years ago
0.11.0-dev.2
4 years ago
0.11.0-dev.1
4 years ago
0.11.0-dev.0
4 years ago
0.11.0-alpha.14
4 years ago
0.11.0-alpha.13
4 years ago
0.11.0-alpha.12
4 years ago
0.11.0-alpha.5
4 years ago
0.11.0-alpha.4
4 years ago
0.11.0-alpha.3
4 years ago
0.11.0-alpha.2
4 years ago
0.10.0
4 years ago
0.10.1
4 years ago
0.9.2
4 years ago
0.8.0-alpha.1
4 years ago
0.9.0
4 years ago
0.8.0-alpha.0
4 years ago
0.7.0-alpha.6
4 years ago
0.7.0-alpha.5
4 years ago
0.7.0-alpha.4
4 years ago
0.7.0-alpha.3
4 years ago
0.7.0-alpha.2
4 years ago
0.7.0-alpha.1
4 years ago
0.7.0-alpha.0
4 years ago
0.6.0
4 years ago
0.5.0
4 years ago
0.4.0
4 years ago
0.3.0
4 years ago
0.2.0
4 years ago
0.1.0
4 years ago
0.0.1
4 years ago