Adding Bitcoin Payment Gateway to React Native App

Bitcoins are buzz word these days. It increased in value from about $570 to more than $5,300 , a whooping 770% increase, in just the last year. Bitcoins are crypto-currency, i.e. they can be used like a currency, but don’t physically exist. They are digital cash that exist on different computers. Bitcoins can be used in transactions and can be transfered between people, just like other currency.  Best thing about bitcoin is that there is no financial system controlling there existence and value.

In this article we will learn how we can add bitcoin payment gateway our React Native App. We will add bitcoin payment feature to a boiler plate membership app. This boiler plate app is built with React Native and Firebase and has the following features :

  1. Login
  2. Registration
  3. Email verification
  4. User Listing
  5. User’s Profile
  6. In App Messaging/ Live Chat
  7. Skill based filter
  8. Distance based filter ( similar to tinder)

You can check the demo of this app here. You can check the features of this app here and if you want, you can get it from here.

So we will add a ‘Hire Me’ or ‘Make Payment’ button to the profile screen and link it to the bitcoin payment screen. Below is the code for bitcoin payment screen :

In the above code, we are using block.io api,  but you can use any other api of your choice if you want (, because there support team never respond). We have divided the total amount of transaction in two parts. The first part, i.e. ‘amountInBTC’, is the net amount that we want it to reach the receiver’s wallet ( bitcoin account). The second part i.e. ‘transactionId’  is the unique id we want to give to the total amount. So that all amount are unique and we can distinguish every transaction with it’s amount. Some small amount will be deducted from senders wallet as transaction fees.  Transaction fee, is the amount that will payed to the bitcoin miners for their hard work of verifying  and adding transaction to the public ledger. In the componentWillMount we make api call and get the wallet address and amount in wallet before the transaction. Next we show the user wallet address and QR code so that he can make the payment. We also provide user with option to confirm  transaction after making payment by pressing the ‘Confirm Payment’ button. When user press ‘Confirm Payment’ button we make second api call and get the current balance of wallet. If sum of old wallet balance ( before transaction) and total transaction amount is equal to new wallet balance ( after transaction ) then we show the message of transaction successful . If there is difference then we inform user that transaction was not successful.

So, this how we can add bitcoin payment gateway to our react native app. I hope you would have enjoyed the tutorial and find it informative. Subscribe to our news letter and YouTube video channel to stay tuned for such exciting React Native tutorials.

Video Tutorial