The cli subcommand provides a human-friendly command-line interface to the node JSON-RPC API.
Usage
See all the available options by running the help command using docker, binary or cargo.
docker exec witnet_node witnet node --help
witnet node --help
cargo run -- node --help
To get more information about any specific command, simply add --help at the end. For instance, this will show the available options for the blockchain command:
The JSON-RPC server address is obtained from the configuration file. The path of this file can be set using the -c or --config flag. This flag must appear before node.
The executable implements the usual logging API, which can be enabled using RUST_LOG=witnet=debug:
$ docker exec witnet_node witnet node blockchain
INFO 2019-01-03T12:04:43Z: witnet::json_rpc_client: Connecting to JSON-RPC server at 127.0.0.1:21338
ERROR 2019-01-03T12:04:43Z: witnet: Error: Connection refused (os error 111)
$ RUST_LOG=witnet=debug witnet node blockchain
INFO 2019-01-03T12:04:43Z: witnet::json_rpc_client: Connecting to JSON-RPC server at 127.0.0.1:21338
ERROR 2019-01-03T12:04:43Z: witnet: Error: Connection refused (os error 111)
$ RUST_LOG=witnet=debug cargo run -- node blockchain
INFO 2019-01-03T12:04:43Z: witnet::json_rpc_client: Connecting to JSON-RPC server at 127.0.0.1:21338
ERROR 2019-01-03T12:04:43Z: witnet: Error: Connection refused (os error 111)
Commands
addPeers
Add addresses to the node's peers and try to connect to them.
The IP addresses are expected in format: list of "address:port" separated by spaces.
List block hashes in the local block chain, matched with their epochs.
docker exec witnet_node witnet node blockchain
witnet node blockchain
cargo --run node blockchain
This method accepts two optional arguments:
--epoch=n: the first epoch for which to show block hashes. A negative epoch means "n epochs ago".
--limit=n: the number of epochs. If zero, unlimited.
# Get all the block hashes from the genesis block
docker exec witnet_node witnet node blockchain --epoch=0 --limit=0
# Get the block hashes from epochs [0, 19]
docker exec witnet_node witnet node blockchain --epoch=0 --limit=20
# Get the block hashes from the last 10 epochs
docker exec witnet_node witnet node blockchain --epoch=-10 --limit=0
# Get the block hash from 10 epochs ago
docker exec witnet_node witnet node blockchain --epoch=-10 --limit=1
# Get the block hash from the last block
docker exec witnet_node witnet node blockchain --epoch=-1 --limit=1
# Get all the block hashes from the genesis block
witnet node blockchain --epoch=0 --limit=0
# Get the block hashes from epochs [0, 19]
witnet node blockchain --epoch=0 --limit=20
# Get the block hashes from the last 10 epochs
witnet node blockchain --epoch=-10 --limit=0
# Get the block hash from 10 epochs ago
witnet node blockchain --epoch=-10 --limit=1
# Get the block hash from the last block
witnet node blockchain --epoch=-1 --limit=1
# Get all the block hashes from the genesis block
cargo run -- node blockchain --epoch=0 --limit=0
# Get the block hashes from epochs [0, 19]
cargo run -- node blockchain --epoch=0 --limit=20
# Get the block hashes from the last 10 epochs
cargo run -- node blockchain --epoch=-10 --limit=0
# Get the block hash from 10 epochs ago
cargo run -- node blockchain --epoch=-10 --limit=1
# Get the block hash from the last block
cargo run -- node blockchain --epoch=-1 --limit=1
Example output:
block for epoch #76229 had digest 8dd75bb0d5475a93c27c4166677fbb3bc154e6731c7e07ecad549a58851c84a4
Display the list of block hashes for each epoch, their miners and the numbers of blocks mined by each address.
docker exec witnet_node ./witnet node minerList
witnet node minerList
cargo run -- node minerList
nodeStats
Display local node stats.
docker exec witnet_node witnet node nodeStats
witnet node nodeStats
cargo run -- node nodeStats
Among other information, this shows counters for proposed and accepted blocks and participations in resolving data requests ("commitments"):
Block mining stats
Proposed blocks
Blocks included in the block chain
Data Request mining stats:
Times with eligibility to mine a data request
Proposed commits
Accepted commits
Slashed commits
Example output:
Block mining stats:
- Proposed blocks: 81
- Blocks included in the block chain: 1
Data Request mining stats:
- Times with eligibility to mine a data request: 2
- Proposed commits: 0
- Accepted commits: 0
- Slashed commits: 0
!!! tip Note that it is perfectly normal for a node to show 0 "blocks included" or "accepted commits" 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.
output
Display a transaction output, as referred by it's "output pointer", that is, <transaction_id>:<output_index>.
cargo run -- node output 33c656101dd1dfa2258415d6487c648152b95983d1151f46a679b5d1902f6a8d
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.
docker exec witnet_node witnet node peers
witnet node peers
cargo run -- node peers
priority
Display priority and time-to-block estimations for different priority tiers according to the current state of the network. The priority is measured in nanowits per weight unit, so you can calculate a fee by multiplying the priority by the weight of the transaction.
The raw command allows sending raw JSON-RPC requests from the command line. It can be used in an interactive way (don't forget the -i flag when using Docker): each line of user input will be sent to the JSON-RPC server without any modifications:
$ docker exec -i witnet_node witnet node raw
$ witnet -c witnet.toml node raw
$ cargo run -- -c witnet.toml node raw
Each block represents a method call: the first line is a request, the second line is a response.
hi
{"jsonrpc": "2.0","error": {"code":-32700,"message": "Parse error"},"id":null}
Alternatively, the input can be read from a file using pipes, as is usual in Unix-like environments. For instance, the bitcoin_price.json data request example from the witnet-rust reposity can be easily deployed into the network using the raw command like this:
The parameter [A] notifies that the node is active.
Adding the flag --all lists all the nodes active and their elegibility. It also lists the nodes with reputation grater than 0 but not active, if any.
!!! tip 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.
Create and broadcast a value transfer transaction. That is, send some amount of wit tokens from the node's own balance into a different Witnet address.
--address=address: recipient address.
--value=amount: amount in nanoWits.
--fee=fee: miner fee in nanoWits.
--time-lock=timestamp: optional time lock for the created output: the receiver will not be able to spend the output until the timestamp is reached. 0 means no time-lock.
docker exec witnet_node witnet node send --address=twit1ulyzvnknjnndkfva636erkkp83wxhhwdfhptsr --value=9999999999999999999 --fee=1
{"jsonrpc": "2.0","error": {"code":-32603,"message": "Cannot build a transaction transferring more value than the current available balance: 9999999999999999999 + 1 > 39649999949502"},"id": "1"}
witnet node send --address=twit1ulyzvnknjnndkfva636erkkp83wxhhwdfhptsr --value=9999999999999999999 --fee=1
{"jsonrpc": "2.0","error": {"code":-32603,"message": "Cannot build a transaction transferring more value than the current available balance: 9999999999999999999 + 1 > 39649999949502"},"id": "1"}
cargo run -- node send --address=twit1ulyzvnknjnndkfva636erkkp83wxhhwdfhptsr --value=9999999999999999999 --fee=1
{"jsonrpc": "2.0","error": {"code":-32603,"message": "Cannot build a transaction transferring more value than the current available balance: 9999999999999999999 + 1 > 39649999949502"},"id": "1"}
Get the unspent transaction outputs of the node. This shows how many UTXOs are available for your node to spend or collateralize.
docker exec witnet_node witnet node utxos
witnet node utxos
cargo run -- node utxos
The output includes information about:
Total number of utxos
Total number of utxos bigger than collateral minimum
Total number of utxos older than collateral coinage
The flag --long can be added to the command to get a detailed list of the UTXOs and whether each of them is spendable or collateralizable at this time.