Running RPC service

If you run an exchange, you will likely want to interact with your Obyte node via RPC interface.

By default, RPC service is not enabled for security reasons. To enable it, you should start your headless node differently: instead of node start.js, cd to tools folder and start RPC-enabled node by running rpc_service.js:

cd tools
node rpc_service.js

The node works as usual, plus it listens on port 6332 of loop-back interface (configured in conf.js or conf.json) for JSON-RPC commands. The commands are getinfo, getnewaddress, validateaddress, getbalance, listtransactions, sendtoaddress. These are all simple HTTP request, but JSON-RPC can be used via WebSockets too and even make it listen to events.


The command returns information about the current state of the DAG.

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"getinfo", "params":{} }'

The command has no parameters and returns and object with 4 keys:

  • connections: number of incoming and outgoing connections

  • last_mci: the highest known main chain index (MCI)

  • last_stable_mci: last stable MCI (stability point)

  • count_unhandled: number of unhandled units in the queue. Large number indicates that sync is still in progress, 0 or small number means that the node is synced (it can occasionally go above 0 when new units are received out of order).


This command generates a new address in your wallet. You will likely want to use it to create a new deposit address and bind it to a user account.

Example usage:

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"getnewaddress", "params":{} }'

The command has no parameters and the response is a newly generated wallet address (32-character string).


This command validates a wallet address and returns true or false.

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"validateaddress", "params":["QZEM3UWTG5MPKYZYRMUZLNLX5AL437O3"] }'

You will likely want to use it before saving a withdrawal address for a customer.


Returns the balance of the specified address or the entire wallet.

Example usage for querying wallet balance:

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"getbalance", "params":{} }'

Querying balance of an individual address:

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"getbalance", "params":["QZEM3UWTG5MPKYZYRMUZLNLX5AL437O3"] }'

To query the balance of the entire wallet, parameters must be empty. To query the balance of an individual address, pass it as the only element of the params array.

The response is an object, keyed by asset ID ("base" for Bytes). For each asset, there is another nested object with keys stable and pending for stable and pending balances respectively. Balances are in the smallest units (bytes for the native currency), they are always integers.

If the queried address is invalid, you receive error "invalid address". If the address does not belong to your wallet, you receive error "address not found".


Use it to get the list of transactions on the wallet or on a specific address.

Example request for transactions on the entire wallet (all addresses):

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"listtransactions", "params":{"since_mci": 1234} }'

On individual address:

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"listtransactions", "params":["QZEM3UWTG5MPKYZYRMUZLNLX5AL437O3"] }'

To query the transactions on an individual address, pass it as the only element of the params array. In this case, only transactions in bytes are returned. If the passed address is invalid, you receive error "invalid address".

In all other cases, params is an object.

To get the list of transactions in a particular asset, set an asset parameter in params. If asset is null or omitted, transactions in bytes will be returned.

To query the list of transactions since a particular main chain index (MCI), specify since_mciproperty in the params object, e.g. "params": {"since_mci":254000} or "params": {"since_mci":254000; "asset": "f2TMkqij/E3qx3ALfVBA8q5ve5xAwimUm92UrEribIE="}. The full list of matching transactions will be returned, however large it is.

To query an individual transaction, specify its unit in the params object: "params": {"unit":"vlt1vzMtLCIpb8K+IrvqdpNLA9DkkNAGABJ420NvOBs="}.

The response is an array of transactions in reverse chronological order.

Each transaction is described by an object with the following fields:

  • action: string, one of invalid, received, sent, moved.

  • amount: integer, amount of the transaction in the smallest units

  • my_address: string, the address that belongs to your wallet and received funds (for receivedand moved only)

  • arrPayerAddresses: array of payer addresses (for received only)

  • confirmations: integer 0 (pending) or 1 (final), shows confirmation status of the transaction

  • unit: string, unit of the transaction (also known as transaction id)

  • fee: integer, fee in bytes

  • time: integer, seconds since the Epoch

  • level: integer, level of the unit in the DAG

  • mci: integer, MCI of the unit. It can change while the unit is still pending and becomes immutable after the unit gets final

Waiting for deposits

To operate an exchange, you'll want to wait for new deposits using the following scenario:

  • call getinfo and remember last_stable_mci, you'll use it in the following (not this one) iteration;

  • call listtransactions with since_mci set to last_stable_mci remembered from the previous (not this one!) iteration;

  • look for transactions with actions received and moved (you need moved in case one user withdraws to a deposit address of another user) and identify the user by my_address;

  • wait;

  • repeat the cycle.

In each cycle, save last_stable_mci in persistent storage and start from it after the wallet is restarted.

If you support several Obyte-issued assets, you'll need to call listtransactions for each asset individually.


Use this command to withdraw bytes or another asset. Example usage:

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"sendtoaddress", "params":["BVVJ2K7ENPZZ3VYZFWQWK7ISPCATFIW3", 1000] }'

There are 3 parameters to this command:

  • destination address (32-character string);

  • amount in bytes or smallest indivisible units (integer);

  • (optional) asset (44-character string or null). If missing or null, the asset is assumed to be bytes.

On success, the response is the unit of the spending transaction (string). If the command failed, an error message is returned. It is possible that the command returns error due to lack of confirmed funds, in this case you should retry the command in a few minutes. If the request timed out without returning an error, do not retry automatically, the funds might be already sent!

If the destination address is invalid, the command returns error "invalid address". To avoid this, it is recommended to validate user-entered withdrawal address using validateaddress above or C++ function or ocore library module in NodeJs:

var validationUtils = require("ocore/validation_utils.js");
if (!validationUtils.isValidAddress(address)){
// notify user that the entered wallet address is invalid