A TypeScript client for interacting with Verus RPC endpoints.
yarn add verusd-rpc-ts-client
import VerusdRpcInterface from 'verusd-rpc-ts-client';
const client = new VerusdRpcInterface(
'chain', // The chain to connect to
'http://localhost:27486', // RPC endpoint URL
{} // Optional axios config
);
constructor(
chain: string,
baseURL: string,
config?: AxiosRequestConfig,
rpcRequest?: <D>(req: RpcRequestBody<number>) => Promise<RpcRequestResult<D>>
)
Gets the balance for one or more addresses.
getAddressBalance(addresses: {
addresses: string[];
friendlynames?: boolean;
}): Promise<RpcRequestResult<{
balance: number;
received: number;
currencybalance: { [key: string]: number };
currencyreceived: { [key: string]: number };
currencynames?: { [key: string]: string };
}>>
Gets the transaction deltas for one or more addresses.
getAddressDeltas(addresses: {
addresses: string[];
friendlynames?: boolean;
}): Promise<RpcRequestResult<Array<{
satoshis: number;
txid: string;
index: number;
blockindex: number;
height: number;
address: string;
currencyvalues?: { [key: string]: number };
currencynames?: { [key: string]: string };
sent?: {
outputs: Array<{
addresses: string | string[];
amounts: { [key: string]: number };
}>;
};
}>>>
Gets the mempool transactions for one or more addresses.
getAddressMempool(addresses: {
addresses: string[];
friendlynames?: boolean;
}): Promise<RpcRequestResult<Array<{
satoshis: number;
txid: string;
index: number;
blockindex: number;
height: number;
address: string;
currencyvalues?: { [key: string]: number };
currencynames?: { [key: string]: string };
sent?: {
outputs: Array<{
addresses: string | string[];
amounts: { [key: string]: number };
}>;
};
}>>>
Gets the unspent transaction outputs for one or more addresses.
getAddressUtxos(addresses: {
addresses: string[];
friendlynames?: boolean;
}): Promise<RpcRequestResult<Array<{
address: string;
txid: string;
outputIndex: number;
script: string;
currencyvalues?: { [key: string]: number | undefined };
currencynames?: { [key: string]: string | undefined };
satoshis: number;
height: number;
isspendable: number;
blocktime: number;
}>>>
Gets information about a block.
getBlock(hash: string, verbosity?: number): Promise<RpcRequestResult<string | BlockInfo>>
Creates a vdxfid from a vdxfkey string, e.g. vrsc::data.example
getVdxfId(vdxfid: string): Promise<RpcRequestResult<{
vdxfid: string;
hash160result: string;
qualifiedname: {
name: string;
parentid: string;
};
bounddata?: {
vdxfkey: string;
uint256: string;
indexnum: string;
};
}>>
Gets information about an identity.
getIdentity(identityid: string): Promise<RpcRequestResult<{
identity: IdentityDefinition;
status: string;
canspendfor: boolean;
cansignfor: boolean;
blockheight: number;
txid: string;
vout: number;
proof?: string;
}>>
Gets the content of an identity.
getIdentityContent(identityid: string): Promise<RpcRequestResult<{
identity: IdentityDefinition;
status: string;
canspendfor: boolean;
cansignfor: boolean;
blockheight: number;
txid: string;
vout: number;
proof?: string;
}>>
Gets information about a currency.
getCurrency(currencyid: string): Promise<RpcRequestResult<CurrencyDefinition>>
Gets information about the current state of the blockchain.
getInfo(): Promise<RpcRequestResult<{
version: number;
protocolversion: number;
VRSCversion: string;
notarized: number;
prevMoMheight: number;
notarizedhash: string;
notarizedtxid: string;
notarizedtxid_height: string;
KMDnotarized_height: number;
notarized_confirms: number;
blocks: number;
longestchain: number;
timeoffset: number;
tiptime: number;
connections: number;
proxy: string;
difficulty: number;
testnet: boolean;
paytxfee: number;
relayfee: number;
errors: string;
CCid: number;
name: string;
p2pport: number;
rpcport: number;
magic: number;
premine: number;
eras: number;
reward: string;
halving: string;
decay: string;
endsubsidy: string;
veruspos: number;
chainid?: string;
notarychainid?: string;
}>>
Gets the current offers in the marketplace.
getOffers(): Promise<RpcRequestResult<OfferList>>
Gets a raw transaction by its ID.
getRawTransaction(txid: string, verbose?: boolean): Promise<RpcRequestResult<string | RawTransaction>>
Creates a new offer in the marketplace.
makeOffer(offer: {
offer: {
offerid: string;
offertype: string;
offerfrom: string;
offerto: string;
offeramount: number;
offercurrency: string;
acceptamount: number;
acceptcurrency: string;
};
}): Promise<RpcRequestResult<{
txid?: string;
hex?: string;
}>>
Sends a raw transaction to the network.
sendRawTransaction(hex: string): Promise<RpcRequestResult<string | RawTransaction>>
Funds a raw transaction with inputs.
fundRawTransaction(hex: string, options?: {
changeAddress?: string;
changePosition?: number;
includeWatching?: boolean;
lockUnspents?: boolean;
reserveChangeKey?: boolean;
feeRate?: number;
subtractFeeFromOutputs?: number[];
}): Promise<RpcRequestResult<{
hex: string;
changepos: number;
fee: number;
}>>
Sends currency to one or more addresses.
sendCurrency(params: {
amounts: { [address: string]: number };
currencyid: string;
fee?: number;
fromaddress?: string;
changeaddress?: string;
returntxtemplate?: boolean;
}): Promise<RpcRequestResult<string | {
outputtotals: { [currencyid: string]: number };
feeamount: number;
hextx: string;
}>>
Gets a map of the possible conversion paths from a given list of currencies.
getCurrencyConverters(currencyids: string[]): Promise<RpcRequestResult<Array<{
[key: string]: CurrencyDefinition;
}>>>
Lists all currencies in the system.
listCurrencies(params?: {
systemtype?: string;
startblock?: number;
endblock?: number;
}): Promise<RpcRequestResult<Array<{
currencydefinition: CurrencyDefinition;
bestheight?: number;
besttxid?: string;
besttxout?: number;
bestcurrencystate?: {
flags: number;
version: number;
currencyid: string;
reservecurrencies: Array<{
currencyid: string;
weight: number;
reserves: number;
priceinreserve: number;
}>;
initialsupply: number;
emitted: number;
supply: number;
currencies: {
[key: string]: {
reservein: number;
primarycurrencyin: number;
reserveout: number;
lastconversionprice: number;
viaconversionprice: number;
fees: number;
conversionfees: number;
priorweights: number;
};
};
primarycurrencyfees: number;
primarycurrencyconversionfees: number;
primarycurrencyout: number;
preconvertedout: number;
};
}>>>
Estimates the conversion outcome when converting through a PBaaS liquidity pool.
estimateConversion(params: {
currencyid: string;
amount: number;
convertto: string;
}): Promise<RpcRequestResult<{
estimatedcurrencyout: number;
inputcurrencyid: string;
netinputamount: number;
outputcurrencyid: string;
estimatedcurrencystate: {
currencies: {
[currencyid: string]: {
conversionfees: number;
fees: number;
lastconversionprice: number;
primarycurrencyin: number;
priorweights: number;
reservein: number;
reserveout: number;
viaconversionprice: number;
};
};
currencyid: string;
emitted: number;
flags: number;
initialsupply: number;
preconvertedout: number;
primarycurrencyconversionfees: number;
primarycurrencyfees: number;
primarycurrencyout: number;
reservecurrencies: Array<{
currencyid: string;
priceinreserve: number;
reserves: number;
weight: number;
}>;
supply: number;
version: number;
};
}>>
Gets the status of a Z operation.
zGetOperationStatus(operationid: string): Promise<RpcRequestResult<z_operation[]>>
Extracts the result from an RPC response, throwing an error if the response contains an error.
static extractRpcResult<D extends ApiResponse>(res: RpcRequestResult<D["result"]>): D["result"]
All methods return a Promise that resolves to a RpcRequestResult
object. This object can contain either a successful result or an error. Use the extractRpcResult
static method to handle errors automatically:
try {
const result = VerusdRpcInterface.extractRpcResult(await client.getAddressBalance({ addresses: ['address'] }));
// Use result
} catch (error) {
// Handle error
}
The client uses TypeScript types from the verus-typescript-primitives
package. Key types include:
CurrencyDefinition
: Represents a currency definitionIdentityDefinition
: Represents an identity definitionRawTransaction
: Represents a raw transactionBlockInfo
: Represents block informationOfferList
: Represents a list of offersz_operation
: Represents a Z operation
MIT