bdledger-sdk

BDLedger SDK for Node.js

Usage no npm install needed!

<script type="module">
  import bdledgerSdk from 'https://cdn.skypack.dev/bdledger-sdk';
</script>

README

BDLedger SDK for Node.js

npm package

Installation

npm install --save bdledger-sdk

Set esModuleInterop to true in your `tsconfig.json.

Usage

Example:

import { Bdledger, blockToHexView, transactionToHexView } from 'bdledger-sdk'

const bdledger = new Bdledger('localhost:2401')

test()

async function test() {
  const version = await bdledger.clientVersion()
  console.log(version)

  const ledgers = await bdledger.getLedgers()
  console.log(ledgers)

  const tx = await bdledger.getTransactionByHash({
    ledger: 'default',
    hash: Buffer.from('52e050aa413dc5a3b32488c4fd0aefb103f8e667', 'hex'),
  })
  if (tx) {
    console.dir(transactionToHexView(tx))
  }

  let b = await bdledger.getBlockByHash({
    ledger: 'default',
    hash: Buffer.from('572b7531addccbee30ebb5d9a77544a0f2229cb0', 'hex'),
    fullTransactions: false,
  })
  if (b) {
    console.dir(blockToHexView(b))
  }

  b = await bdledger.getBlockByHash({
    ledger: 'default',
    hash: Buffer.from('572b7531addccbee30ebb5d9a77544a0f2229cb0', 'hex'),
    fullTransactions: true,
  })
  if (b) {
    console.dir(blockToHexView(b))
  }
}

Please refer to:

Development

npm install
git submodule update --remote

Run in api/grpc

npm install

Generate gRPC code with:

npm run genGrpc

Generated gRPC code will be in src/grpc

Reference: gRPC examples for Node.js

Testing (TODO)

  1. Download mock server
  2. Run mock servers with --port={{port}}
  3. Set the port in test/client.test.js
  4. Run npm test