Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

Working with cardano cli

ryan lemmer edited this page Jan 16, 2019 · 1 revision

Working with cardano-cli

To use this command line, you'll need to install Rust lang. Then install cardano-cli:

git clone https://github.com/input-output-hk/cardano-cli.git --recursive

cd cardano-cli
cargo install

(There are cardano-cli tutorials here: https://cardanorust.iohkdev.io/cli-wallet/)

Setup up a local blockchain

You can use any of staging/mainnet/testnet as --template, e.g. to pull a local copy of the staging network:

cardano-cli blockchain new staging --template=staging

cardano-cli blockchain pull staging

There is also a fast fetch, but this is still experimental code, try with caution:

cardano-cli blockchain remote-fetch staging hermes # to kill when 1s remains

You can check the status of the blockchain with

cardano-cli blockchain status staging

Recover a Daedelus "Random Index" wallet

Daedelus V0 wallets use an address derivation scheme with randomly generated account and address indices - there wallets are created with 12-word mnemonics.

In contrast, the ICARUS key derivation scheme uses sequential indices and 15 or 24-word mnemonics. Yoroi and the underlying cardano-cli use the ICARUS derivation scheme.

However, we can still use cardano-cli to recover a Daedelus "random" wallet:

cardano-cli wallet recover --daedalus-seed --derivation-scheme=v1 --mnemonics-length=12 --wallet-scheme=random_index_2levels TestWallet

Note the 12 word mnemonic and random_index_2levels for Daedelus wallets. We need to name the new wallet (TestWallet in this case).

You will need to enter the wallet's 12-word mnemonic along with a spending password.

Create new "Sequential" Wallet

cardano-cli wallet create TheWallet

This returns a 24 word mnemonic.

Working with Wallets

Next we attach the new wallet to our staging blockchain and catch the wallet up with the chain using sync:

cardano-cli wallet attach TestWallet staging

cardano-cli wallet sync TestWallet

You can check the status (including balance) of the wallet with

cardano-cli wallet status TestWallet

We can now also see a statement of all transactions for this wallet:

cardano-cli wallet statement TestWallet

and to see the wallet utxo:

cardano-cli wallet utxos TestWallet

Working with Transactions

Create an unsigned transaction

To create and submit a new transaction, let's assume we have

  • a wallet with some utxo
  • an address (string) we want to transfer funds to <TARGET_ADDR>
  • a change address (string) to receive change for the transaction <CHANGE_ADDR>
cardano-cli transaction new mainnet

# returns tx id e.g. "5QuBND"

Add a recipient address and coin amount (e.g. 42 Lovelaces) for the Tx:

cardano-cli transaction add-output <TX ID> <TARGET_ADDR> 42

Add a change address:

cardano-cli transaction add-change <TX ID> <CHANGE_ADDR>

Transaction input selection

Input selection determines the fees for the transaction:

cardano-cli transaction input-select <TX ID> TestWallet

Review Transaction

cardano-cli transaction status <TX ID>

e.g.

input-total: 9982.485077
output-total: 9982.314095
actual fee: 0.170982
fee: 0.170982
tx-bytes: 355
inputs:
  <INPUT TX ID>.1
outputs:
  <OUT ADDR> 0.004422
  <CHANGE ADDR> 9982.309673

Signing a Transaction

First we need to finalise the transaction:

cardano-cli transaction finalize <TX ID>

Then sign:

cardano-cli transaction sign <TX ID>

and submit the transaction to the blockchain

cardano-cli transaction send <TX ID> staging

Once the transaction is confirmed, we can use poll for it in our local blockchain and wallet:

cardano-cli blockchain pull staging     # update local blockchain copy
cardano-cli wallet sync TestWallet
cardano-cli wallet status TestWallet