Requirements
Ruby >= 3Installation
Install the gem and add to the application's Gemfile by executing:
bundle add blockbeeIf bundler is not being used to manage dependencies, install the gem by executing:
gem install blockbeeAPI and utils
Importing in your project file
require 'blockbee'Get information (service of regarding a cryptocurrency)
require 'blockbee'
info = BlockBee::API.get_info(coin, prices)
# or if you wish to get full BlockBee service information
info = BlockBee::API.get_info(nil, prices)Where
coinis the coin you wish to use, from BlockBee's supported currencies (e.g 'btc', 'eth', 'erc20_usdt', ...).pricesby default0. If1will return the prices of the cryptocurrencies converted to all supported FIAT currencies.
Generating a new Address
require 'blockbee'
blockbee_helper = BlockBee::API.new(coin, callback, api_key, own_address: own_address, parameters: parameters, bb_params: bb_params)
address = blockbee_helper.get_address
# or address['address_in'] if you just wish the address stringWhere:
coinis the coin you wish to use, from BlockBee's supported currencies (e.g 'btc', 'eth', 'erc20_usdt', ...).callbackis the URL that will be called upon payment.api_keyis the API Key provided by BlockBee's dashboard.own_address(optional) is your own crypto address, where your funds will be sent to.parameters(optional) is any parameter you wish to send to identify the payment, such as{orderId: 1234}.bb_params(optional) parameters that will be passed to BlockBee _(check which extra parameters are available here: https://docs.blockbee.io/#operation/create).
Response sample:
{
"status": "success",
"address_in": "0xe10818d4037B7C427109dFbCFC2c8757c0352FE8",
"address_out": "0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d",
"callback_url": "https://webhook.site/ef8e2859-12a9-4028-8a94-51582e83dd05?order_id=13435",
"minimum_transaction_coin": "1.00000000",
"priority": "default",
"multi_token": true
}Getting notified when the user pays
Once your customer makes a payment, BlockBee will send a callback to your
callbackUrl. This callback information is by default inGETbut you can se it toPOSTby settingpost => 1inbb_params. The parameters sent by BlockBee in this callback can be consulted here: https://docs.blockbee.io/#operation/confirmedcallbackget
Checking the logs of a request
require 'blockbee'
blockbee_helper = BlockBee::API.new(coin, callback, api_key, own_address: own_address, parameters: parameters, bb_params: bb_params)
logs = blockbee_helper.get_logsSame parameters as before, the
datareturned can b e checked here: https://docs.blockbee.io/#operation/logs
Response sample:
{
"status": "success",
"callback_url": "https://example.com/?order_id=1235",
"address_in": "0x58e90D31530A5566dA97e34205730323873eb88B",
"address_out": "0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d",
"notify_pending": false,
"notify_confirmations": 1,
"priority": "default",
"callbacks": []
}Generating a QR code
require 'blockbee'
blockbee_helper = BlockBee::API.new(coin, callback, api_key, own_address: own_address, parameters: parameters, bb_params: bb_params)
qrcode = blockbee_helper.get_qrcode(value: value, size: size)Where:
valueis the value requested to the user in the coin to which the request was done. Optional, can be empty if you don't wish to add the value to the QR Code.sizeSize of the QR Code image in pixels. Optional, leave empty to use the default size of 300.
Response is an object with
qr_code(base64 encoded image data) andpayment_uri(the value encoded in the QR), see https://docs.blockbee.io/#operation/qrcode for more information.
Response sample:
{
"status": "success",
"qr_code": "iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAYeklEQVR4nO3daZQdZZkH8Od5q+quvXenO3tCQtg3WQLDOiwi4FEGRA96RhkRlEUd9cw5Ojif/DTOHEcF4YAwntFRhBEHBPWoKAECGNnXSICQBEL23m/fvkvV+8yHut3pEPoSaop6qjv/3wcOSbrurVv3/vutW8/7vMUiQgCgx2jvAMD+DiEEUIYQAihDCAGUIYQAyhBCAGUIIYAyhBBAmdvk35g5sf2IS4S5BxFe5nTPEu8Ri3ceRYwvM9qjRXiWBJ49MU1eJkZCAGUIIYAyhBBAGUIIoAwhBFCGEAIoQwgBlDWrE05HvQ9YvRw33Q4kU1iL9mjxvmsxVkqbbBJhn2fihxMjIYAyhBBAGUIIoAwhBFCGEAIoQwgBlCGEAMoQQgBlUYr1Tej2ekajXvieTmrbcJs8UYQdSPMbPZ149xkjIYAyhBBAGUIIoAwhBFCGEAIoQwgBlCGEAMpYruhPuZ9Ltdu4y6NF66lNZsVk9Q7dZGwkBlCGEAMoQQgBlCCGAMoQQQBlCCKAMIQRQhhACKEMIAZQ1K9bHWERWr0cnc6vgNL/MmUh9efhkjidGQgBlCCGAMoQQQBlCCKAMIQRQhhACKEMIAZRFaepNs2QaNONtEdZtOFbvqY33oWbiYtYYCQGUIYQAyhBCAGUIIYAyhBBAGUIIoAwhBFCGEAIoa1asn85MbF1NtxYegXpFOALsWDI3fsZICKAMIQRQhhACKEMIAZQhhADKEEIAZQghgDKEEEBZlGJ9EzEWvhMryMa4Ane8dX/1lQ1wBCKIUN/HSAigDCEEUIYQAihDCAGUIYQAyhBCAGUIIYCymOuEqZXMms2JLbOdTAEt3lJtjHXYeMV7MCPsM0ZCAGUIIYAyhBBAGUIIoAwhBFCGEAIoQwgBlCGEAMr2l2J9vOItIiezzHMyNxKPMMFA/QbX6guNYyQEUIYQAihDCAGUIYQAyhBCAGUIIYAyhBBAGSdT2IlXMh26EUQ7MjGW49K8Wm4yTb3qtU0s/gsw8yCEAMoQQgBlCCGAMoQQQBlCCKAMIQRQhhACKItSrE8z3fKuet05AvVVw5PpkI79iWKEkRBAGUIIoAwhBFCGEAIoQwgBlCGEAMoQQgBlzeqEAJAAjIQAyhBCAGUIIYAyhBBAGUIIoAwhBFCGEAIoQwgBlP0fDDJ0PYOZxyEAAAAASUVORK5CYII=",
"payment_uri": "0x0E945b1554c8029A6B9bE1F7A24ae75d2F44d8DB"
}Usage
<img src={"data:image/png;base64,#{qr_code}"}/>Estimating transaction fees
require 'blockbee'
estimation = BlockBee::API.get_estimate(coin, addresses, priority)Where:
coinis the coin you wish to check, from BlockBee's supported currencies (e.g 'btc', 'eth', 'erc20_usdt', ...)addressesThe number of addresses to forward the funds to. Optional, defaults to 1.priorityConfirmation priority, (check this article to learn more about it). Optional, defaults todefault.
Response is an object with
estimated_costandestimated_cost_usd, see https://docs.blockbee.io/#operation/estimate for more information.
Response sample:
{
"status": "success",
"estimated_cost": "0.00637010",
"estimated_cost_currency": {
"AED": "0.03",
"AUD": "0.01",
"BGN": "0.01",
"BRL": "0.04"
}
}Converting between coins and fiat
require 'blockbee'
blockbee_helper = BlockBee::API.new(coin, callback, api_key, own_address: own_address, parameters: parameters, bb_params: bb_params)
conversion = blockbee_helper.get_conversion(from_coin, value)Where:
valuevalue to convert infrom.from_coincurrency to convert from, FIAT or crypto.
Response is an object with
value_coinandexchange_rate, see https://docs.blockbee.io/#operation/convert for more information.
Response sample:
{
"status": "success",
"value_coin": "241.126",
"exchange_rate": "0.803753"
}Getting supported coins
require 'blockbee'
supported_coins = BlockBee::API.get_supported_coinsResponse is an array with all supported coins.
Response sample:
{
"btc": {
"coin": "Bitcoin",
"logo": "https://api.cryptapi.io/media/token_logos/btc.png",
"ticker": "btc",
"minimum_transaction": 8000,
"minimum_transaction_coin": "0.00008000",
"minimum_fee": 546,
"minimum_fee_coin": "0.00000546",
"fee_percent": "1.000",
"network_fee_estimation": "0.00002518"
},
"bch": {
"coin": "Bitcoin Cash",
"logo": "https://api.cryptapi.io/media/token_logos/bch.png",
"ticker": "bch",
"minimum_transaction": 50000,
"minimum_transaction_coin": "0.00050000",
"minimum_fee": 546,
"minimum_fee_coin": "0.00000546",
"fee_percent": "1.000",
"network_fee_estimation": "0.00000305"
}
}Checkout
Requesting Payment
require 'blockbee'
blockbee_helper = BlockBee::Checkout.new(notify_url: NOTIFY_URL, api_key: API_KEY, parameters: {
'order_id': 2022
}, bb_params: {
'post' => 1
})
payment_page = blockbee_helper.payment_request(redirect_url, value)Where:
api_keyis the API Key provided by our Dashboard.parametersis any parameter you wish to send to identify the payment, such as{'order_id': 1234}.bb_paramsparameters that will be passed to BlockBee _(check which extra parameters are available here: https://docs.blockbee.io/#operation/create).redirect_urlURL in your platform, where the user will be redirected to following the payment. Should be able to process the payment using thesuccess_token.notify_urlURL in your platform, where the IPN will be sent notifying that a payment was completed. Parameters are available here: https://docs.blockbee.io/#operation/paymentipn.valueamount in currency set in Payment Settings you want to receive from the user.
Getting notified when the user completes the Payment
When receiving payments, you have the option to receive them in either the
notify_urlor theredirect_url, but adding theredirect_urlis required (refer to our documentation at https://docs.blockbee.io/#operation/paymentipn).
Payment samples:
{
"status": "success",
"success_token": "G4asA2xwEr0UeY2IZqlZjX3IYrNofmnIAkzHPAoxmpmlYP9ZLTvQUolKN0X27Z0B",
"payment_url": "https://pay.blockbee.io/payment/OcRrZGsKQFGsoi0asqZkr97WbitMxFMb/",
"payment_id": "OcRrZGsKQFGsoi0asqZkr97WbitMxFMb"
}Payment Logs
Fetch Payment information and IPN logs.
require 'blockbee'
logs = BlockBee::Checkout.payment_logs(token, api_key)Where:
tokenis thepayment_idreturned by the payment creation endpoint.api_keyis the API Key provided by BlockBee's dashboard.
Response sample:
{
"status": "success",
"is_paid": false,
"is_pending": false,
"is_expired": false,
"is_partial": false,
"payment_data": [
{
"value": "0.000137",
"value_paid": "0",
"value_outstanding": "0.000137",
"exchange_rate": "0.0000137489",
"coin": "btc",
"txid": []
}
],
"notifications": []
}Requesting Deposit
require 'blockbee'
blockbee_helper = BlockBee::Checkout.new(notify_url: NOTIFY_URL, api_key: API_KEY, parameters: {
'order_id': 2022
}, bb_params: {
'post' => 1
})
deposit_page = blockbee_helper.deposit_requestWhere:
api_keyis the API Key provided by our Dashboard.parametersis any parameter you wish to send to identify the payment, such as{'order_id': 1234}.bb_paramsparameters that will be passed to BlockBee (check which extra parameters are available here: https://docs.blockbee.io/#operation/deposit).notify_urlURL in your platform, where the IPN will be sent notifying that a deposit was done. Parameters are available here: https://docs.blockbee.io/#operation/depositipn.
Response sample:
{
"status": "success",
"payment_url": "https://pay.blockbee.io/deposit/jv12du8IWqS96WVDjZK2J285WOBOBycc/",
"payment_id": "jv12du8IWqS96WVDjZK2J285WOBOBycc"
}Deposit Logs
Fetch Deposit information and IPN logs.
require 'blockbee'
logs = BlockBee::Checkout.deposit_logs(token, api_key)Where:
tokenis thepayment_idreturned by the deposit creation endpoint.api_keyis the API Key provided by BlockBee's dashboard.
Response sample:
{
"status": "success",
"deposits": [],
"total_deposited": "0",
"currency": "USDT",
"notifications": []
}Payouts
Create Payout / Payout Request
This function can be used by you to create Payouts.
require 'blockbee'
coin = 'polygon_matic'
requests = {
'0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d' => 0.5,
'0x18B211A1Ba5880C7d62C250B6441C2400d588589' => 0.1
}
create_payout = BlockBee::API.create_payout(coin, payout_requests, api_key, process)Where:
coinThe cryptocurrency you want to request the Payout in (e.gbtc,eth,erc20_usdt, ...).requestsAddress(es) together with the amount that must be sent.api_keyis the API Key provided by BlockBee's dashboard.processIf the Payout Requests will be sent right away. Defaults toFalse. Note: ifTruewill instantly queue the payouts to be sent to the destination addresses.
Response sample:
If process is false.
{
"status": "success",
"request_ids": [
"3825d29b-7a8f-47da-8623-e99850674247",
"d9925105-ea5f-4661-8d01-505096212ac5"
]
}If process is true.
{
"status": "success",
"payout_info": {
"id": "d9219d07-a8e5-4d89-a869-3c5717a25b27",
"status": "Created",
"from": "",
"requests": {
"0xA8EbeD50f2e05fB4a25b2DdCdc651A7CA769B5CF": "0.300000000000000000",
"0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d": "0.200000000000000000"
},
"total_requested": "0.5",
"total_with_fee": "0.505",
"total_fiat": "",
"fee": "0.005",
"coin": "bep20_usdt",
"txid": "",
"timestamp": "05/03/2024 15:00:00"
},
"queued": true
}List Payouts / Payout Requests
List all Payouts or Payout Requests in your account.
Note: If requests is True it will fetch a Payout Requests list.
require 'blockbee'
list_payouts = BlockBee::API.list_payouts(coin, status, page, api_key, payout_request)Where:
coinThe cryptocurrency you want to request the lists in (e.gbtc,eth,erc20_usdt, ...).statusThe status of the Payout / Payout Request. Possible statuses are:- Payout Request: [
all,pending,rejected,processing,done] - Payout: [
created,processing,done,error]
- Payout Request: [
pageThis endpoint is paginated and will show only50items per page. Defaults to1.api_keyis the API Key provided by BlockBee's dashboard.payout_requestIfTruewill fetch Payout Requests, otherwise will fetch Payouts. Defaults toFalse.
Response sample:
{
"status": "success",
"payouts": [
{
"id": "3825d29b-7a8f-47da-8623-e99850674247",
"status": "Done",
"total_requested": "0.6",
"total_with_fee": "0.606",
"total_fiat": "",
"fee": "0.006",
"coin": "polygon_matic",
"timestamp": "13/03/2024 17:48:39"
}
],
"num_pages": 1
}Get Payout Wallet
Gets your Payout Wallet for the specified coin. Can algo get the balance.
require 'blockbee'
wallet = BlockBee::API.get_payout_wallet(coin, api_key, balance)Where:
coinThe cryptocurrency you want to request the lists in (e.gbtc,eth,erc20_usdt, ...).api_keyis the API Key provided by BlockBee's dashboard.balanceIfTruewill also fetch the balance of the address.
Response sample:
{
"address": "0x18B211A1Ba5880C7d62C250B6441C2400d588589",
"balance": "2.7"
}Create Payout with Payout Request ID(s)
With this function you can create a Payout in the created status by simply providing an array with the Payout Requests ID.
require 'blockbee'
payout_ids = [52211, 52212]
payout = BlockBee::API.create_payout_by_ids(api_key, payout_ids)Where:
payout_idsits an array with the Payout RequestsID.
Response sample:
{
"status": "success",
"payout_info": {
"id": "d9219d07-a8e5-4d89-a869-3c5717a25b27",
"status": "Created",
"from": "",
"requests": {
"0xA8EbeD50f2e05fB4a25b2DdCdc651A7CA769B5CF": "0.300000000000000000",
"0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d": "0.200000000000000000"
},
"total_requested": "0.5",
"total_with_fee": "0.505",
"total_fiat": "",
"fee": "0.005",
"coin": "bep20_usdt",
"txid": "",
"timestamp": "05/03/2024 15:00:00"
}
}Process Payout by ID
By default, a Payout when created will be in created state. With this function you may finish it using its ID.
require 'blockbee'
payout = BlockBee::API.process_payout(api_key, payout_ids)Where:
payout_idsIts theID(or multipleID) of the Payout you wish to fulfill.
Response sample:
{
"status": "success",
"payout_info": {
"id": "d9219d07-a8e5-4d89-a869-3c5717a25b27",
"status": "Created",
"from": "",
"requests": {
"0xA8EbeD50f2e05fB4a25b2DdCdc651A7CA769B5CF": "0.300000000000000000",
"0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d": "0.200000000000000000"
},
"total_requested": "0.5",
"total_with_fee": "0.505",
"total_fiat": "",
"fee": "0.005",
"coin": "bep20_usdt",
"txid": "",
"timestamp": "05/03/2024 15:00:00"
},
"queued": true
}Check the Payout status
Will return all important information regarding a Payout, specially its status.
require 'blockbee'
payout_id = 51621
status = BlockBee::API.check_payout_status(api_key, payout_id)Where:
payout_idIts theIDof the Payout you wish to check.
Response sample:
{
"status": "success",
"payout_info": {
"id": "d9219d07-a8e5-4d89-a869-3c5717a25b27",
"status": "Done",
"from": "0x18B211A1Ba5880C7d62C250B6441C2400d588589",
"requests": {
"0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d": "0.500000000000000000",
"0x18B211A1Ba5880C7d62C250B6441C2400d588589": "0.100000000000000000"
},
"total_requested": "0.6",
"total_with_fee": "0.606",
"total_fiat": "",
"fee": "0.006",
"coin": "polygon_matic",
"txid": "0xf9aa1618a7e460f8c68b6a02369b5058282c53a4ee23f967abef0d35203f328c",
"timestamp": "13/03/2024 18:10:35"
}
}Testing
Option 1: Using .env file (Recommended)
- Copy the example environment file:
cp .env.example .env- Edit
.envwith your actual API credentials:
# Required: Your BlockBee API Key from https://dash.blockbee.io/
BLOCKBEE_API_KEY=your-actual-api-key-here
# Required: Callback URL for payment notifications
BLOCKBEE_CALLBACK_URL=https://your-domain.com/webhook- Install dependencies and run tests:
bundle install
bundle exec rake testOption 2: Using environment variables
Alternatively, you can set environment variables directly:
export BLOCKBEE_API_KEY="your-api-key-here"
export BLOCKBEE_CALLBACK_URL="https://your-domain.com/webhook"
bundle exec rake testNote: If no API key is provided, only basic tests (like version check) will run. The .env file is automatically ignored by git to keep your credentials secure.
Help
Need help? Contact us @ https://blockbee.io/contacts/