@arcblock/grpc-client

gRPC client to read/write data on forge powered blockchain

Usage no npm install needed!

<script type="module">
  import arcblockGrpcClient from 'https://cdn.skypack.dev/@arcblock/grpc-client';
</script>

README

grpc-client

styled with prettier docs Gitter

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 blockchain
  • senders: shortcut methods that takes a wallet and a tx object, then do the signing, and sending
  • encoders: shortcut methods that takes a wallet and a tx 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

Debugging

  • If you are in Node.js: DEBUG=@arcblock/grpc-client node script.js

Documentation

  • Complete method list can be found here: README.md
  • Rpc arguments and response structure can be found here: API.md