A high-level developer friendly interface to interact with Bitcoin Cash (BCH) network (prototype stage)
- Before you begin
- Overview of packages
|This code is in a beta stage, so there is no backwards-compatibility guarantee.
Mainnet-js provides a developer friendly API to develop BCH applications.
It is an OpenAPI 3 specification (swagger), implemented as a library in typescript. That library is then used in a generated express server to provide a REST service. And that service can be deployed in a production stack via docker.
However, the typescript library is also compiled for use directly in nodejs, or as ECMA script for webapps, or as a webpack bundle for use from a single file.
So it can be used in the browser, nodejs, electrum apps, WebWorkers and the like.
The core bitcoin library is @bitauth/libauth which provides fast battle-tested crypto related functions using wasm binaries in WebAssembly.
mainnet is currently developed and tested node v14, if your node version is very old or very new, you may have issues getting started. Check the nodejs version first.
nvm to experiment if your issue occurs with different versions of node.
To run the rest service under docker (recommended) use:
docker pull mainnet/mainnet-rest
docker run -d --env WORKERS=5 -p 127.0.0.1:3000:80 mainnet/mainnet-rest
See the full documentation for more installation and configuration details.
To install mainnet as a dependency of your webapp use:
yarn add mainnet-js
To include contracts functionality, use the following packages:
yarn add @mainnet-cash/contract
See the full documentation for notes and examples for bundling mainnet-js in your project.
It may be possible to use a generated client in your preferred programming language to interact with your REST service.
If you have docker installed, you can generate clients in a particular language from the project folder using:
yarn api:build:client <generator_name>
For a list of generators see:
If you need additionalProperties passed to the client generator, these may be added in the wrapper script
This project contains a number of smaller projects in a mono-repo structure, with each package located in the packages folder.
|REST Express Server
Additionally, a live version of the current REST api is available for viewing at rest-unstable.mainnet.cash
Please see the contributing guide for more detailed information.