Your Trusted Partner for Exquisite Room Additions in Hilton Head

When it comes to transforming your living space and expanding your home’s functionality, look no further than HHI Builders. With our unrivaled expertise and commitment to excellence, we are dedicated…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Ultimate Guide to Bitcoin Testnet Fullnode Setup

Blockchain Image from Unsplash.com

In this in-depth tutorial, we will cover the basics of blockchain, why you would want a bitcoin full-node, how to setup a bitcoin full-node on linux using the testnet chain and how to interact with your node and the blockchain using the cli and the json rpc, where we will create wallets and addresses and sending tbtc to your accounts.

Before we start setting up our bitcoin full-node, we first need to get through some blockchain basics, if you already aware of it, you can skip the the setup section of this post.

Transaction data is permanently recorded into files called blocks. You can think of it as a transaction ledger. Blocks are organised into a linear sequence over time.

A blockchain is a transaction database shared by all nodes participating in a system based on the bitcoin protocol. A full copy of a currency’s blockchain contains every transaction ever executed in the currency. With this information, one can find out how much value belonged to each address at any point in history.

Every block contains a hash of the previous block. This has the effect of creating a chain of blocks from the genesis block to the current block. Each block is guaranteed to come after the previous block chronologically because the previous block’s hash would otherwise not be known. Each block is also computationally impractical to modify once it has been in the chain for a while because every block after it would also have to be regenerated. These properties are what make bitcoins transactions irreversible. The blockchain is the main innovation of Bitcoin.

Mining is the process of adding transaction records to bitcoin’s public ledger of past transactions. The term “mining rig” is referred to where as a single computer system that performs the necessary computations for “mining”.

The blockchain serves to confirm transactions to the rest of the network as having taken place. Bitcoin nodes use the blockchain to distinguish legitimate Bitcoin transactions from attempts to re-spend coins that have already been spent elsewhere.

A full node is a node (computer system with bitcoin-core running on it) which downloads every block and transaction and check them against bitcoin’s consensus rules. which fully validates transactions and blocks. Almost all full nodes also help the network by accepting transactions and blocks from other full nodes, validating those transactions and blocks, and then relaying them to further full nodes.

Some examples of consensus rules:

At minimum, a full node must download every transaction that has ever taken place, all new transactions, and all block headers. Additionally, full nodes must store information about every unspent transaction output until it is spent.

A subset of full nodes also accept incoming connections and upload old blocks to other peers on the network. This happens if the software is run with `-listen=1` as is default.

Contrary to some popular misconceptions, being an archival node is not necessary to being a full node. If a user’s bandwidth is constrained then they can use `-listen=0`, if their disk space is constrained they can use pruning, all the while still being a fully-validating node that enforces bitcoin’s consensus rules and contributing to bitcoin’s overall security.

Now for the fun part, to setup bitcoin-core on linux, in my case I am using a fresh Ubuntu 20.04 instance and the following commands will be executed as a non-root user.

Create the user and group for bitcoin:

Update the package manager and install the dependencies:

Download bitcoin-core and verify that the package matches the sha hash:

When you have to upgrade the software version of bitcoin-core in the future you can remove the symlink with `sudo rm -rf /usr/local/bitcoin/current` and symlink to the newer version as shown above.

Create the systemd unit-file for bitcoind:

Now move the temporary config files, change the ownership and symlink the bitcoin home directory to the path that we created earlier:

Move the systemd unit file in place, then reload systemd and start bitcoind:

Switch to the `bitcoin` user:

And append the bitcoin path to the `~/.profile` file so that your user know where to find the bitcoin binaries:

Once bitcoind process has started, the initial block download will start and you can get the progress as the bitcoin user using the cli:

Or as the root user you can view the progress using `journalctl`:

If you run into any issues you can see the status of bitcoind using:

Or check the logs:

To get the current block count:

To get some basic info about the first block ever created on the bitcoin blockchain. As the genesis block, it has the index value 0. We can use `getblockhas` to get the hash value for the first block ever created:

We can now use `getblock` with the hash value to retrieve details about the block:

We can use the `nextblockhash` to retrieve information about block 1:

We can use `-getinfo` to get information show as the verification progress and balances in our wallets, should they exist:

First get the jsonrpc user and password:

Because this is a test environment, we can set the username and password as an environment variable:

Create a wallet:

List wallets:

If we inspect the `bitcoin.conf` we will notice that we don’t have the wallet loaded in our config:

But since we created the wallet, we can see the `wallet.dat` in our data directory:

Let’s restart the `bitcoind` service and see if we can still list our wallet, first restart the service:

Then wait a couple of seconds and list the wallets:

As you can see it’s not loaded, due to it not being in the config. Let’s update our config `~/.bitcoin/bitcoin.conf`, and restart the service:

When I restarted the `bitcoind` service, I checked the logs with `journalctl -fu bitcoind`, and I could see the wallet has been loaded:

When I list the wallets again:

Now that the wallet has been loaded, we can get wallet info:

Create another wallet, named `test-wallet`:

After we created our wallet, list the wallets again:

Now that we have 2 wallets, we need to specify the wallet name, when we want to do a `getwalletinfo` method for a specific wallet, `test-wallet` in this case:

In order to understand where the data resides for our `test-wallet`, we can use `find`:

Include the wallet name in the config located at `~/.bitcoin/bitcoin.conf`:

Then restart bitcoind:

Now list our wallets again, and you should see they are being read from config and the wallets will persist if your node restarts:

To backup a wallet, the `test-wallet` in this case:

To check where the file was backed up:

At this moment we have wallets, but we don’t have any addresses associated to those wallets, we can verify this by listing wallet addresses using the `getaddressesbylabel` and passing a empty label as new addresses gets no labels assigned by default.

Let’s generate a new address for our `test-wallet`:

As you can see our address for `test-wallet` is `tb1qr66hw59k958xrz008n679p8r9n2y7mjfr3tsjc`, note that you can have multiple addresses per wallet.

To get address information for the wallet by using the `getaddressinfo` method and passing the wallet address as the parameter:

As before, we can view the address by label, to view the address for your wallet, we will now see our address:

Get available wallet balance with at least 6 confirmations,:

Get balances (all balances) for the `test-wallet` wallet:

Create a new address:

List all addresses for the wallet:

Now we can label addresses on wallets, to label the first address as “green”:

Label the new address as “blue”:

Now we can list addresses for our wallet by the label, “blue” in this example:

List addresses for our wallet by the label “green”:

Create another address for our test-walet:

Set the new address to the green label:

List addresses by green label:

You can receive free test btc, by using any of these testnet faucet websites to receive tBTC over testnet:

The transaction details for sending 0.001 tbtc to my `tb1qr66hw59k958xrz008n679p8r9n2y7mjfr3tsjc` address, we will receive the following information:

Then to list transactions:

As you can see at the time, there were 0 confirmations, we can see the same txid as well as other info. With the testnet, we require at least 1 confirmation before a transaction is confirmed, where the mainnet requires 6.

To get balances for our wallet:

As you can see as we don’t have any confirmations yet, so therefore the trusted value is still 0.

Listing the transactions over time:

After a couple of minutes:

We can also use a blockchain explorer, head over to a testnet blockchain explorer, such as:

And provide the txid, in my case it was this one:

This transaction was done a while ago, so the confirmations will be much more than from the output above, but you can see the confirmations, addresses involved and tbtc amount.

To only get the trusted balance, using the getbalance method and with at least 6 confirmations(note: testnet only requires 1 confirmation to mark a transaction confirmed):

Let’s send another transaction, the list the transactions using the listtransactions method:

After 12 hours, we can see that we have 102 confirmations for our first transaction and 99 transactions for the second transaction:

After 3 transactions, view the balance in the test wallet using the `getbalance` method:

To send a transaction is by using the sendtoaddress method and the source wallet will be in the request url, ie: `/wallet/wallet-name`

First we look if we have a address for our account that we are sending from, if not then we can create a wallet and a address, for this example, I have a address for the `wallet` wallet:

Ensure that our source wallet has funds in it:

We have enough funds to send, so we now have the source wallet name and we need to get the wallet address, where we want to send the funds to, which in this case is the address in `test-wallet` as the destination:

Just to double check our current funds in the wallet that will receive funds:

Now we will use the sendtoaddress method, with the recipient address and the amount to send as the parameters. To summarize:

Sending the amount:

We will receive a transaction id in the response, and if we list for transactions for our source wallet, we will see the transaction:

So when we look at the sender wallet, we will see the funds was deducted:

And when we look at the receiver wallet, we can see that the account was received:

The source code of this blog post will be added to this Github Repository:

Add a comment

Related posts:

Are You Plagued With Single Digit Views?

Are you one of those really successful writers on Medium who are fortunate enough to get thousands and thousands of views for the stories you write? Or could you be one of the multitude who get only…

Glacier Tour in Alaska

Matanuska Glacier is locted in Alaska. It is a valley glacier. It is the largest glacier accessible by car in the United States. It is 27 miles long by 4 miles wide. The glacier’s terminus feeds the…

Getting Mocked and Complimented by Slackbot

I recently met up with a close friend who’s a senior software engineer. In their off-time, they’d been working on some for-fun features for the Slackbot in our friend group’s Slack chat (because…