Perhaps I failed to scare you enough to make you give up this crazy idea of accepting payment in bitcoin. Well then, I have another portion of a headache for you.
Start of review for developers HERE
Wallet, wallet! What wallet??
In order to organize the reception of bitcoin on the site, as it is not too difficult to guess, we will need a wallet. Moreover, neither a hardware one, like Trezor or KeepKey, nor a desktop one, like the Orthodox Bitcoin-Qt, suits us. Only server implementation, only hardcore. The hardcore will be bitcoind, the reference bitcoin demon from the bitcoin core team.
A small digression (or a warning, as you prefer): what is described below assumes that you have experience interacting with the command line of UNIX-like operating systems (Linux, FreeBSD, MacOSX), have at least a vague idea of what bash scripts are (not a quotation book, but a command line shell), have experience installing software packages at least at the Copy-Paste level, and, probably, speak some language programming.
Installation of the bitcoind daemon is described quite fully on the official website bitcoin core. If you are interested in this process, or something doesn’t work out for you, welcome to the comments, if there are enough people interested, I will cover this topic in more detail. Here is a short cheat sheet on how to install bitcoind for one of the most common server operating systems - Ubuntu Linux:
#add a repository:
#!IMPORTANT - installation of packages requires superuser rights
sudo apt-add-repository ppa:bitcoin/bitcoin
# We politely ask the system to update the list of packages it knows:
sudo apt-get update
# And finally the magic:
sudo apt-get install bitcoind
After successfully executing the above commands, the very bitcoin daemon that we need for further manipulations will be firmly established on your Linux server. It is important to remember that the installation itself does not yet give us the opportunity to send and receive coins.
The demons are walled up!!
Now we need to decide in what mode we will launch our demon. It is logical to ask - what exactly are they? And they come in three main types.
The first is actually combat. If your untimely deceased uncle turned out to be the secret holder of untold wealth in bitcoin, you can safely start in combat mode and conduct all experiments with real money..
We, simpler people, will consider two other modes first. To be completely precise, it would be more correct to talk about what networks our service will work with. That same combat mode is the mainnet, that is, the main network through which very real bitcoins travel and with all the ensuing problems at once.
The second, more gentle mode for young, unseasoned developers istestnet - from the name it’s easy to guess that the network is a test one. If you had enough of a headache to begin with, you can stop there. The test network is "almost like the real one." You will need an internet connection, transactions will also be confirmed by miners, but the time to form a block in the test network is much shorter. And, of course, test coins do not have any financial weight. If you search the Internet, you can find a considerable number of sites that provide test coins for temporary use (in the community it is considered good form to return test coins after use).
If you are a complete recluse, or have no desire to download a meaningless test blockchain, then there is a third, and the most interesting, and in my opinion, the most convenient way for local development - regtest (Regression Test Mode) - essentially you create your own little bitcoin for yourself. Of course, only you will see your transactions, but you can admire the tidy sum of 100,000 BTC in your wallet and spend it left and right. In fact, you have access to any speed of transactions, any amounts, and of course, you can observe the behavior of the software in the same way as in a combat network, but completely free and much faster.
If you decide to use the testnet test network, the setup will differ little from the setup of a regular full node. The first thing you need to do after installing the bitcoind daemon before running it is to create a configuration file. In your home directory on your Linux machine, run the command mkdir -p ~/.bitcoin - this is where bitcoind will look for the configuration file, and create the bitcoin file there..conf containing the lines:
# allow access via JSON-RPC server=1 # in addition, we will need a user who will send commands to the daemon rpcuser=username rpcpassword=userpassword # and specify the working network testnet testnet=1
If you are using an operating system other than Linux, the location of the configuration file may be different:
Windows: %APPDATA%\Bitcoin
OSX: $HOME/Library/Application Support/Bitcoin/
Linux/FreeBSD: $HOME/.bitcoin/
When everything is ready, We start the daemon with the command bitcoind -daemon and wait a couple of minutes. Now we can check what we have done. Run the command bitcoin-cli getwalletinfo and look at the result. It should look something like this:
{
"result": {
"walletname": "wallet.dat",
"walletversion": 159900,
"balance": 0.00000000,
"unconfirmed_balance": 0.00000000,
"immature_balance": 0.00000000,
"txcount": 0,
"keypoololdest": 1528398419,
"keypoolsize": 981,
"keypoolsize_hd_internal": 1000,
"unlocked_until": 0,
"paytxfee": 0.00000000,
"hdmasterkeyid": "a721caa39233676ccd3dc0509d0b93a6bc55fb52"
},
"error": null,
"id": null
}
It doesn't matter what it all means yet. It is important that the result must contain information about the state of your newly created full node. Now the fun part begins - the process of synchronizing with the network.
For the main network it may take a couple of days, but testnet is much more compact. And depending on the Internet speed it will take up to several hours. We execute the command bitcoin-cli getnetworkinfo and study the result. We are interested in the "connections" line; it must be non-zero. This is a parameter that tells you how many connections your bitcoind has to remote nodes. If for some reason there is a proud “0” there, something went wrong. We look at the file .bitcoin/debug.log and try to figure out what exactly it is. In the next article we will look in more detail at how to collect your personal Bitcoin on a separate machine, that is, how to use regtest (Regression Test Mode).
In the meantime, let's try to do something more or less useful on the resulting node. The question immediately arises - we do not have anything similar to a wallet interface. How can we get an address, send funds and see the balance?
Run the command
bitcoin-cli getnewaddress
In response we will receive something like this: muMKs9cCCfdq5mV7mnffuLLFNqgFR33nNB. This is our new address on the testnet network.. It's different from the usual one - which is good because no one will be able to accidentally send real coins to the test address. But what does this address give us? For example, we can get some test coins from sites like those listed below:
https://testnet.coinfaucet.eu/en/
https://kuttler.eu/en/bitcoin/btc/faucet/
http://tpfaucet.appspot.com
You can look at examples of the code given in the article at github
But we will look at what to do with them next in the following articles.
You May Also Like
Apple publishes new rules on cryptocurrency apps
According to TechCrunch, a number of Apple developers recently joined forces to create the “Developers Union.” The union asked Apple to provide Apple Store users with the opportunity to download free trials of their applications. This is one of the first times that independent iOS developers are trying to fight back against Apple Store policies.
We accept payment in bitcoin: Part four, closer to the point!
In previous articles, we looked at the general principles of organizing a bitcoin payment gateway, figured out the tools and necessary software, and even assembled our own pocket bitcoin network.
