Get started with Cardano CLI
Want to start experimenting right away without installing anything locally? You can use Demeter.run to access a cloud-based development environment with cardano-node, cardano-cli pre-installed and a jupyter notebook tutorial you can follow along:
Alternatively, if you prefer to set up your local environment, continue with the instructions below.
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
This guide assumes you have installed cardano-node into your system. If not you can refer to Installing cardano-node guide for instructions on how to do that.
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
This creates two files:
- payment.vkey (verification key / public key): Used to derive your wallet address. This is what you share to receive funds. The file looks like this:
{
"type": "PaymentVerificationKeyShelley_ed25519",
"description": "Payment Verification Key",
"cborHex": "582056a29cba161c2a534adae32c4359fda6f90a3f6ae6990491237b28c1caeef0c4"
}
- payment.skey (signing key / private key): Used to sign and approve transactions. Keep this file secure and never expose it publicly. The file looks like this:
{
"type": "PaymentSigningKeyShelley_ed25519",
"description": "Payment Signing Key",
"cborHex": "58208c61d557e1b8ddd82107fa506fab1b1565ec76fe96e8fb19a922d5460acd5a5b"
}
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 latest 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.