Package Exports
- nano-rpc-client
- nano-rpc-client/dist/browser.js
- nano-rpc-client/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nano-rpc-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Nano RPC client
A simple and strongly typed client for Nano's RPC, written in Typescript.
Usage
In node, you have to provide a fetch
function
import NanoRpcClient from 'nano-rpc-client'
import nodeFetch from 'node-fetch'
const client = new NanoRpcClient('https://my.nano.node/rpc', nodeFetch)
If you're in the browser, window.fetch
is used by default
import NanoRpcClient from 'nano-rpc-client'
const client = new NanoRpcClient('https://my.nano.node/rpc')
RPC command arguments and their results are strongly typed
const info = await client.accountInfo('nano_1pnano1yzoxyk11geczosh1bwh97w5t1kfmokwz8hkgiy55h6a7rz6dyr1tm')
info.balance // this is a bigint
info.confirmedBalance // this throws an error at compile time because it doesn't exist
const confirmedInfo = await client.accountInfo('nano_1pnano1yzoxyk11geczosh1bwh97w5t1kfmokwz8hkgiy55h6a7rz6dyr1tm', { includeConfirmed: true })
confirmedInfo.confirmedBalance // this exists (and is a bigint) at compile time because you added the `includeConfirmed` option
You can pass an AbortSignal
to all calls to cancel them
const controller = new AbortController()
const confirmedInfo = await client.accountInfo('nano_1pnano1yzoxyk11geczosh1bwh97w5t1kfmokwz8hkgiy55h6a7rz6dyr1tm', undefined, { abortSignal: controller.signal })
if('someCondition')
controller.abort()
Errors in the RPC command (normally returned in the body) are thrown as RpcError
s that contain a message
try {
const info = await client.accountInfo('')
} catch (e) {
console.log(e.message) // logs "Bad account number"
}
Goals
- To be the de facto JS RPC client, with strong argument typing and great autocomplete
- To eventually be included as an official package of the nano ecosystem (meaning, distributed under an easily recognizable name like
@nano/rpc
or@nano-utils/rpc
or something like that) - To support the most current version of the RPC spec
- In the future, validate arguments before the request is made (for example, validate nano address strings or number strings)
Non-goals
- To support versions of the RPC spec other than latest