-
Notifications
You must be signed in to change notification settings - Fork 12
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/)
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
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.
cardano-cli wallet create TheWallet
This returns a 24 word mnemonic.
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
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>
Input selection determines the fees for the transaction:
cardano-cli transaction input-select <TX ID> TestWallet
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
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