Bitcoin-cli allows you to do everything you probably already know about Bitcoin and the Blockchain world. Explore transactions, create wallets, send and receive BTC through a transaction, among other functionalities.
Wallets and transactions with bitcoin-cli
A good first step to play with bitcoin-cli is to create a wallet and manage to receive or send value with it. Let's go step by step and learn more about how to use the bitcoin-cli.
Step 1: creating the wallet
To create your first wallet just run the command bitcoin-cli createwallet "". Note that the command may fail if you already have a wallet created on your computer.
To verify the existence of the wallet, use the command ls /.bitcoin/data/testnet3/wallets/.
Remember that Bitcoin stores all kinds of serialized information in .dat files.
Step 2: create new address
After creating the wallet, you need to create an address inside the wallet in order to receive or send funds. The simple command bitcoin-cli getnewaddress -addresstype legacy will allow you to perform this action and you will see the address created in the console.
Step 3: Obtaining funds
If you already have your address, you will need a Bitcoin faucet to obtain test BTC. For that, it is necessary that your node is running on the tesnet. If you decided to run it on the mainnet, you will have to use real BTC.
There are several Bitcoin faucets you can use to get some BTC, you can explore some of them:
Note: some faucets are not stable and stop working over time or you have momentary problems. Try repeatedly until you find one that can give you some BTC to continue your testing.
Once you have located a faucet, copy the address obtained in the previous step, enter it and in a matter of minutes you will get some Satoshis.
Check your wallet balance with the bitcoin-cli getbalance command.
Step 4: Transaction confirmation
You can also confirm your transaction by checking how many blocks above the block containing your transaction. Many companies expect, for example, 5 or 10 blocks to be sure that their transactions have been successfully confirmed.
To do this, use the command bitcoin-cli getbalance "*" N, where N is the number of blocks you want to check to confirm your transaction.
Step 5: List of transactions
View all transactions related to your wallet with the bitcoin-cli listtransactions command. You will see all the information associated with each transaction.
To inspect a particular transaction, copy the txid and use the bitcoin-cli gettransaction <txid> command.
Get even more information about a transaction with the bitcoin-cli gettransaction <txid> false true command such as the input and output scripts.
Step 6: Send BTC
Having your wallet ready, an address and after you have requested test funds, you can create a transaction to send BTC to another address.
The command bitcoin-cli sendtoaddress <address> 0.0001 will allow you to send value to another wallet. Just make sure you have sufficient funds and enter the destination address correctly.
This command will return the txid of the transaction which you can inspect as you have done in the previous step.
Conclusion
You have seen how easy it is to use bitcoin-cli to create a wallet, addresses, obtain and send bitcoins through a text interface.
Remember that these commands work through RPC over HTTP, so they are the basis for building any web or mobile application such as a bitcoin browser, wallet or other type of app for exchanging value between users.
Want to see more contributions, questions and answers from the community?