Common RPC APIs are available in all RPC services like full_node, farmer, harvester, wallet, etc.
You need to create RPC connection before actually sending rpc request to the service.
Please remember that all rpc API is provided as an async function.
const {RPCAgent} = require("chia-agent");
const {get_connections} = require("chia-agent/api/rpc/common");
const agent = new RPCAgent({
service: "full_node", // Can be any services. i.e. full_node, farmer, harvester, wallet, crawler
});
// Then call RPC function
const response = await get_connections(agent, {...});
// Once agent is instantiated, you can re-use it everytime you want to request crawler API.
/*
* You can instantiate `agent` with hostname/port.
* See https://github.com/Chia-Mine/chia-agent/blob/main/src/rpc/index.ts
*/
const agent = new RPCAgent({
protocol: "https",
host: "aaa.bbb.ccc",
port: 8559,
ca_cert: fs.readFileSync(...),
client_cert: fs.readFileSync(...),
client_key: fs.readFileSync(...),
});
const {RPCAgent} = require("chia-agent");
const {get_network_info} = require("chia-agent/api/rpc/common");
const agent = new RPCAgent({service: "farmer"}); // Can be any service like full_node, harvester, etc...
const response = await get_network_info(agent);
{
success: True;
network_name: str;
network_prefix: str;
genesis_challenge: str;
}
const {RPCAgent} = require("chia-agent");
const {get_connections} = require("chia-agent/api/rpc/common");
const agent = new RPCAgent({service: "farmer"}); // Can be any service like full_node, harvester, etc...
const response = await get_connections(agent, params);
{
node_type?: str;
}
{
connections: TConnectionGeneral[] | TConnectionFullNode[];
}
For content of TConnectionGeneral
,
see https://github.com/Chia-Mine/chia-agent/blob/main/src/api/types.ts
For content of TConnectionFullNode
,
see https://github.com/Chia-Mine/chia-agent/blob/main/src/api/ws/full_node/index.ts
const {RPCAgent} = require("chia-agent");
const {open_connection} = require("chia-agent/api/rpc/common");
const agent = new RPCAgent({service: "crawler"}); // Can be any service like full_node, harvester, etc...
const response = await open_connection(agent, params);
{
host: str;
port: uint16;
}
{
success: False;
error: str;
} | {
success: True;
}
const {RPCAgent} = require("chia-agent");
const {close_connection} = require("chia-agent/api/rpc/common");
const agent = new RPCAgent({service: "crawler"}); // Can be any service like full_node, harvester, etc...
const response = await close_connection(agent, params);
{
node_id: str;
}
{}
const {RPCAgent} = require("chia-agent");
const {stop_node} = require("chia-agent/api/rpc/common");
const agent = new RPCAgent({service: "crawler"}); // Can be any service like full_node, harvester, etc...
const response = await stop_node(agent);
{}
const {RPCAgent} = require("chia-agent");
const {get_routes} = require("chia-agent/api/rpc/common");
const agent = new RPCAgent({service: "crawler"}); // Can be any service like full_node, harvester, etc...
const response = await get_routes(agent);
{
routes: str[];
}
const {RPCAgent} = require("chia-agent");
const {healthz} = require("chia-agent/api/rpc/common");
const agent = new RPCAgent({service: "crawler"}); // Can be any service like full_node, harvester, etc...
const response = await healthz(agent);
{
success: "true";
}