Nimiq JSON-RPC Client Library for Gleam
Important:
This library requires Gleam v1.9, as it uses a Github dependency.
Installation
gleam add nimiq_rpc
Usage
First, create a client instance:
import nimiq_rpc
pub fn main() {
let client = nimiq_rpc.client("http://localhost:8648")
// To add authentication information, use this function:
let client = nimiq_rpc.client_with_auth(
"http://localhost:8648",
"username",
"password",
)
}
Each RPC method has its own typed method in this library. The methods are ordered by dispatcher, just like they are in the Rust source code (but your editor’s auto-import should help you resolve each method name you want to use). The name of each method is the snake-case
version of the camelCase
method name.
import nimiq_rpc/consensus
import nimiq_rpc/blockchain
pub fn main() {
// ...
let assert Ok(has_consensus) = client |> consensus.is_consensus_established()
io.debug(has_consensus) // True or False
let assert Ok(number) = client |> blockchain.get_block_number()
io.debug(number) // For example 13424115
}
Further documentation of the individual methods can be found at https://hexdocs.pm/nimiq_rpc.