@arcblock/forge-sdk
v1.0.27-alpha.0 forge blockchain arcblock sdk nodejs
Forge Javascript SDK packages all in one
Table of Contents
Install
npm i @arcblock/forge-sdk
// OR
yarn add @arcblock/forge-sdk
Usage
ES5(commonjs)
Support Node.js
const ForgeSDK = require('@arcblock/forge-sdk');
// Connect to multi endpoints
ForgeSDK.connect('https://test.abtnetwork.io/api', { name: 'test' });
ForgeSDK.connect('https://zinc.abtnetwork.io/api', { name: 'zinc' });
ForgeSDK.connect('tcp://127.0.0.1:28210', { name: 'local' });
const sender = ForgeSDK.Wallet.fromRandom();
const receiver = ForgeSDK.Wallet.fromRandom();
// Declare on test chain
await ForgeSDK.declare({ moniker: 'sender', wallet: sender }, { conn: 'test' }).then(console.log);
await ForgeSDK.declare({ moniker: 'receiver', wallet: receiver }, { conn: 'test' }).then(console.log);
// Get zinc chain info
ForgeSDK.getChainInfo({ conn: 'zinc' }).then(console.log);
// Get local chain info
ForgeSDK.getChainInfo({ conn: 'local' }).then(console.log);
// Poke and transfer on test chain
await ForgeSDK.checkin({ wallet: sender }, { conn: 'test' }).then(console.log);
await ForgeSDK.transfer({ to: receiver.toAddress(), token: 1, wallet: sender }, { conn: 'test' }).then(console.log);
ES6
If you want to support both node.js and browser, please use lite version And the lite version only supports http connections
import ForgeSDK from '@arcblock/forge-sdk/lite';
ForgeSDK.connect('https://test.abtnetwork.io/api', { name: 'test' });
ForgeSDK.getChainInfo().then(console.log);
ForgeSDK.declare({
moniker: 'abcd',
wallet: ForgeSDK.Wallet.fromRandom(),
}).then(console.log);
Util
const ForgeSDK = require('@arcblock/forge-sdk');
const bn = ForgeSDK.Util.fromTokenToUnit(10, 16);
console.log(bn);
Wallet
const ForgeSDK = require('@arcblock/forge-sdk');
const wallet = ForgeSDK.Wallet.fromRandom();
console.log(wallet.toJSON());
Message
const ForgeSDK = require('@arcblock/forge-sdk');
const message = ForgeSDK.Message.createMessage('Transaction', {
from: 'xxx',
nonce: 1234,
itx: {},
});
console.log(message);
Packages Included
- graphql-client, available after
ForgeSDK.connect
- grpc-client, available after
ForgeSDK.connect
- forge-util, available on
ForgeSDK.Util
- did-util, available on
ForgeSDK.Util
- forge-wallet, available on
ForgeSDK.Wallet
- forge-message, available on
ForgeSDK.Message
npm i @arcblock/[email protected]
Metadata
- Apache-2.0
- Whatever
- wangshijun
- released 12/24/2019