Reader small image

You're reading from  Mastering Blockchain.. - Third Edition

Product typeBook
Published inAug 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781839213199
Edition3rd Edition
Languages
Right arrow
Author (1)
Imran Bashir
Imran Bashir
author image
Imran Bashir

Imran Bashir has an M.Sc. in Information Security from Royal Holloway, University of London, and has a background in software development, solution architecture, infrastructure management, and IT service management. He is also a member of the Institute of Electrical and Electronics Engineers (IEEE) and the British Computer Society (BCS). Imran has extensive experience in both the public and financial sectors, having worked on large-scale IT projects in the public sector before moving to the financial services industry. Since then, he has worked in various technical roles for different financial companies in Europe's financial capital, London.
Read more about Imran Bashir

Right arrow

Bitcoin Clients and APIs

This chapter introduces Bitcoin client installation, and a basic overview of various APIs and tools that are available for developing Bitcoin applications and interacting with the Bitcoin blockchain. We will examine how to set up a Bitcoin node and test networks. Also, we will introduce various commands and tools that are used to perform important functions in Bitcoin systems. The chapter will be made up of the following main topics:

  • Bitcoin client installation
  • Experimenting further with bitcoin-cli
  • Bitcoin programming

Let's begin by running through the Bitcoin client installation process.

Bitcoin client installation

The Bitcoin core client can be installed from https://bitcoin.org/en/download. This is available for different architectures and platforms, ranging from x86 Windows to ARM Linux, as shown in the following screenshot:

Figure 8.1: Download Bitcoin Core

We will discuss a number of topics relating to Bitcoin's installation and setup. We'll begin by discussing different Bitcoin clients available and their associated tools, which enable you to run and manage the Bitcoin client and interact with the Bitcoin blockchain.

Types of clients and tools

There are different types of Bitcoin core clients and relevant tools. A Bitcoin client is a piece of software that is responsible for generating private/public key pairs and facilitates Bitcoin payments using the Bitcoin blockchain. In addition, a client can implement full synchronization function with a blockchain or choose to only implement basic wallet functionality or simple payment verification...

Experimenting further with bitcoin-cli

As we've seen so far, bitcoin-cli is a powerful and feature-rich command-line interface available with the Bitcoin Core client and can be used to perform various functions using the RPC interface provided by the Bitcoin Core client.

We will now see how to send Bitcoin to an address using the command line. For this, we will use the Bitcoin command-line interface on the Bitcoin regtest:

  1. Generate a new address using the following command:
    $ bitcoin-cli -regtest getnewaddress
    2NC31WFFRwRkwd3S4TpyjN5GGDY7E63GSVd
    
  2. Send 20 BTC to the newly generated address:
    $ bitcoin-cli -regtest sendtoaddress \ 2NC31WFFRwRkwd3S4TpyjN5GGDY7E63GSVd 20.00
    

    The output of this command will show the transaction ID, which is:

    a83ff460a32f29387d531f19e7092a5dcf6ce52d20931227447c0b9b7a5f2980
    
  3. We can now generate a few more blocks to get some confirmation for this:
    $ bitcoin-cli -regtest...

Bitcoin programming

Bitcoin programming is a very rich field. The Bitcoin Core client exposes various JSON-RPC commands that can be used to construct raw transactions and perform other functions via custom scripts or programs. Also, the command-line tool bitcoin-cli is available, which makes use of the JSON-RPC interface and provides a rich toolset to work with Bitcoin.

These APIs are also available via many online service providers in the form of Bitcoin APIs, and they provide a simple HTTP REST interface. Bitcoin APIs, such as blockchain.info (https://blockchain.info/api), BitPay (https://bitpay.com/api), block.io (https://www.block.io), and many others, offer a myriad of options to develop Bitcoin-based solutions.

Various libraries are available for Bitcoin programming. A list is shown as follows. Those of you who are interested can explore the libraries further:

Summary

This chapter started with an introduction to Bitcoin installation, followed by some discussion on source code setup and how to set up Bitcoin clients for various networks. After this, we examined various command-line options available in Bitcoin clients. Lastly, we saw which APIs are available for Bitcoin programming and the main points to keep in mind while evaluating APIs for usage. In the next chapter, we will introduce alternative electronic cash blockchain projects, that is, the digital currency projects other than Bitcoin, such as Litecoin and Namecoin. We will also discuss various ideas that led to the development of alternative coin projects.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Blockchain.. - Third Edition
Published in: Aug 2020Publisher: PacktISBN-13: 9781839213199
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Imran Bashir

Imran Bashir has an M.Sc. in Information Security from Royal Holloway, University of London, and has a background in software development, solution architecture, infrastructure management, and IT service management. He is also a member of the Institute of Electrical and Electronics Engineers (IEEE) and the British Computer Society (BCS). Imran has extensive experience in both the public and financial sectors, having worked on large-scale IT projects in the public sector before moving to the financial services industry. Since then, he has worked in various technical roles for different financial companies in Europe's financial capital, London.
Read more about Imran Bashir