Skip to content

Wit/Node JSON-RPC API ​

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.

DANGER

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 ​

json
{
    "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 ​

json
{
  "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 ​

json
{"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 ​

json
{
  "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 ​

json
{
  "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 ​

json
{
    "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 ​

json
{
    "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 ​

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

getConsensusConstants ​

Get consensus constants used by the node.

Parameters ​

  • None

Returns ​

Example ​

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

getMempool ​

Get all the pending transactions.

Parameters ​

  • None

Returns ​

Example ​

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

getPublicKey ​

Get the public key of the node.

Parameters ​

  • None

Returns ​

  • [u8; 33]

Example ​

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

getPkh ​

Get public address of the node.

Parameters ​

  • None

Returns ​

  • String

Example ​

json
{
  "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 ​

json
{
  "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.

INFO

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 ​

json
{"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 ​

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

getSupplyInfo ​

Get supply information.

Parameters ​

  • None

Returns ​

Example ​

json
{"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 ​

json
{
  "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 ​

json
{
  "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 ​

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

initializePeers ​

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

Parameters ​

  • None

Returns ​

  • true

Example ​

json
 {"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 ​

json
 {
   "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": [
           {
             "public_key": {
               "bytes": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], 
               "compressed": 2
             }, 
             "signature": {
               "Secp256k1": {
                 "der": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69]
               }
             }
           }
         ]
       }
     }
   }
 }

nodeStats ​

Get stats info from node.

Parameters ​

  • None

Returns ​

Example ​

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

masterKeyExport ​

Export the private key associated with the node identity in XPRV format.

Parameters ​

  • None

Returns ​

  • String: Private key in XPRV format.

Example ​

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

peers ​

List inbound and outbound connections currently established by the node. Outbound connections are those initiated on our side, and inbound connections are those that were initiated by peer nodes. A node that does not announce a public address (IP and port) will normally have no inbound connections, as there is no way for other nodes to discover a valid network route to it.

Parameters ​

  • None

Returns ​

Example ​

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

priority ​

Get priority and time-to-block estimations for different priority tiers.

Parameters ​

  • None

Returns ​

PriorityEstimate: A map whose keys represent the different levels of priority for data requests transactions and value transfer transactions: stinky, low, medium, high and opulent. The value is a map which includes:

  • priority: priority value in nanowits per weight unit.
  • time_to_block: average for your transaction to be included in a block in seconds.

Example ​

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

protocol ​

Get information about protocol versions and which version is currently being enforced.

Parameters ​

  • None

Returns ​

Example ​

json
{
  "jsonrpc":"2.0",
  "method":"protocol",
  "id":"1"
}

queryStakes ​

Query amount of nanowits staked by an address or get all stake entries in the network.

Parameters

Returns

Example

json
{
  "jsonrpc":"2.0",
  "method":"queryStakes",
  "params":{
    "all":true
  },
  "id":1
}

rewind ​

Delete the chain state until the specified epoch and resync from there.

Parameters ​

  • Epoch: u32

Returns ​

  • true

Example ​

json
{"jsonrpc":"2.0","id":1,"method":"rewind","params": [1000000]}

sendRequest ​

Create and broadcast a data request transaction to the Witnet Network.

Parameters ​

Returns ​

Example ​

json
{
  "jsonrpc":"2.0",
  "method":"sendRequest",
  "params":{
    "dro":{
      "data_request":{
        "time_lock":0,
        "retrieve":[
          {
            "kind":"HTTP-GET",
            "url":"https://api.binance.US/api/v3/ticker?symbol=ETHUSD",
            "script":[
              132, 24, 119,130,24,100,105,108,97,115,116,80,114,105,99,101,130,24,87,26,0,15,66,64,24,91
            ]
          },
          {
            "kind":"HTTP-GET",
            "url":"https://api.bitfinex.com/v1/pubticker/ETHUSD",
            "script":[
              132,24,119,130,24,100,106,108,97,115,116,95,112,114,105,99,101,130,24,87,26,0,15,66,64,24,91
            ]
          },
          {
            "kind":"HTTP-GET",
            "url":"https://www.bitstamp.net/api/v2/ticker/ethusd",
            "script":[
              132,24,119,130,24,100,100,108,97,115,116,130,24,87,26,0,15,66,64,24,91
            ]
          },
          {
            "kind":"HTTP-GET",
            "url":"https://api.bittrex.com/v3/markets/ETH-USD/ticker",
            "script":[
              132,24,119,130,24,100,109,108,97,115,116,84,114,97,100,101,82,97,116,101,130,24,87,26,0,15,66,64,24,91
            ]
          },
          {
            "kind":"HTTP-GET",
            "url":"https://api.coinbase.com/v2/exchange-rates?currency=ETH",
            "script":[
              134,24,119,130,24,102,100,100,97,116,97,130,24,102,101,114,97,116,101,115,130,24,100,99,85,83,68,130,24,87,26,0,15,66,64,24,91
            ]
          },
          {
            "kind":"HTTP-GET",
            "url":"https://api.kraken.com/0/public/Ticker?pair=ETHUSD",
            "script":[
             135,24,119,130,24,102,102,114,101,115,117,108,116,130,24,102,104,88,69,84,72,90,85,83,68,130,24,97,97,97,130,22,0,130,24,87,26,0,15,66,64,24,91
            ]
          }
        ],
        "aggregate":{
          "filters":[
            {
              "op":5,
              "args":[
                250,63,192,0,0
              ]
            }
          ],
          "reducer":3
        },
        "tally":{
          "filters":[
            {
              "op":5,
              "args":[250,64,32,0,0]
            }
          ],
          "reducer":3
        }
      },
      "witness_reward":150000000,
      "witnesses":10,
      "commit_and_reveal_fee":10000000,
      "min_consensus_percentage":51,
      "collateral":15000000000
    },
    "fee":{
      "absolute":3588
    },
    "dry_run":false
  },
  "id":"12"
}

sendValue ​

Create and broadcast a value transfer transaction. That is, send some amount of wit coins from the node's own balance into a different Witnet address.

Parameters ​

BuildVtt

Returns ​

VTTTransaction

Example ​

json
{
  "jsonrpc":"2.0",
  "id":1,
  "method":"sendValue",
  "params":{
    "dry_run":true,
    "fee":10,
    "utxo_strategy":{
      "random":{
        "from":null
      }
    },
    "vto":[
      {
        "pkh": "wit1234567890abcdefghijklmnopqrstuvwxyz123",
        "time_lock": 0,
        "value": 10
      }
    ]
  }
}

sign ​

Sign a piece of data with the node's master key.

Parameters ​

  • [u8; 32]

Returns ​

Example ​

json
{
  "jsonrpc":"2.0",
  "id":1,
  "method":"sign",
  "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]
}

signalingInfo ​

Get consolidated and on-going upgrades of the Witnet network.

Parameters ​

  • None

Returns ​

Example ​

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

stake ​

Create and broadcast a stake transaction to the Witnet Network.

Parameters

Returns

Example

json
{
  "jsonrpc":"2.0",
  "method":"stake",
  "params":{
    "authorization":"009264becc376ba03741c99caa57b4b391dfb793eff5f62e64800de8164925f74209b9f92429037c206a37cbf826702ec21ee805027ff201fea22e4728d8b79293",
    "value":10000000000000,
    "withdrawer":"twit13u2luhdlfzu700augc9mm9sa0xhng6jc34r5vy",
    "fee":{
      "absolute":1
    },
    "utxo_strategy":"random",
    "dry_run":false
  },
  "id":"2"
}

syncStatus ​

Get node synchronization status.

Parameters ​

  • None

Returns ​

SyncStatus: Map with the chain beacon, the current epoch and the state of the node. Values of node state are:

  • WaitingConsensus: waiting for reaching consensus between its peers
  • Synchronizing: synchronization process.
  • AlmostSynced: it has all the blocks in the chain and is ready to start consolidating block candidates in real time.
  • Synced: can consolidate block candidates, propose its own candidates (mining) and participate in resolving data requests (witnessing).

Example ​

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

tryRequest ​

Ask your node to resolve data request locally, without actually broadcasting it to the Witnet network.

Parameters ​

  • DataRequestOutput: unsigned data request struct with retrievals' script and filters' argsfields encoded as CBOR values serialized as Vec<u8> arrays.

Returns ​

  • Data request result stringified as a RadonTypes value.

Example ​

json
{
  "jsonrpc": "2.0", 
  "id": 1, 
  "method": "tryRequest", 
  "params": { 
    "data_request": { 
      "time_lock": 1, 
      "retrieve": [ 
        { 
          "url": "https://www.bitstamp.net/api/v2/ticker/ethusd/", 
          "contentType": "JSON API", 
          "kind": "HTTP-GET", 
          "headers": [], 
          "script": [ 132, 24, 119, 130, 24, 100, 100, 108, 97, 115, 116, 130, 24, 87, 25, 3, 232, 24, 91 ] 
        }, 
        { 
          "url": "https://api.coincap.io/v2/assets", 
          "contentType": "JSON API", 
          "kind": "HTTP-GET", 
          "headers": [], 
          "script": [ 134, 24, 119, 130, 24, 97, 100, 100, 97, 116, 97, 130, 24, 24, 1, 130, 24, 100, 104, 112, 114, 105, 99, 101, 85, 115, 100, 130, 24, 87, 25, 3, 232, 24, 91 ]
        }, 
        { 
          "url": "https://api.coinpaprika.com/v1/tickers/eth-ethereum", 
          "contentType": "JSON API", 
          "kind": "HTTP-GET", 
          "headers": [], 
          "script": [ 134, 24, 119, 130, 24, 102, 102, 113, 117, 111, 116, 101, 115, 130, 24, 102, 99, 85, 83, 68, 130, 24, 100, 101, 112, 114, 105, 99, 101, 130, 24, 87, 25, 3, 232, 24, 91 ] 
        } 
      ], 
      "aggregate": { 
        "filters": [{ "op": 5, "args": [250, 63, 192, 0, 0] }], 
        "reducer": 3 
      }, 
      "tally": { 
        "filters": [{ "op": 5, "args": [250, 63, 192, 0, 0] }], 
        "reducer": 3 
      }
    },
    "collateral": 1,
    "min_consensus_percentage": 50, 
    "commit_and_reveal_fee": 1, 
    "witnesses": 1, 
    "witness_reward": 1
  }
}

unstake ​

Create and broadcast an unstake transaction to the Witnet Network.

Parameters ​

Returns ​

Example ​

// Not allowed yet