Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simpleledgerinc/grpc-bchrpc-node
A BCHD gRPC client for node.js
https://github.com/simpleledgerinc/grpc-bchrpc-node
bchd
Last synced: about 2 months ago
JSON representation
A BCHD gRPC client for node.js
- Host: GitHub
- URL: https://github.com/simpleledgerinc/grpc-bchrpc-node
- Owner: simpleledgerinc
- Created: 2019-07-01T18:20:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T22:39:27.000Z (about 2 years ago)
- Last Synced: 2024-10-07T16:18:08.244Z (3 months ago)
- Topics: bchd
- Language: JavaScript
- Homepage:
- Size: 3.09 MB
- Stars: 11
- Watchers: 4
- Forks: 10
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## A BCHD gRPC client for node.js
This package provides a gRPC client for connecting to a BCHD full node.
### Install
`$ npm i grpc-bchrpc-node` (for web-browser based projects see [this](https://github.com/jcramer/grpc-bchrpc-web) version)
### Run Unit Tests
`$ git clone https://github.com/simpleledgerinc/grpc-bchrpc-node`
`$ npm i`
`$ npm test`### Optional: Rebuild gRPC generated js & d.ts from source (from `./bchrpc.proto`)
1. Install Protobuf Compiler from: https://github.com/protocolbuffers/protobuf
2. `$ npm i`
3. `$ npm run build`### Example usage
In this simple example we create a new client that connects to `bchd.greyh.at:8335` and calls the `getRawTransaction` rpc endpoint and prints the result to the console. We use `reversedHashOrder: true` to automatically reverse the txid endianness because BCHD expects to receive transaction hashes without endianness reversed.
```ts
let grpc = new GrpcClient();
let txid = "11556da6ee3cb1d14727b3a8f4b37093b6fecd2bc7d577a02b4e98b7be58a7e8";
let res = await grpc.getRawTransaction({ hash: txid, reversedHashOrder: true });
console.log(Buffer.from(res.getTransaction_asU8()).toString('hex'));
```See also the `test` directory for more examples of how to use.
### Tests
Some integration tests have been added. Extensive test coverage is not planned currently planned since this library is just a wrapper for BCHD's gRPC interface.
`$ npm test`
### Connecting to local BCHD
To connect to a local BCHD server you will need to utilize a self-signed certificate. Simply start BCHD using `rpccert=` and `rpckey=` flags pointing to a location where to save new certificate and private key files.
Then you can connect using the following `GrpcClient` constructor:
`const grpc = new GrpcClient({ url: "localhost:8335", rootCertPath: ""});`