nimiq-rpc-client-ts
v0.4.5
Published
A Nimiq RPC client for TypeScript
Downloads
1,082
Readme
Nimiq RPC Client for TypeScript
A fully typed Nimiq RPC client for TypeScript.
How to use
Installation
npm install nimiq-rpc-client-ts
NIMIQ_SECRET
The development network is currently in a phase where we request developers to set up their own nodes.
Usage
It is structured the same way as the Rust RPC Client
import { NimiqRPCClient } from 'nimiq-rpc-client-ts'
const url = "NODE_URL"
const client = new NimiqRPCClient(new URL(url))
const { data: currentEpoch, error: errorCurrentEpoch } = await client.blockchain.getEpochNumber()
if (errorCurrentEpoch || !currentEpoch)
throw new Error(errorCurrentEpoch?.message || 'No current epoch')
client.blockchain.getBlockNumber()
client.network.getPeerCount()
// use auto-complete to see all available methods, or checkout the class https://github.com/onmax/albatross-rpc-client-ts/blob/main/src/index.ts#L26
Call custom method
If you have a custom method in your RPC server, or the library is out of date, you can always make a raw
request:
interface ResponseType {
myResult: string
}
const { data, error } = await client.call<ResponseType>({ method: 'myAwesomeCustomMethod', params: ["FirstParameter", "secondParameter"] }, { /* some http options */ })
// ?^ ResponseType | undefined ?^ Use call for custom HTTP methods or `subscribe` for custom WS
Need help?
Check the tests for examples on how to use the client here.