Node API Reference

Usage

The JSON-RPC API can be consumed through different transports: TCP, HTTP and Websockets. The node operator can enable or disable the JSON-RPC service, as well as specify a different network address for each transport in the node's configuration file. By default, the tcp port is set to be 21338, http to 21339 and the ws to 21340.

Sensitive methods

Sensitive methods are those that either use the node's master key or provide information that may compromise the node's public key or address, or even the node's private key itself.

Sensitive methods allow node operators to easily manage their own nodes from a command line interface within the same host or private network. By default, sensitive methods are enabled.

When exposing any of the JSON-RPC ports (tcp/21388, http/21339, ws/21340) to a public IP, ensure to disable sensitive methods first by setting enable_sensitive_methods = false in your node's witnet.toml configuration file.

Public methods

Public methods provide information that do not compromise node's private information, like its private or public key, or address:


addPeers

Add one or more peer addresses to the list of available ones.

Parameters

  • Vec<SocketAddr>

Returns

  • true

Example

{
    "jsonrpc":"2.0",
    "id":1,
    "method":"addPeers",
    "params": [
        "5.9.5.85:22339", 
        "45.130.104.29:21336"
    ] 
}

authorizeStake

Create a stake authorization for the given address.

Parameters

Returns

Example

{
  "jsonrpc":"2.0",
  "method":"authorizeStake",
  "params":{
    "withdrawer":"twit13u2luhdlfzu700augc9mm9sa0xhng6jc34r5vy"
  },
  "id":"1"
}

clearPeers

Clear all peers from the list of available ones.

Parameters

  • None.

Returns

  • true

Example

{"jsonrpc":"2.0","id":1,"method":"clearPeers"}

createVRF

Create a VRF proof for the provided message with the stored key.

Parameters

  • Vec<u8>

Returns

  • Vec<u8>

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method": "createVRF",
  "params": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
}

dataRequestReport

Show information about a data request.

Parameters

  • drTxHash: Data request transaction hash.

Returns

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"dataRequestReport",
  "params":["de93bfab2acf2cd4d9f63b80030370e399de975efcb695e298b64b3345ef5a9e"]
}

getBalance

Get the balance of a the pkh.

Parameters

  • pkh: The public key hash to get the balance from.

  • simple?: Distinguish between fetching a simple balance or fetching confirmed and unconfirmed balance. Defaults to `false`.

Returns

Example

{
    "jsonrpc":"2.0",
    "id":1,
    "method":"getBalance",
    "params":["wit1vcpsy5cmfaz2jgt5h3getdkqh38cs5edkxmnla"]
}

getBlock

Get detailed information about a block being queried by its hash.

Parameters

  • blockHash: The hash of the block must be provided as a hexadecimal string.

  • metadata: (Optional) If set to true, transactions metadata will be provided.

Returns

Example

{
    "jsonrpc":"2.0",
    "id":1,
    "method":"getBlock",
    "params":[
        "0fc5be1043da24fb0a6e6420d9df286fdc22fada5b371dbb547dad4e08e83212", 
        true
    ]
}

getBlockChain

Get the list of all the known block hashes.

Parameters

  • epoch: (Optional) First epoch for which to return block hashes. If the provided value is negative, it returns block hashes from the last n epochs. Default to 0.

  • limit: (Optional) Number of block hashes to return. If the provided value is negative, return the last n block hashes from this epoch range. If the value is zero, it's unlimited. Default to 0.

Returns

  • Vec<u32, Hash>: An array of epochs and block hashes.

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getBlockChain",
  "params": { "limit": 1, "epoch": 1 }
}

getConsensusConstants

Get consensus constants used by the node.

Parameters

  • None

Returns

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getConsensusConstants",
  "params":null
}

getMempool

Get all the pending transactions.

Parameters

  • None

Returns

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getMempool",
  "params":null
}

getPublicKey

Get the public key of the node.

Parameters

  • None

Returns

  • [u8; 33]

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getPublicKey",
  "params":[]
}

getPkh

Get public address of the node.

Parameters

  • None

Returns

  • String

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getPkh",
  "params":[]
}

getReputation

Displays the reputation score associated with a given public address and its eligibility to mine a block.

Parameters

  • pkh: The Witnet public address.

Returns

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getReputation",
  "params": ["wit1nwhl5clpeste6gsexmd706c5jv64kc8fd5q94s"] 
}

getReputationAll

Get all the nodes active and their elegibility. It also lists the nodes with reputation grater than 0 but not active, if any.

Note that it is perfectly normal for a node to show 0 reputation for the first days of it being up. Please be patient, new identities in the system are subject to a slow start for critical security reasons.

Parameters

  • None.

Returns

Example

{"jsonrpc":"2.0","id":1,"method":"getReputationAll" }

getSuperblock

Get the blocks that pertain to the superblock specified.

Parameters

Map including one only of these:

  • block_epoch: Superblock epoch.

  • superblock_index: Superblock index.

Returns

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getSuperblock",
  "params": { 
    "block_epoch": 1800000 
  } 
}

getSupplyInfo

Get supply information.

Parameters

  • None

Returns

Example

{"jsonrpc":"2.0","id":1,"method":"getSupplyInfo","params": [] }

getTransaction

Get detailed information about a transaction being queried by its hash.

Parameters

  • txHash: It should be provided as a hexadecimal string.

Returns

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getTransaction",
  "params": ["0afd47114900d4ab866a80203f54900b9fee6bdcd0a44f0be8cad3587c7a445a"] 
}

getUtxoInfo

Get unspent transaction outputs belonging to given public address.

Parameters

  • pkh: Public address.

Returns

Example

{
  "jsonrpc":"2.0",
  "id":1,
  "method":"getUtxoInfo",
  "params": ["wit1234567890abcdefghijklmnopqrstuvwxyz123"] 
}

knownPeers

Get the list of peer addresses known to the node.

Parameters

  • None

Returns

A list with the address of the peer and the type which can be new or tried.

Example

{"jsonrpc":"2.0","id":1,"method":"knownPeers","params": [] }

initializePeers

Initialize all known peers present in witnet.toml#connections.

Parameters

  • None

Returns

  • true

Example

 {"jsonrpc":"2.0","id":1,"method":"initializePeers"}

inventory

Make the node process, validate and potentially broadcast a new inventory entry.

Parameters

Returns

  • true if no errors.

Example

 {
   "jsonrpc":"2.0",
   "id":1,
   "method": "inventory", 
   "params": {
     "transaction": {
       "ValueTransfer": {
         "body": {
           "inputs": [
             {
               "output_pointer": "0000000000000000000000000000000000000000000000000000000000000000:0"
             }
           ], 
           "outputs": [
             {
               "pkh": "wit100000000000000000000000000000000123456", 
               time_lock: 0, 
               value: 1
             }
           ]
         }, 
         "signatures": [
           {