@cerc-io/nitro-rpc-client (0.0.9)
Installation
@cerc-io:registry=
npm install @cerc-io/nitro-rpc-client@0.0.9
"@cerc-io/nitro-rpc-client": "0.0.9"
About this package
Nitro RPC Client
The nitro RPC client is a typescript client that can make RPC calls against a go-nitro RPC server.
Using the RPC Client
import { NitroRpcClient } from "./rpc-client";
const rpcPort = 4222;
const rpcClient = await NitroRpcClient.CreateHttpRpcClient(
`127.0.0.1:${rpcPort}/api/v1`
);
const counterParty = `0xDEADBEEF`;
const paymentChannelInfo = await rpcClient.DirectFund(counterParty);
console.log(
`Created channel ${paymentChannelInfo.ChannelId} with counterparty ${counterParty}`
);
await rpcClient.Close();
CLI Tool
The Nitro RPC comes with a CLI tool to trigger calls through the nitro RPC client.
npm exec -c 'nitro-rpc-client version'
The full list of API calls can be seen using the --help
flag.
❯ npm exec -c 'nitro-rpc-client --help'
nitro-rpc-client <command>
Commands:
nitro-rpc-client version Get the version of the Nitro RPC
server
nitro-rpc-client address Get the address of the Nitro RPC
server
nitro-rpc-client direct-fund Creates a directly funded ledger
<counterparty> channel
nitro-rpc-client direct-defund Defunds a directly funded ledger
<channelId> channel
nitro-rpc-client virtual-fund Creates a virtually funded payment
<counterparty> [intermediaries...] channel
nitro-rpc-client virtual-defund Defunds a virtually funded payment
<channelId> channel
nitro-rpc-client get-ledger-channel Gets information about a ledger
<channelId> channel
nitro-rpc-client get-payment-channel Gets information about a payment
<channelId> channel
nitro-rpc-client pay <channelId> Sends a payment on the given channel
<amount>
Options:
--help Show help [boolean]
--version Show version number [boolean]
-p, --port [number] [default: 4005]
Global install
yarn global add file:/path/to/local/go-nitro/packages/nitro-rpc-client
Replace /path/to/local/go-nitro/packages/nitro-rpc-client
with the actual path to local nitro-rpc-client package
Using the create-channels script
A test script is available to easily create channels. It requires 3 running RPC servers for Alice,Bob, and Irene. The go-nitro
repository contains a test script to start and run the required RPC servers
The create-channels
script will do the following (using the nitro-rpc-client
):
- Create a ledger channel between Alice and Irene.
- Create a ledger channel between Bon and Irene.
- Create some virtual channels.
- Make some payments.
- Close some virtual channels.
The script can be run from the packages/nitro-rpc-client
folder with npx ts-node ./scripts/client-runner.ts create-channels
.
The script also accepts a few options for the amount of channels to create/close.
❯ npx ts-node ./scripts/client-runner.ts create-channels --help
client-runner create-channels
Creates some virtual channels and makes some payments
Options:
--help Show help [boolean]
--version Show version number [boolean]
--createledgers Whether we attempt to create new ledger channels.
Set to false if you already have some ledger channels
created. [boolean] [default: true]
--numvirtual The number of virtual channels to create between Alice and
Bob. [number] [default: 5]
--numclosevirtual The number of virtual channels to close and defund.
[number] [default: 2]
--numpayments The number of payments to make from Alice to Bob.Each
payment is made on a random virtual channel
[number] [default: 5]
The --createledgers
option is helpful when you want to create some additional virtual channels using existing ledger channels. Setting it to false
means the script will just use the existing ledger channels when creating new virtual channels.
Dependencies
Dependencies
ID | Version |
---|---|
@statechannels/exit-format | ^0.2.0 |
ajv | ^8.12.0 |
axios | ^1.3.6 |
eventemitter3 | ^5.0.0 |
json-bigint | ^1.0.0 |
json-rpc-2.0 | ^1.5.1 |
nats | ^2.13.1 |
websocket | ^1.0.34 |
yargs | ^17.7.1 |
Development Dependencies
ID | Version |
---|---|
@types/ajv | ^1.0.0 |
@types/jest | 29.5.0 |
@types/json-bigint | ^1.0.4 |
@types/node | ^18.15.11 |
@types/websocket | ^1.0.5 |
@types/yargs | ^17.0.24 |
@typescript-eslint/eslint-plugin | ^5.59.0 |
@typescript-eslint/parser | ^5.59.0 |
eslint | ^7.17.0 |
eslint-config-prettier | ^8.5.0 |
eslint-plugin-import | ^2.26.0 |
eslint-plugin-jest | ^26.8.2 |
eslint-plugin-jsdoc | ^39.2.9 |
eslint-plugin-node | ^11.1.0 |
eslint-plugin-prettier | ^3.3.1 |
eslint-plugin-storybook | ^0.6.11 |
jest | 29.5.0 |
prettier | ^2.2.1 |
prettier-plugin-packagejson | ^2.2.18 |
ts-jest | 29.1.0 |
ts-node | ^10.9.1 |
typescript | ^4.6.3 |