Get started with Cardano CLI
Setting up environment variables
CARDANO_NODE_SOCKET_PATH
Cardano CLI uses the node-to-client protocol to communicate with the node. This requires setting an environment variable for the node socket path. Ensure you use the path declared when starting the node.
export CARDANO_NODE_SOCKET_PATH=~/node.socket
CARDANO_NODE_NETWORK_ID
Each network has a unique identifier (--mainnet or --testnet-magic NATURAL). This is used by the node-to-client protocol to ensure communication with a node on the desired network. It is useful to set up an environment variable for the network ID. Alternatively, you can provide the flag --testnet-magic <network-id>
with each command that interacts with the node.
- Mainnet
export CARDANO_NODE_NETWORK_ID=mainnet
- Pre-production testnet
export CARDANO_NODE_NETWORK_ID=1
- Preview testnet
export CARDANO_NODE_NETWORK_ID=2
- SanchoNet testnet
export CARDANO_NODE_NETWORK_ID=4
Generating keys and addresses
For a complete overview of Cardano address types, read CIP-19.
Generate a payment key pair and an address
To generate a key pair, run:
cardano-cli address key-gen \
--verification-key-file payment.vkey \
--signing-key-file payment.skey
Build an address
This address will not have staking rights. It cannot delegate or receive rewards because it does not have a stake part associated with it, only a payment part (see CIP-19).
cardano-cli address build \
--payment-verification-key-file payment.vkey \
--out-file paymentNoStake.addr
cat paymentNoStake.addr
addr_test1vzdtyyt48yrn2fa3wvh939rat0gyv6ly0ljt449sw8tppzq84xstz
Testnet addresses start with 'addr_test' and mainnet addresses with 'addr'.
Generate a stake key pair
cardano-cli stake-address key-gen \
--verification-key-file stake.vkey \
--signing-key-file stake.skey
Build the address with payment and stake parts
The resulting address will be associated with the payment and stake credentials:
cardano-cli address build \
--payment-verification-key-file payment.vkey \
--stake-verification-key-file stake.vkey \
--out-file payment.addr
cat payment.addr
addr_test1qzdtyyt48yrn2fa3wvh939rat0gyv6ly0ljt449sw8tppzrcc3g0zu63cp6rnjumfcadft63x3w8ds4u28z6zlvra4fqy2sm8n
Query the balance of an address
cardano-cli query utxo --address $(< paymentNoStake.addr)
TxHash TxIx Amount
--------------------------------------------------------------------------------------
262c7891f932cde390bcc04c25805f3f422c1a5687d5d47f6681e68bb384fe6d 0 10000000000 lovelace + TxOutDatumNone
- You can get test tokens for pre-production and preview testnets using this faucet
- For SanchoNet tokens, go to the SanchoNet faucet.