We are going to run a Bitcoin full node in a Debian system (Sid)
Download Bitcoin precompiled binaries
I download the Bitcoin Core binary suitable for my system architecture (e.g: linux amd 64 bits)
https://bitcoincore.org/en/download/
I download 64 bit version for linux:
$ wget https://bitcoincore.org/bin/bitcoin-core-0.14.2/bitcoin-0.14.2-x86_64-linux-gnu.tar.gz
Extract the tar ball:
$ tar xvzf bitcoin-0.14.2-x86_64-linux-gnu.tar.gz
Install the binaries in /usr/local/bin directory
$ sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-0.14.2/bin/*
Run Bitcoin node
By now we are going to run only Bitcoin node with no graphical interface:
I create a new user to run the Bitcoin node
$ sudo adduser bitcoin_user
Then we log in with the new user
$ sudo login bitcoin_user
And launch the Bitcoin node (in daemon mode listening to commands):
bitcoin_user@my_box:~$ bitcoind -daemon
Bitcoin server starting
you can execute
$ bitcoind -server
to accept RPC-JSON commands.If you do not want to print the log to stdout:
$ bitcoind -printtoconsole=0 ...
Disable wallet functionality:
$ bitcoind -disablewallet ...
Disable network:
$ bitcoind -noconnect ...
Show help about bitcoin server options:
$ bitcoind -help
We can list configuration files:
$ cd .bitcoin
$ ls
banlist.dat bitcoind.pid blocks chainstate database db.log debug.log peers.dat wallet.dat
Data directory
bitcoin.conf configuration file
NOTE: Right now, if we do not open the necessary ports in the router we are only using our Bitcoin node as a wallet.
Communicate with the server using Bitcoin client for command line
https://bitcoincore.org/en/doc/0.16.2/rpc/
https://bitcoin.org/en/developer-reference#rpc-quick-reference
Get general help:
$ bitcoin-cli help
Get help for a specific command:
$ bitcoin-cli help getinfo
$ bitcoin-cli getinfo
$ bitcoin-cli getblockchaininfo
$ bitcoin-cli getnetworkinfo
$ bitcoin-cli getnettotals
$ bitcoin-cli getwalletinfo
$ bitcoin-cli getconnectioncount
8
To stop the Bitcoin server:
$ bitcoin-cli stop
List my accounts:
$ bitcoin-cli listaccounts
{
"": 0.00000000
}
NOTE: "" is the default account.
Get addresses for your default account:
$ bitcoin-cli getaddressesbyaccount ""
[
"1pXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"1JXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
]
Validate an address:
$ bitcoin-cli validateaddress "1pXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
It shows public key, etc for that address.
Dump private key:
$ bitcoin-cli dumpprivkey "1pXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
It shows private key associated to that address. Be careful!!!
Show info about a block based on its hash:
$ bitcoin-cli getblock "0000000000000000038726af63010f9b3e8fa34ac75050d620d1253176ed88fc"
We recommend you to encrypt your wallet: How to encrypt and decrypt your Bitcoin wallet
If your wallet is encrypted, you need to enther the passphrase to execute dumpprivkey and other protected commands.
E.g: We enable the passphrase for 300 seconds:
$ bitcoin-cli walletpassphrase "my_pass_phrase" 300
Now we can dump the private key if we want to:
$ bitcoin-cli dumpprivkey "XXXXXXXXXXXXXXXXXXXXXXXX"
We can manually lock the wallet if we do not want to wait until timeout:
$ bitcoin-cli walletlock
How to perform a transaction
We will use sendtoaddress command:
$ bitcoin-cli help sendtoaddress
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount )
Send an amount to a given address.
Requires wallet passphrase to be set with walletpassphrase call.
Arguments:
1. "address" (string, required) The bitcoin address to send to.
2. "amount" (numeric or string, required) The amount in BTC to send. eg 0.1
3. "comment" (string, optional) A comment used to store what the transaction is for.
This is not part of the transaction, just kept in your wallet.
4. "comment_to" (string, optional) A comment to store the name of the person or organization
to which you're sending the transaction. This is not part of the
transaction, just kept in your wallet.
5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.
The recipient will receive less bitcoins than you enter in the amount field.
Result:
"txid" (string) The transaction id.
Examples:
> bitcoin-cli sendtoaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1
> bitcoin-cli sendtoaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "donation" "seans outpost"
> bitcoin-cli sendtoaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "" "" true
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendtoaddress", "params": ["1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd", 0.1, "donation", "seans outpost"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
First we introduce wallet pass phrase if our wallet is encrypted:
$ bitcoin-cli walletpassphrase "my_wallet_pass_phrase" 500
We need to set a transaction fee amount in Bitcoins per kilo byte:
$ bitcoin-cli help settxfee
settxfee amount
Set the transaction fee per kB. Overwrites the paytxfee parameter.
Arguments:
1. amount (numeric or string, required) The transaction fee in BTC/kB
Result
true|false (boolean) Returns true if successful
Examples:
> bitcoin-cli settxfee 0.00001
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "settxfee", "params": [0.00001] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
URLs to find a suitable transaction fee:
https://bitcoinfees.21.co/
https://estimatefee.com/
Convert satoshis per byte into BTC per kB
When writing this article 200 satoshis per byte was a good value.
100000000 satoshis equal 1 Bitcoin.
200 satoshis per byte == 200000 satoshis per kB == 0.002 BTC per kB
As a general rule:
X satoshis per byte == X*1000 satoshis per kB == X/100000 BTC per kB
$ bitcoin-cli settxfee 0.002
true
$ bitcoin-cli getbalance
0.05000000
True in the end means fee will substract from transfered value so less than 0.05 BTC will arrive.
$ bitcoin-cli sendtoaddress "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 0.05 "test" "to_destiny" true
1eXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
It returns the transfer Id. You can use that Id to show info about the transaction
$ bitcoin-cli gettransaction "1eXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
After transaction completed we can check balance:
$ bitcoin-cli getbalance
0.00000000
To show amount of bitcoins each of your addresses currently contains:
$ bitcoin-cli listunspent
You can find info about your address, transfer, etc in this URL:
https://bitinfocharts.com/bitcoin/explorer/
https://blockexplorer.com
Change address
If after a transaction the bitcoin node generates a change address which does not appear in current account, then
$ bitcoin-cli listunspent
command won't show the new address and correct values.$ bitcoin-cli listaddressgroupings
will show the new address, among other used addresses.To add the new change address to default account:
$ bitcoin-cli setaccount "1XXXXXXYYYYYYYYYZZZZZZZZZZZZZZZZZZ" ""
Now
$ bitcoin-cli listunspent
and $ bitcoin-cli getaddressesbyaccount ""
commands will work again.Reference
How to run a bitcoin full node:
https://bitcoin.org/en/full-node
Secure your wallet:
https://bitcoin.org/en/secure-your-wallet
Download bitcoin core:
https://bitcoincore.org/en/download/
Original Bitcoin client/API calls list:
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list