PPP Week03 Transfer funds without running a cardano-node

In this article, I will be sharing my way of generating addresses on the testnet and transferring funds between them without running a cardano-node. I made this article so that people with low specs can interact with the testnet. The article is roughly divided into three sections: Installation, Setup, and Transfer. These commands are run on a Ubuntu 20.04.1 LTS VM.

Installation

Install cardano-cli

Get the cardano-node build from iohk from here. You can choose another build too. Extract the files

tar -xvzf cardano-node-1.33.0-linux.tar.gz

and then add them to your PATH. For ubuntu simply copying the contents to a directory called bin in your ~ dir should be enough (don't forget to reset your terminal).

Install bcc

bcc or blockfrost-cardano-cli is blockfrost's cardano-cli with a few commands implemented. This is will allow us to submit transactions to the testnet without running a node. Create an account here then install the cli using the command below.

npm install -g @blockfrost/blockfrost-cardano-cli

now either set the BLOCKFROST_PROJECT_ID_TESTNET variable for the current shell or add it to your .bash_profile. I recommend adding it to your shell using the command below

export BLOCKFROST_PROJECT_ID_TESTNET=<your-key-here>

Get your key from the blockfrost [dashboard] (https://blockfrost.io/dashboard?callbackUrl=%2Fdashboard).

Setup

Create addresses

The following commands will generate 2 keys and then generate their addresses for the testnet.

Generate Keys

cardano-cli address key-gen \
    --verification-key-file 01.vkey \
    --signing-key-file 01.skey
cardano-cli address key-gen \
    --verification-key-file 02.vkey \
    --signing-key-file 02.skey

Generate addresses

cardano-cli address build \
    --payment-verification-key-file 01.vkey \
    --testnet-magic 1097911063 \
    --out-file 01.addr
cardano-cli address build \
    --payment-verification-key-file 02.vkey \
    --testnet-magic 1097911063 \
    --out-file 02.addr

Get funds from the faucet

Do a cat 01.addr on the terminal and use the address to get funds from the faucet.

Query from testnet

To check whether you received the funds from the faucet or not run the following command. Optionally run bcc query protocol-parameters -t --out-file protocol.json. It will get the protocol parameters to calculate the min-fees. You can approximate the fees to 200000 if you don't care.

bcc query utxo --address $(cat 01.addr) -t

 TxHash                                                           TxIx   Amount              
 ──────────────────────────────────────────────────────────────── ────── ─────────────────── 
 c3850544d66a0eef38326551c35807975c201f25787e8e9a379a306ee6f9c1f3 1      199200000 lovelace  
 ac2214ad459b6d5921992b9563ba4da6505e88fb7a12f75103c5ba68d43eb4fe 0      1000000000 lovelace 
 1c05c7beee527db726aa534e1b3ec9f316211676f81c833a74982d18a6abac37 1      689400000 lovelace  

Select a utxo from this table and use the TxHash and TxIx in the --tx-in line in the next command.

Transfer

Draft transaction

This command below assumes that you are using the utxo from the faucet. If not, please change the amounts at the end of the --tx-out lines.

cardano-cli transaction build-raw \
    --alonzo-era \
    --tx-in <TxHash>#<TxIx> \
    --tx-out $(cat 02.addr)+10000000 \
    --tx-out $(cat 01.addr)+989800000 \
    --invalid-hereafter 0 \
    --fee 200000 \
    --out-file tx.body

Calculate fees (optional)

cardano-cli transaction calculate-min-fee \
    --tx-body-file tx.body \
    --tx-in-count 1 \
    --tx-out-count 2 \
    --witness-count 1 \
    --byron-witness-count 0 \
    --testnet-magic 1097911063 \
    --protocol-params-file protocol.json

Add fees to command

Add the fees here

--fee <your-fees> \

Calculate the change using expr <UTXO BALANCE> - <AMOUNT TO SEND> - <TRANSACTION FEE> and replace the amount at this line

--tx-out $(cat 01.addr)+<here> \

in the draft transaction section.

Submit transaction

Before submitting the transaction, you will need to sign it first using cardano-cli and then submit it using bcc.

Sign the transaction

cardano-cli transaction sign \
    --tx-body-file tx.body \
    --signing-key-file 01.skey \
    --testnet-magic 1097911063 \
    --out-file tx.signed

Submit the transaction

bcc transaction submit -f tx.signed -t

If everything worked out well, you will be able to check your funds in the second address using

bcc query utxo --address $(cat 02.addr) -t

Thanks to:

  • @srk in #blockfrost in IOG's Technical Community on discord

References:

I am planning to write another blog post for creating a contract on the testnet after [my question on CSE is resolved] (https://cardano.stackexchange.com/questions/6934/ppviewhashesdontmatch-and-unspendableutxonodatumhash-error-on-redeeming-funds-fr). There appears to be some problem with bcc. Sorki (aka @srk) knows more about this.