Crypto&Blockchain

Run your own Bitcoin Full Node on an Azure Linux VM

Run your own Bitcoin Full Node on an Azure Linux VM

One year ago, I began my journey in the crypto and blockchain area. Recently, multiple circumstances made me thinking about my own crypto-related server. Of course, I choose Azure for running this server (for the time being). It has been a while since I last touched Linux, so I had quite a bit to refresh and learn. In this post, I’ll show you the steps that are needed for setting up an independent full node to support the Bitcoin network.

Setting up the Virtual Machine on Azure

First, we need to install the Azure CLI on our computer. We will use this one to connect to our virtual machine later on via SSH. Follow the instructions found here.

The second prerequisite is a program to generate SSH keys. You can use either the OpenSSH client shipping with Windows 10 (latest versions), use the Azure CLI or PuTTY (follow these instructions).

Create the VM

Once you have installed the CLI and your SSH keys are created, log into your Azure account. Go to the marketplace, and search for ‘ubuntu‘. Choose Ubuntu Server 18.04 LTS and hit the ‘Create‘ button in the next window.

Fill in the details of your Azure VM on the first page of the creation module:

Do not forget to set the SSH admin user, as adding one afterward is not as easy as it seems and it often also fails (I had a hard time to learn that). Also, we need to allow traffic through the default HTTP (80) and SSH (22) ports. Once you configured everything, go to disks.

I did not select premium disks but instead went with a Standard HDD to save some money. You can change that to your needs. The important part here is to NOT use managed disks as we will need to resize the OS disk after the creation of the VM. Follow the rest of the steps in the creation wizard and create your virtual machine. Once the machine is created, you should create a DNS label (hit the ‘Configure’ link at the VM’s overview page to get to the IP settings).

Log in via SSH

Let’s try if we can log in to our Linux VM via the Azure CLI. Open the ‘Microsoft Azure Command Prompt‘ on your PC. To be able to connect to our virtual machine, we need to log in to Azure first to obtain an access token for our session:

az login 

This will open a new browser tab, where you need to log in to your account again. After that, we will be redirected back to the CLI. Once that happened, go back to the overview page of your VM and click on ‘Connect’. This will open a pane where we will see the RDP and SSH connection option. Select SSH and copy the text below ‘Login using VM local account‘:

Paste it into the Azure Command Prompt window and provide your password (you should never use a password-less SSH key). If your screen looks now similar to this, you have successfully logged in:

Now that we have verified that we are able to log in via SSH, type exit to log out again as we have one step left to perform on the virtual machine.

Resizing the OS disk

A Bitcoin full node needs to download and verify the whole blockchain. The current size of the blockchain is around 250 GB, which would never fit in the default size of the OS disk of our VM. Luckily, it is pretty easy to resize the OS disk by running some commands in the Azure CLI.

First, stop the virtual machine:

az vm stop --resource-group YourResourceGroupName --name YourVMName 

Resizing the OS disk needs the VM to be deallocated (this may take some minutes):

az vm deallocate --resource-group YourResourceGroupName --name YourVMName

Once deallocation has finished, we are able to resize the OS disk with this command:

az vm update --resource-group YourResourceGroupName --name YourVMName --set storageProfile.osDisk.diskSizeGB=1024

Once you see the new size in the returned response from Azure, we can start the VM again:

az vm start --resource-group YourResourceGroupName --name YourVMName 

Depending on the distribution you are using, you may have to perform additional steps. Ubuntu, however, mounts the new disk size without any additional action. Verifying the new disk size is pretty easy (after logging back in via SSH), as the System Information displayed after login should already reflect the change (like in the screen above).

Preparing the Bitcoin node

After completing all the steps above, we are finally able to move on with the preparations for the Bitcoin node.

Bitcoin service user

As we will run the node as a service, we need an unprivileged service account:

sudo useradd -m -s /dev/null bitcoin

Great, we just created the account, including the creation of the home directory for the service user and default shell entry. If you want to see the system’s response, just leave out the /dev/null part out when running the command.

As we are going to restrict the access to the service to the bitcoin user (and its default group, which is also bitcoin), we need to add our admin user to the group. Run the following command to do so:

sudo usermod -a -G bitcoin [admin-user]

In order to make these changes (especially the group add) persistent, we need to perform a restart before we move on. You can not only use the Azure portal or CLI, but also use this command to make the VM restart immediately:

sudo shutdown -r now

This will log you out of the current SSH session. After waiting one minute or two, just log back in to continue the preparation of the full node.

Downloading and Verifying Bitcoin binaries

The next step involves downloading the bitcoin core package and its valid signature files (as we don’t trust, but verify). Run these two commands (you will need to hit enter a second time after the first download finished). I also created a temp directory for the download and other stuff.

mkdir ~/temp
cd ~/temp
btc_version="0.18.1"
wget https://bitcoincore.org/bin/bitcoin-core-$btc_version/bitcoin-$btc_version-x86_64-linux-gnu.tar.gz
wget https://bitcoincore.org/bin/bitcoin-core-$btc_version/SHA256SUMS.asc

According to Bitcoin.org the latest releases are signed with Wladimir J. van der Laan’s releases key, which has the fingerprint we are going to verify the downloaded binaries. It is recommended to do this for all crypto-related binaries you’re downloading, no matter on which OS.

Let’s try to import the key of Mr. van der Laan:

gpg --receive-key 0x01EA5486DE18A882D4C2684590C8019E36C2E964

You may get an error message telling you there was a server failure. In this case, run the following command to import the key:

gpg --keyserver hkp://keyserver.ubuntu.com:80 --receive-key 0x01EA5486DE18A882D4C2684590C8019E36C2E964

If you still get errors, there might be some missing packages or other reasons for the server failure. I managed to come through with the second command more often than the first, but in the end, I had the key in my local key store.

Now let’s verify the downloaded files:

gpg --verify SHA256SUMS.asc
sha256sum --ignore-missing -c SHA256SUMS.asc

If the command tells you that the signature is good and indeed from Mr. van der Laan, everything is fine with the hash file. The second command verifies the archive we downloaded earlier and should result in ‘OK’. If not, you should immediately delete those files as they might contain malware.

Note: I have read quite a few comments on reddit and other sites that we can safely ignore those warnings …

Installing Bitcoin binaries

Now that we have our bitcoin service user and verified the bitcoin binaries, we are finally at the point to install them:

tar zxf bitcoin-$btc_version-x86_64-linux-gnu.tar.gz
pushd bitcoin-$btc_version/bin; sudo cp bitcoind bitcoin-cli /usr/bin; popd;
bitcoind --version

After getting the install verification via the version string, it is a good practice to remove both the binaries and the hash file. If you need to reinstall, perform the steps above again to verify the authenticity of the files. Run these commands to remove those files:

rm bitcoin-$btc_version-x86_64-linux-gnu.tar.gz
rm SHA256SUMS.asc

Create a service config file

Now that we have Bitcoin installed, we need to prepare a .conf file for our upcoming service:

vi bitcoin.conf  
or
nano bitcoin.conf

This will open a text editor on Linux. Enter the base config to get the RPC server of the Bitcoin daemon (needed for bitcoin-cli) activated and save the file to the temp disc (press ‘ESC’ + ‘:’ and write ‘wq‘ if you used vi:, ‘CTRL’+’x’ followed by ‘y’ on nano):

testnet=0
regstest=0
mainnet=1
# Global Options
server=1 #activating rpc
rpcconnect=127.0.0.1 #default
rpcport=8332 #default
rpcallowip=127.0.0.1/32 #default
rpcbind=127.0.0.1  #default
disablewallet=1 #keeping wallet off (atm)
daemon=1
# Options only for mainnet
[main]
# Options only for testnet
[test]
# Options only for regtest
[regtest]

Now we just need to copy that file into the /etc/bitcoin folder. If this folder does not yet exist, create it with the following command:

sudo mkdir -p /etc/bitcoin

Next, copy the bitcoin.conf file to it:

sudo cp bitcoin.conf /etc/bitcoin

Assign ownership to the bitcoin service user and make it readable for all users:

sudo chown bitcoin:bitcoin /etc/bitcoin/bitcoin.conf
sudo chmod 0664 /etc/bitcoin/bitcoin.conf

The last step is to create a directory for the daemon where we will find the PID (Process ID) file after starting the service:

sudo mkdir -p /run/bitcoind/
sudo chmod 0755 /run/bitcoind/
sudo chown bitcoin:bitcoin /run/bitcoind/

Create the Bitcoin service

Now we are able to set up the core service of our node, the Bitcoin daemon service. In order to start, just copy and paste the one found at Bitcoin’s Github account into a new file on your VM. Once you have that file in your temp folder, copy it over to the system’s services folder:

sudo cp bitcoind.service /lib/systemd/system

Now we need to enable the service to make it automatically starting up on reboot:

sudo systemctl enable bitcoind

And finally, we need to start the service (or reboot the machine if you want to test that part):

sudo systemctl start bitcoind

After some time, you should be able to use the bitcoin-cli to get some info of your local blockchain copy:

sudo bitcoin-cli -rpccookiefile=/var/lib/bitcoind/.cookie -datadir=/var/lib/bitcoind -getinfo

Please note you need to use sudo because the owner of the service and the files is our bitcoin user we created earlier. If you don’t want to always pass the authentication cookie path, you can create a symbolic link to your current user’s .bitcoin folder:

sudo ln -s /var/lib/bitcoind/.cookie ~/.bitcoin/.cookie

Now we are able to just call sudo bitcoin-cli -getinfo. Another way of checking if the service and the daemon are running is to read the log that gets generated:

sudo tail /var/lib/bitcoind/debug.log -f 

You should see the log scrolling through as it writes new entries. The most entries will look like this:

2019-09-07T14:54:51Z UpdateTip: new best=000000000000004fa323c7ee57b4b22272c7ea757a6a5bdb53dbda73572f559d height=239240 version=0x00000002 log2_work=70.203272 tx=18819570 date='2013-06-02T08:32:35Z' progress=0.041989 cache=675.7MiB(5032783txo)

If you arrived at this point

Congratulations! You are running a Bitcoin full node (without wallet for the time being, though). It will take some time to download and verify the whole blockchain, but you are now effectively helping and securing the Bitcoin network.

This is just the first post about my journey with Bitcoin and my own node. Make sure to follow for future blog posts. As always, I hope this post will be helpful for some of you.

Helpful links

Note: this post was reposted on my Trybe.one account.

Posted by msicc in Azure, Crypto&Blockchain, Linux, 0 comments
Crypto and Blockchain projects & tools (April 2019)

Crypto and Blockchain projects & tools (April 2019)

NOTE: All following project and tools reflect my own opinion and my own experience. This post is not an investment advice or advice to use them. Also, your mileage may vary. Please make sure you also read the disclaimer at the end of this post as well. This post contains affiliate/referral links.

For Users

Mass adoption. If you keep following the crypto and blockchain space, you might have heard this term a lot. At the moment, besides gambling dApps (decentralized applications) on different blockchains, there are only a few real-world products floating around. Let’s have a look at some of them.

Presearch

Presearch is a decentralized search engine that has more than 1 million users (as of writing this), which is quite impressive for a beta product, especially in this special area. Presearch tries to disrupt the dominance of Google (which acts as the gate to the internet for more than 70% of all users).

I have been using Presearch for a few months now as my personal gate to the internet, and I enjoy the aggregation of my preferred search engines. If you look at my start page, you can see all the search providers I have chosen. From Bing, Google to Github as well as iTunes and Spotify, everything gets searched with a click. If you open a new Tab with Presearch, you can filter the search once more. I often use the Presearch engine search, which just delivers the best results for me. I am helping the product to evolve with this behavior, as a little bonus, I get 0.25 PRE(search token) for the searches I perform.

Presearch

Presearch has protection against cheaters (AI powered) in place. I am obviously not cheating to help the product, and my honesty is rewarded with an account level of 9. They have a Chrome extension which sets the current search engine (Desktop) just by installing it. Presearch even has a mobile app (beta, iOS), which is currently not able to connect to your account which I use from time to time. However, as happened with Bing and Google before, I am using their mobile website most of the time on my iPhone.

Brave Browser

If you have been following me for some time, you know that I am a fan of Microsoft. Recently, however, Microsoft turned into a more business-oriented company, leaving the consumer to just go with the products of other providers. This led me to search for alternatives of my personal browser – so I ended up with Brave Browser.

Brave aims to be faster and more private than the default choices users have. Websites store all kind of data in cookies and use trackers to collect data from a user while the later one is browsing the web. With Brave, you get back a good amount of control of the data you are willing to share. Over time, your privacy level will grow again just by using Brave. The browser shows you how many trackers, cookies and scripts were blocked while you are browsing.

Since a few weeks, user can receive rewards for watching ads. Users will be prompted to view ads (mostly short videos), and receive some BAT, the native currency of Brave – which they can use again to reward content creators. This is an opt-in feature, so users always have the choice.

If you have a blog, website or YouTube channel, you can help the project to grow. Register your site/channel as a creator, and use your BAT rewards to tip others and invite them to join, too. This way, knowledge about Brave will spread across the web from all sides.

CoinPaprika

CoinPaprikais a market analysis tool, and it is a powerful one. I discovered the project last summer (shortly after they started). I like it “hot and spicy”, so the name alone immediately called my attention. As I have two or three app ideas that need a service like CoinPaprika, I was happy to learn they have an open API as well, with really generous API rate limits. I am contributing to the project in the form of maintaining a .NET library.

coinpaprika_client

CoinPaprika is somewhat different to other providers, as they do not rely on data of CoinMarketCap (which a lot of services in this area do). Instead, they are pulling in data of more than 250 exchanges on their own, resulting in over 2000 currencies they track. On top, they provide a great oversight on each project (click the coin stats links above to see some samples).

They are also working on a mobile app, which will combine their analysis tools with a non-custodial wallet (based on Trust Wallet’s core). You can get a short overview and register for beta notification at
https://coins.coinpaprika.com/.

AtomicPay

AtomicPay is a non-custodial payment service provider. While there are quite some providers of such services floating around, AtomicPay holds the flag of decentralization pretty high. The service just provides the invoicing infrastructure, while the payment itself is only tracked by the system. The effective payment is a direct customer to merchant transaction – the funds move directly into the merchant’s wallet. The whole infrastructure is built around Electrum and its derivations for other currencies.

atomicpay-title-image

By using common implementations like SegWit and HD (Hierarchical Deterministic) wallets as well as no address re-use, AtomicPay ensures security and privacy on a high level with a reasonable amount of initial administrative work. AtomicPay provides several integrations into already existing online shopping systems, an open Rest-API, payment buttons for websites and more.

I am also involved in this project and currently working on the official native apps for Android and iOS. We have already published a .NET SDK, which enables you already today to implement crypto payments into your apps. On our roadmap, we have a Xamarin.Forms ready plugin and SDKs for other programming languages as well.

For Developers

Being a mature programming language, C# has already quite some important and ready-to-use libraries to interact with certain blockchains. Here is a list of projects I am following:

Wallets and Exchanges

If you want to get some cryptocurrencies, you need some starting points:

  • Where to buy?
  • Where to convert/exchange?
  • Where to store HODLs?

While there are several options out there, I have found a combination that works for me.

BitPanda

Buying crypto currencies with bank transfer or credit card is pretty easy on BitPanda, an Austrian provider. They accept deposits in EUR, CHF, USD and GBP. Once your FIAT deposit is in your BitPanda account, you can exchange them for a variety of crypto currencies including Bitcoin, Ethereum, NEO and more. If you want to sign up and get a 10 EUR bonus after your first purchase, you can use my referral link (I am getting the bonus as well).

Binance

Binance is one of the biggest centralized crypto exchanges around. They have a huge amount of tradeable assets and also great liquidity. If a trading pair is available on Binance, chances are high that you will get the best price there. Their apps and website offer a good default set of indicators, so you normally won’t need any additional tools. Binance is also said to be one of the few exchanges to not fake their trading volume. If you haven’t signed up to Binance, feel free to use my referral link.

ChangeNOW

ChangeNOW is a decentralized exchange that is connected to big centralized exchanges to get the best rates. On certain pairs, you have a fixed rate option besides the quick-and-dirty approach that all such services provide. However, if you use that one, you will get a smaller exchange value than with the default option because of lowering the risk. In my experience, the exchange rates reflect the current market prices more often than not. Other providers have a bigger spread.

Transactions are executed as fast as possible, if something goes wrong and you provide your wallet for refunds, your funds will always be safe. Additionally, you can provide your mail address to get informed when the exchange took place (so you won’t need to constantly refresh the website).

KyberSwap

KyberSwapis another decentralized exchange, but just for Ethereum tokens (at least at them moment of writing this). It is based on the Kyber protocol, which allows fast and direct swaps of tokens (for example BAT=>KNC) without the need of exchanging first to Ethereum and then into the desired token. There are already quite a few dApps built on the Kyber protocol, you can see a list here. Recently, KyberSwap launched a nice and easy to use iOS app, which supports also a price alert feature (USD and ETH base pairs only, however).

Trust Wallet

Trust Wallet, the official non-custodial wallet of Binance, has a good reputation when it comes to storing your HODLs. It is available for both Androidand iOS, with a desktop version being worked on. They are constantly adding new coins, and the usage is even for new users pretty easy. Their Telegram support group is always just a message away in case you need some help.

MyEtherWallet and MEWConnect

If you want to perform advanced operations (like cleaning pending transactions or getting your *.eth address), there is a big chance that you will be able to do it with MyEtherwallet.

They recently launched a newer version of their website. However, not all functionality has been ported over (yet). If you cannot find an option on the new site, you will find it for sure at their vintage site. The most secure way to connect to MyEtherWallet is their MEWConnect app (available for iOS and Android), which transforms your phone into a hardware wallet-like device. You need to confirm transactions on the device before you can move on in the browser, adding in an additional security layer.

Etherscan

Etherscan is the best known Ethereum blockchain explorer around. It has tons of features, from viewing transactions or contracts to token details and ENS-Lookup. Whenever I need to verify or search something related to the Ethereum blockchain, this is my first goto-address.

O3 Wallet (NEO)

If you are searching for blockchains built with .NET, sooner or later you will run into NEO. I only recently began to explore the possibilities of the NEO blockchain and its native currency. NEO has a token ecosystem as well. IF you need a cross-platform wallet, I would give the O3 wallet a try. It integrates with Switcheo (another decentralized exchange) and quite a few other dApps (like registering your .neo address via NNS) running on NEO.

New projects

The crypto space never stand still. New projects are showing up almost every day. Here is a list of projects I recently started to discover. It is way to early to write a review on them, but I may do so in a follow up post.

  • WolfpackBot (beta, crypto trading bot running on its own blockchain)
  • Bravo (write reviews, receive crypto)
  • Switcheo (decentralized exchange for NEO and ETH tokens, EOS soon)
  • Electroneum (mobile (cloud) mining on its own blockchain, use 5576A9 to get a 1% bonus on your mining rewards (5% for me))

News Sources

It is always good to know what is going on in the crypto space. Here are some reliable news sources I use:

Conclusion

Besides the hundreds (if not thousands) of gambling dApps across all blockchains, there are also interesting real word projects one can use today. Some of them are more popular than others, but not every project is worth your attention. This post showed some of the projects I am interested in.

If you know a project/tool/dApp that is missing in this list, feel free to leave a comment below or ping me on social networks. Maybe your suggestions will make it into the next post of this kind.

Disclaimer: I am contributing to one or more crypto/blockchain projects with code written by me under the MIT License. Future contributions may contain their own (and different) disclaimer. I am not getting paid for my contributions to those projects at the moment of writing this.

Please note that none of my crypto-related posts is an investment or financial advice. As cryptocurrencies are volatile and risky,  you should only invest as much as you can afford to lose. Always do your own research!

Title Image Credit

Posted by msicc in Crypto&Blockchain, Editorials, 0 comments
Introducing Coinpaprika and announcing C# API Client

Introducing Coinpaprika and announcing C# API Client

As I am diving deeper and deeper into the world of cryptocurrencies, I am exploring quite some interesting products. One of them is Coinpaprika, a market research site with some extensive information on every coin they have listed.

What is Coinpaprika?

In the world of cryptocurrencies, there are several things one needs to discover before investing. Starting with information on the project and its digital currencies, the persons behind a project as well as their current value and its price, there is a lot of data to walk through before investing. Several sites out there are providing aggregated information, and even provide APIs for us developers. However, most of them are

  •  extremely rate limited
  •  freemium with a complex pricing model
  •  slow

Why Coinpaprika?

A lot of services that provide aggregated data rely on data of the big players like CoinMarketCap. Coinpaprika, however, has a different strategy. They are pulling their data from a whopping number of 176 exchanges into their own databases, without any proxy. They have their own valuation system and a very fast refreshing rate (16 000 price updates per minute). If you have some time and want to compare how prices match up with their competition, Coinpaprika even implemented a metrics page for you. In my personal experience, their data is more reliable average to those values I see on those exchanges I deal with (Binance, Coinbase, BitPanda, Changelly, Shapeshift).

Coinpaprika API and Clients

Early last week, I discovered Coinpaprika on Steemit. They announced their API is now available to the general public along with clients for PHP, GO, Swift and NodeJS. Coinpaprika has also a WordPress plugin and an embeddable widget (on a coin’s detail page) that allows you to easily show price information on your website. After discovering their site, I got in contact with them to discuss a possible C# implementation for several reasons:

  •  very generous rate limits (25 920 00 requests per month, others are around 6 000 to 10 000), which enables very different implementation scenarios
  •  their API is fast like hell
  •  their independence from third parties besides exchanges
  •  their very catchy name (just being honest)

A few days later, I was able to discuss the publication of the C# API client implementation I wrote with them. I am happy to announce that you can now download the C# API Client from Nuget or fork it from my Github repository. They will also link to it from their official API repository soon. The readme-file on Github serves as documentation as well and shows how to easily integrate their data into your .NET apps. The library itself is written in .NET Standard 2.0. If there is the need to target lower versions, feel free to open a pull request on Github. The Github repo contains also a console tester application.

Conclusion

If you need reliable market data and information on the different projects behind all those cryptocurrencies, you should evaluate Coinpaprika. They aggregate their data without any third party involved and provide an easy to use and blazing fast API. I hope my contribution in form of the C# API client will be helpful for some of you out there.

If you like their product as much as I do, follow them:

  • Twitter: https://twitter.com/coinpaprika
  • Facebook: https://www.facebook.com/coinpaprika/
  • Steemit: https://steemit.com/@coinpaprika
  • Medium: https://medium.com/coinpaprika
  • Telegram: https://t.me/Coinpaprika

Happy coding, everyone!

Disclaimer: I am contributing to this project with code written by me under the MIT License. Future contributions may contain their own (and different) disclaimer. I am not getting paid for my contributions to the project.

Please note that none of my crypto related posts is an investment or financial advice. As crypto currencies are volatile and risky,  you should only invest as much as you can afford to lose. Always do your own research!

Posted by msicc in Crypto&Blockchain, Dev Stories, 1 comment