Skip to main content
Version: 2.0.0

Casper-Client Commands

State Root Hash

casper-client get-state-root-hash --node-address [NODE_SERVER_ADDRESS]

Example:

casper-client get-state-root-hash --node-address http://[IP]:7777

You can find a list of Testnet IP addresses at CSPR live.

The first command to cover is the get-state-root-hash command from the casper-client tool. The state root hash is an identifier of the current network state. It is similar to a Git commit ID for commit history. It gives a snapshot of the blockchain state at a moment in time. For this tutorial, it will be used to query the network state after sending deploys.

note

After sending deploys to the network, you must get the new state root hash to see the changes reflected. Otherwise, you will be looking at events in the past.

Querying Network State

casper-client query-global-state \
--node-address [NODE_SERVER_ADDRESS] \
--state-root-hash [STATE_ROOT_HASH] \
--key [ACCOUNT_HASH] \
-q "[SESSION_NAME]/[SESSION_NAMED_KEY]" (OPTIONAL)

This command allows you to query the state of a Casper network at a given moment in time, which is specified by the state-root-hash described above.

  • The node-address is the server on the network.
  • The key is the identifier for the query. It must be either the account public key, account hash, contract address hash, transfer hash, or deploy hash. The tutorial demonstrates two of these key types.
  • The optional query path argument (q) allows you to drill into the specifics of a query concerning the key.

Put Deploys (onto the Chain)

Deploy via a compiled Wasm binary

casper-client put-deploy \
--node-address [NODE_SERVER_ADDRESS] \
--chain-name casper-test \
--secret-key [KEY_PATH]/secret_key.pem \
--payment-amount [PAYMENT_AMOUNT_IN_MOTES] \
--session-path [CONTRACT_PATH]/counter-v1.wasm

This command creates a deploy and sends it to the network for execution. In this first usage of the command,

  • The session-path points to a compiled Wasm contract.
  • This contract is then installed on the network specified by the chain-name. The Testnet is "casper-test" but this is configurable.
  • The payment-amount is in units of motes (1 nano-CSPR) and is required to pay the transaction fee for the deploy. If it is too small, the transaction will get denied due to insufficient funds.

Deploy via a named key already on the blockchain

casper-client put-deploy \
--node-address [NODE_SERVER_ADDRESS] \
--chain-name casper-test \
--secret-key [KEY_PATH]/secret_key.pem \
--payment-amount [PAYMENT_AMOUNT_IN_MOTES] \
--session-name "counter" \
--session-entry-point "counter_inc"

This second usage of put-deploy does not place a new contract on the chain, but it allows you to call entry points (functions) defined in smart contracts.

This examples uses "counter" and "counter_inc" from the tutorial walkthrough. However, these will be different when you write your contracts.

Get Deploys (from the Chain)

casper-client get-deploy \
--node-address [NODE_SERVER_ADDRESS] \
[DEPLOY_HASH]

The get-deploy command is complementary to the put-deploy command. It retrieves a deploy from the network and allows you to check the status of the deploy. The DEPLOY_HASH is the identifier to a specific deploy and is returned by the put-deploy command.