A transaction records the exchange of Bitcoin from one account to another.
In a Terminal window, execute this command to see the unspent balance owned by a user "Alice" on the real Bitcoin blockchain:
curl https://blockchain.info/unspent?active=1Cdid9KFAaatwczBwBttQcwXYCpvK8h7FK
As shown below, Alice has two "unspent outputs", one worth 8,450,000 satoshis and one worth 100,000 satoshis.
Troubleshooting
If curl is not installed, execute these commands to install it:sudo apt-get update
sudo apt install curl -y
A satoshi is the smallest unit of Bitcoin currency. There are 100,000,000 satoshis in a Bitcoin. So Alice has 0.0855 Bitcoins, or about $250 at the current Bitcoin price of $2900 (as of 6-11-17).
A typical transaction contains one input and two outputs, as shown in the figure below, taken from the Mastering Bitcoin online e-book.
With credit cards, a transaction is sent to the central bank, and once recorded there, the transaction is finalized.
But with Bitcoin, the transaction is not finalized until it is gathered together with others to form a block of transactions, and signed by a Bitcoin miner. All the miners in the network race to be the first one to calculate a valid signature, and the first miner to succeed wins. The winning miner is rewarded with a prize of newly minted Bitcoins (currently 12.5 bitcoins per block) and also transaction fees included in each transaction. A new block is signed every 10 minutes, on average.
Even after a block is mined, it might be cancelled later and reversed. The current standard is to consider a transaction irrevocable after six confirmations, or six blocks. The author of "Mastering Bitcoin" explains the situation this way:
Bitcoin is nearly at its limit: all blocks full, as shown below. For this reason, Bitcoin forked in August, 2017, and another fork is expected soon, as the Bitcoin community remains divided on ways to address this problem.
sudo apt-get update
sudo apt-get install git build-essential -y
sudo apt-get install autoconf libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libtool -y
sudo apt-get install libdb5.3++-dev libevent-dev pkg-config -y
wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz
sha256sum db-4.8.30.NC.tar.gz
The result should be
12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef,
as shown below.
Execute these commands:
tar -xvf db-4.8.30.NC.tar.gz
cd db-4.8.30.NC/build_unix
mkdir -p build
BDB_PREFIX=$(pwd)/build
../dist/configure --disable-shared --enable-cxx --with-pic --prefix=$BDB_PREFIX
make install
cd ../..
There are a lot of warnings during the "make
install" but as long as there are no errors
at the end, ignore them.
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git tag
The latest version seems to be v0.9.5rc2,
as shown below.
However, if you scroll up, you can see that this is just a cruel joke. The version numbers treat 0.10 as greater than 0.9, s in accordance with Semantic Versioning 2.0.0 standards. The newest stable version was actually v0.15.0.1 when I did it on 10-16-17, as shown below. I recommend avoiding the "rc" versions.
(If you accidentally install the wrong version, and decide to reinstall a different one, you must execute this command first to clean out the old one: "git clean -f -x -d".)
Execute these commands to clone the latest version and see compile-time options. Adjust the version number as necessary.
git checkout v0.15.0.1
./autogen.sh
./configure --help
There are a lot of options available, worth
taking a look at, but for our purposes
a default installation will be fine.
Execute these commands:
./configure --with-incompatible-bdb
make
The compiling takes about 20 minutes.
It also requires at least 2 GB of RAM.
Execute these commands to install the bitcoin core software, and to check the installation location:
sudo make install
which bitcoind
which bitcoin-cli
Both items should be in /usr/local/bin,
as shown below.
cd
mkdir .bitcoin
nano .bitcoin/bitcoin.conf
Paste in these lines, replacing the
password with something unique:
rpcuser=bitcoinrpc
rpcpassword=7bLjxV1CKhNJmdxTUMxTpF4vEemWCp49kMX9CwvZabYi
as shown below.
Press Ctrl+X, Y, Enter to save the file.
bitcoind -regtest -daemon
Execute this command to see listening
processes:
netstat -pant
The daemon for our private "regtest"
network is listening on port
18444,
as shown below.
Press Shift+PrintScrn to copy the whole desktop to the clipboard.
YOU MUST SUBMIT A FULL-SCREEN IMAGE FOR FULL CREDIT!
Paste the image into Paint.
Save the document with the filename "YOUR NAME Proj 7a", replacing "YOUR NAME" with your real name.
bitcoin-cli -regtest getblockchaininfo
Scroll back up to see the start of the output.
At this point, our blockchain contains
zero blocks, as shown below.
bitcoin-cli -regtest getinfo
Your wallet's "balance" is zero,
as shown below.
Execute this command to encrypt your wallet. I'm using a password of P@ssw0rd -- of course, you should replace that with a strong password of your own choice when deploying blockchains with real value.
bitcoin-cli -regtest encryptwallet P@ssw0rd
Wait a few seconds for the service to stop.
Execute these commands to restart the server, and see the wallet status again.
bitcoind -regtest -daemon
bitcoin-cli -regtest getinfo
Now "getinfo" shows an "unlocked until" value
of zero, indicating that the wallet is locked,
as shown below.
Execute these commands to unlock your wallet for ten minutes (360 seconds), and see the wallet status again.
bitcoin-cli -regtest walletpassphrase P@ssw0rd 360
bitcoin-cli -regtest getinfo
Now "getinfo" shows an "unlocked until" value
in Unix epoch format,
as shown below.
bitcoin-cli -regtest backupwallet wallet.backup
ls -l ~/wal*
You see a "wallet.backup" file,
as shown below.
Execute these commands to unlock youur wallet and restore your wallet from backup:
bitcoin-cli -regtest walletpassphrase P@ssw0rd 360
bitcoin-cli -regtest importwallet wallet.backup
bitcoin-cli -regtest dumpwallet wallet.txt
head wallet.txt
You see a file header, followed by some addresses,
as shown below.
Execute this command to get a new address from the available pool of addresses (100, by default).
bitcoin-cli -regtest getnewaddress
The address appears,
as shown below.
It's a long random sequence
of bytes.
The address starts with "m" or "n"
because it's on a test network.
Bitcoin addresses on the real blockchain start
with "1" or "3".
bitcoin-cli -regtest generate 1
bitcoin-cli -regtest getblockchaininfo
Now the blockchain contains
one block, as shown below.
On the real Bitcoin blockchain, the difficulty is set much higher, so mining a block requires an expensive cluster of specialized computers. But the difficulty is set very low on our test network, so mining blocks is easy.
bitcoin-cli -regtest listtransactions
There is one transaction, in the amount of
50 bitcoins,
as shown below. This is your award for
mining the first block.
Execute this command to view your balance:
bitcoin-cli -regtest getbalance
Your balance is 0,
as shown below.
Why isn't your balance 50? Because the block you mined isn't "confirmed" yet. On the real Bitcoin blockchain, a block is confirmed when there have been 6 blocks after it mined, but on our testnet, confirmation takes 100 additional blocks.
bitcoin-cli -regtest generate 100
You see 100 block hashes,
as shown below.
Execute this command to see information about the blockchain:
bitcoin-cli -regtest getblockchaininfo
Now the blockchain contains
101 blocks, as shown below.
Execute this command to view your balance:
bitcoin-cli -regtest getbalance
Your balance is 50 bitcoins,
as shown below.
bitcoin-cli -regtest listunspent
You see one transaction for 50 bitcoins,
that's "spendable",
as shown below.
Press Shift+PrintScrn to copy the whole desktop to the clipboard.
YOU MUST SUBMIT A FULL-SCREEN IMAGE FOR FULL CREDIT!
Paste the image into Paint.
Save the document with the filename "YOUR NAME Proj 7b", replacing "YOUR NAME" with your real name.