chia-daemon
v0.12.3
Published
A JS daemon client for chia rpc with dynamically generated end points
Downloads
27
Readme
chia-daemon
A JS client for chia daemon and https services with dynamically generated end points
Getting Started
npm install
npm test
Documentation
https://dkackman.github.io/chia-daemon/
Basic Usage
Each service is a field on the services
property of the ChiaDaemon
.
- Since all service calls go through the daemon there is no need for other endpoint configuration
- All RPC calls are async
- Since all rpc call are dynamically invoked there is no need to update the library with new Chia releases.
(i.e. if you invoke
daemon.wallet.foo()
it will call make an RPC to a function namedfoo
at that endpoint and error if it doesn't exist there)
import { ChiaDaemon, loadUIConfig } from 'chia-daemon';
const daemon = new ChiaDaemon(loadUIConfig(), 'my-chia-app');
const connected = await daemon.connect();
if (connected) {
const state = await daemon.services.full_node.get_blockchain_state();
console.log(state);
}
Also supports https
connections:
import { createHttpsService, createConnection } from "chia-daemon";
const connection = createConnection(
"wallet",
"localhost",
);
const wallet = createHttpsService(connection);
const response = await wallet.get_wallets({ include_data: true });
console.log(`You have ${response.wallets.length} wallets`);
Payload Helpers
Includes helper functions to get request payloads right:
Get the OpenAPI responseBody Schema Descriptor
console.log(daemon.services.full_node.getPayloadDescriptor('open_connection'));
{
type: 'object',
required: [ 'ip', 'port' ],
properties: {
ip: { type: 'string', format: 'ipaddress' },
port: { type: 'integer' }
}
}
Get a Payload Object Instance
const connection = daemon.services.full_node.makePayload('open_connection');
console.log(connection);
{ ip: '', port: 0 }
connection.ip = 'chia.net';
connection.port = 4444;
await daemon.services.full_node.open_connection(connection);