Listening for Payments on the Bitcoin and Ethereum Blockchains
With our ongoing token sale at BX8.io, it was essential for our ICO website to listen for blockchain payments made by participants. We wanted to make sure that people who were sending us crypto would get instant confirmation that we had received their contributions.
In the past, we used Blockcypher to fulfill this role on our older platform, BloomRemit. Blockcypher is a blockchain API company that can programmatically generate forwarding addresses for payments. The address listens for payments and then immediately forwards whatever it receives to the ultimate destination. In our case, that was a Bloom wallet address. As we anticipated larger amounts to flow through the addresses provided, we felt less comfortable trusting a third party for these transactions.
So we decided to create our own solution for this and called it crypto-cold-store. It has 2 features. 1) It allows you to generate a new address and 2) listen for new deposits on the addresses that you generate.
$ curl "https://crypto-cold-store-testnet.bx8.io/api/v1/deposit_detail?coin=btc&code=apr28"$ { "address":"3Q8V6w97njBNPJXWPaXWqBDNXmSTBs28VW" }
For notifications of deposits on any of the generated addresses, we use a ruby library called message_bus. This makes it easy for us to push notifications on a single channel and our subscribers(apps) can monitor any new transaction entries from there.
If you use Ruby like we do, there is another library called message_bus_client that you can install on your apps that would consume those notifications. Here’s a sample code on how you could start with it.
client = MessageBusClient.new(“https://message-bus-url.com”)client.subscribe(“/channel-notifications”) do |payload, message_id|
# do something with the payload, like associating a user
end
Listening for payments is one of the features any ICO website should have. There are varying solutions available but when expecting BTC or ETH as a payment method, crypto-cold-store is a great and simple solution.