README
gRpc Client library to connect your app with forge powered blockchain node, all requests are sent over tcp, can be used in only Node.js environment.
A GRpcClient
instance mainly supports 3 groups of methods that saves you time when read/write data from/to blockchain.
rpcs
: read/write block/transaction/account/asset/chain/node data form/to the blockchainsenders
: shortcut methods that takes awallet
and atx
object, then do the signing, and sendingencoders
: shortcut methods that takes awallet
and atx
object, encode the transaction for later signing, used internally by senders
Table of Contents
Install
npm i @arcblock/grpc-client
// or
yarn add @arcblock/grpc-client
Usage
const GRpcClient = require('@arcblock/grpc-client');
const client = new GRpcClient('tcp://127.0.0.1:28210');
console.log({
rpcs: client.getRpcMethods(),
senders: client.getTxSendMethods(),
encoders: client.getTxEncodeMethods(),
});
(async () => {
// fetch forge change info
const { info } = await client.getChainInfo();
console.log('chainInfo', info);
// get block info
const stream = client.getBlock({ height: 11 });
stream
.on('data', function({ block }) {
console.log('blockInfo:', block);
})
.on('error', err => {
console.error('error', err);
});
})();
Examples
- Declare identify on the blockchain
- Get free token for newly created account
- Transfer assets between 2 accounts
- Transfer tokens between 2 accounts
- Exchange asset and token between 2 newly created accounts
- Create/update asset on the blockchain
- Consume newly create asset
- Stake for the connected node
Debugging
- If you are in Node.js:
DEBUG=@arcblock/grpc-client node script.js