CryptoProcessing.io Simple BTC Payments

Eugene Khashin
4 min readNov 24, 2020

This guide describes steps to setup BTC payments for your website or mobile app.

As a result, you will show deposit address in your interface and you will get notifications on incoming payments.

You have to choose how you plan to identify payments, because you will have to generate addresses and understand what the generated address actually used for. There are 2 options: address per customer or address per deposit. In this guide we will show instruction how to process with first way as it’s most common one.

Your Environment

Assuming you have customers database, let’s say it’s users table. Also you should have a website with public endpoint which might be reached by our backend (for transactions webhooks).

Also in current case we assume you have your own BTC wallet where all BTC will be actually collected at (we suggest using electrum.org, but it’s up to you).

CP Account

Create account at CryptoProcessing.io and process 2FA setup, IP whitelist restrictions (specify IP address of your server you use to make requests to CP).

Generate API Keys

Page: https://cryptoprocessing.io/api_keys
Press Generate New API Key and save it, this key is required to make http requests to the API.

Test Request

curl "https://cryptoprocessing.io/api/v1/ping" \
-H "Authorization: Token <token>"

<token> is your API Key

Wallet Setup

In your CP account find BTC Main Wallet and click on it, then follow steps.

https://cryptoprocessing.io/wallets/:id

By default your balance should be equal to 0. Find Wallet ID in browser address bar and save it (it will be required to make API calls)

Payments Forwarding

This section is used to automate BTC collection to your wallet (eg. Electrum, or Coinbase or Blockchain.info).

https://cryptoprocessing.io/wallets/:id/forwardings

You will find, you don’t have any forwarding configuration. Click on CREATE button and fill all required fields:

https://cryptoprocessing.io/wallets/:id/forwardings/new

BTC Address
Your address from your wallet which you want to have collected all payments at.

Blocks Count
1 (how many blocks we have to count to transfer money). You may also use 0 as a value, but this works if you enable such a feature by pressing ALLOW UNSPENT USAGE button in wallet page.

Fee
7000
(the value will be deducted from incoming payments to process BTC forwarding). You may play with this value, but we suggest to use this value at start.

Webhooks

We call your http endpoint once transaction caught or confirmation from BTC network processed.

Go to wallet page and press WEBHOOKS button.

https://cryptoprocessing.io/wallets/:id/webhooks

Press Create New Webhook button and fill all required fields:

URL
Endpoint from your website, eg https://yourwebsite.com/webhooks/cp

Max Confirmations
1
(how may confirmations you want to wait for transaction being accepted by your backend). We suggest using 1, as for BTC it’s secure enough.

Max Retries
3
(how many times we will retry our callback if you will return non 2xx status). Let’s start with 3 and if you will need to have more retries, you’ll be able to change the value or re-create webhook.

Webhook Content: https://docs-api.cryptoprocessing.io/#webhook-request (Webhook for BTC section), we will describe the code how to parse it correctly.

Deposit Address Creation (API)

For each of your customers you generate and save address (when customer registered in your system)

https://docs-api.cryptoprocessing.io/#create-address

We suggest passing name parameter to have ability to identify address in case we need to investigate something by your request.

BTC Rate

If you need to show BTC/USD rate you may use a Ticker service to get current rate:

https://ticker.cryptoprocessing.io/api/v1/data/price

You need to parse BTC:USD value and show it to customer, but specify that forwarding fee (7000 sat is applied to each deposit).

Webhook Parsing

Once something is happened in BTC Blockchain we will call your webhook and you have to parse it.

There are 2 main option how to interact with any service:
1. Pushing (we call you with data and you operate with it)
2. Pulling (you call us and operate with responses)

To avoid MITM attacks we suggest combining of both options:
We call you and you synchronize transactions by requesting them.

Here is meta-example of code you should use (please implement it using programming language you’re good in):

Look at webhook content

transaction["outs"].each do |tx|
address = tx["address"]
CALL_UPDATE_TRANSACTIONS_PROCEDURE(address)
end

UPDATE_TRANSACTIONS_PROCEDURE

(address) # Procedure/Function Parametertransactions = GET https://docs-api.cryptoprocessing.io/#wallet-39-s-address-transactions# Endpoint should look like: https://cryptoprocessing.io/api/v1/wallets/#{wallet_id}/addresses/#{address}/transactionstransactions.each do |tx| # for each transaction
addresses = tx["receiver_addresses"]
tx_hash = tx["hash"]
confirmations_count = tx["confirmations_count"]
addresses.each do |address_object| # for each address in tx
user = FIND_USER_BY_ADDRESS(address_object["address"])
amount = address_object["amount"]
existing_tx = FIND_TRANSACTION(tx_hash)
if not existing_tx.present? # if it's not found
SAVE_TRANSACTION(tx_hash, amount, confirmations_count)
else
UPDATE_CONFIRMATIONS_COUNT(tx_hash, amount, confirmations_count)
end
end
end

Procedure might be called without webhook and it’s calling shouldn’t break anything or trigger multiple deposits. This method is used to synchronize customers’ transactions.

Functions you have to implement on your backend:FIND_USER_BY_ADDRESS
FIND_TRANSACTION
SAVE_TRANSACTION
UPDATE_CONFIRMATIONS_COUNT

Once transaction is created on your side you may show the deposit to your customer.

Feel free to share your feedback with me in Telegram:
https://t.me/adastreamer

--

--