BlockIO
This Lib make integration with block.io in easy way.

With Block.io you can

    create new wallets: Bitcoin, Dogecoin, Litecoin
    look transactions
    accept payments
    make withdraws
    etc

Demo bot

See DemoBlockIOBot. It also available in the Store.
See docs about this bot.
​

Initial setup

Need to set Api key and secret pin in first. You can create command /init with such BJS:
1
// set secret PIN
2
Libs.BlockIO.setSecretPin("YOURS SECRET PIN");
3
​
4
Libs.BlockIO.Bitcoin.setApiKey("YOURS_API_KEY for Bitcoin");
5
Libs.BlockIO.Dogecoin.setApiKey("YOURS_API_KEY for Dogecoin");
6
Libs.BlockIO.Litecoin.setApiKey("YOURS_API_KEY for Litecoin");
7
​
8
// Testnet
9
Libs.BlockIO.testNet.Bitcoin.setApiKey("YOURS_API_KEY for Bitcoin");
10
Libs.BlockIO.testNet.Dogecoin.setApiKey("YOURS_API_KEY for Dogecoin");
11
Libs.BlockIO.testNet.Litecoin.setApiKey("YOURS_API_KEY for Litecoin");
Copied!
Just run bot and execute this command /init. Then you can remove it.
You get Secret PIN from Block.io by e-mail
You get API keys in Block.io dashboard by link "Show API Keys"
You can also provide pin and api key in commands in options

Methods

All methods from https://block.io/api available in the Lib.
You can run it via command:
1
Libs.BlockIO.XXXcoin.methodYYY(
2
{ onSuccess: "/onNewAddress",
3
onError: "/onerror",
4
// ....
5
// OTHER POSSIBLE PARAMS - see are later
6
} );
Copied!
XXXCoin - it is Bitcoin, Litecoin or Dogecoin
You can also use Testnet: Libs.BlockIO.testNet.XXXcoin

All methods

Method name for Libs.BlockIO.XXXcoin
Description
getNewAddress
Returns a newly generated address, and its unique(!) label generated by Block.io. You can optionally specify a custom label.
getBalance
Returns the balance of your entire Bitcoin, Litecoin, or Dogecoin account (i.e., the sum of balances of all addresses/users within it) as numbers to 8 decimal points, as strings.
getAddressBalance
Returns the balance of the specified addresses, or labels. Upto 2500 addresses/labels can be specified per request.
Can be used to query balances for external (non-account) addresses. If an external address' balance is returned, its user_id and label fields will be null.
getMyAddresses
Returns the (unarchived) addresses, their labels, user ids, and balances on your account. Upto 2500 addresses per page. Page parameter is optional.
getAddressByLabel
Returns the address specified by a label.
isValidAddress
Returns whether a single specified address is valid for the network, or not.
archiveAddresses
Archives upto 100 addresses in a single API call. Addresses can be specified by their labels.
unarchiveAddresses
Unarchives upto 100 addresses in a single API call. Addresses can be specified by their labels.
getMyArchivedAddresses
Returns all the archived addresses, their labels, and user ids on your account.
getTransactions
Returns various data for the last 25 transactions spent or received. You can optionally specify a before_tx parameter to get earlier transactions.
​
You can use this method to query for addresses that are not on your account.
getRawTransaction
Returns the raw data, including transaction hex, for a given transaction ID.
getNetworkFeeEstimate
Estimates the Network Fee you will need to pay when you make a withdrawal request. The Network Fee is required by the Bitcoin/Dogecoin/etc. networks, not Block.io.
isGreenTransaction
Returns an array of transactions that were sent by Block.io Green Addresses. Funds sent from Green Addresses are guaranteed by Block.io, and can be used immediately on receipt with zero network confirmations.
getCurrentPrice
Returns the prices from the largest exchanges for Bitcoin, Dogecoin, or Litecoin, specified by the API Key. Specifying the base currency is optional.
withdraw
Withdraws amount of coins from any addresses in your account to up to 2500 destination addresses.
withdrawFromAddresses
Withdraws AMOUNT coins from upto 2500 addresses at a time, and deposits it to up to 2500 destination addresses.
withdrawFromLabels
Withdraws AMOUNT coins from upto 2500 labels at a time, and deposits it to upto 2500 destination addresses, or labels.
Full methods docs here​
So if you need, for example, getTransactions method for Litecoin change this code:
1
Libs.BlockIO.XXXcoin.methodYYY(
2
{ onSuccess: "/onNewAddress",
3
onError: "/onerror",
4
// ....
5
// OTHER POSSIBLE PARAMS
6
} );
Copied!
to:
1
Libs.BlockIO.Litecoin.getTransactions(
2
{ onSuccess: "/onGetTransaction",
3
onError: "/onerror",
4
// ....
5
// OTHER POSSIBLE PARAMS
6
} );
Copied!

What it is - "OTHER POSSIBLE PARAMS" ?

It can be:
    api_key and pin. If you do not set here (for all methods)
    label, address (for getNewAddress methods and etc)
    labels, addresses
    to_addresses, from_addresses, from_labels (for withdraw )
    page
    transaction_ids (for isGreenTransaction method)
    type (for getTransactions method)
See available params in https://block.io/api page

​

Example for getNewAddress

For example: "Actions for Handling Addresses"
From block.io help:
from Block.io help - https://block.io/api
So we have API method "Get New Address":
1
Libs.BlockIO.Bitcoin.getNewAddress(
2
{ onSuccess: "/onNewAddress",
3
onError: "/onerror"
4
} );
Copied!
This function getNewAddress have 2 callbacks: onSuccess and onError.
onSuccess callback command /onNewAddress will be runned:
1
let wallet = options; // we have Block.io response in options
2
​
3
// uncomment this line for inspecting all options
4
// Bot.sendMessage(inspect(options));
5
​
6
Bot.sendMessage(
7
"*New wallet* was created. \n #⃣Wallet: `" +
8
wallet.address + "`\n 🏷Label: `" +
9
wallet.label + "`"
10
);
Copied!
​

Example for making Withdraw

from Block.io help - https://block.io/api
We know about params: to_addresses and from_labels from block.io help. See "Withdraw From Labels" method there
Transfer coin from Block.io wallet with label "default" to any wallet:
1
Libs.BlockIO.Bitcoin.withdrawFromLabels(
2
{ to_addresses:"3KyRZdjJCpHjHfnjaELvrDpNAxUE3D1NK4",
3
from_labels:"default",
4
amounts:0.002,
5
onSuccess: "/onwithdraw", onError: "/onerror"
6
});
Copied!
onWithdraw command:
1
Bot.sendMessage(inspect(options))
Copied!

​

Error handing

You can show error message from Block.io
1
Bot.sendMessage("Error");
2
​
3
if(options&&options.data){
4
Bot.sendMessage(options.data.error_message);
5
}
6
​
Copied!
​

How to...

Open new BTC address for each user (chat)?

possible BJS for command /newAddress:
1
Libs.BlockIO.Bitcoin.getNewAddress(
2
{
3
label: "chat" + chat.chatid,
4
onSuccess: "/onNewAddress",
5
onError: "/onError",
6
} );
Copied!
command /onNewAddress:
1
Bot.sendMessage(inspect(options));
2
Bot.sendMessage("Created: " + options.address);
Copied!
command /onError:
1
Bot.sendMessage("Error happens on wallet creation");
Copied!
​

How can I check any payment by user on block.io if I know him bitcoin address and payment will be 0,0001 Bitcoin?

Looks like you need to receive payments on one own wallet from several users.
It is bad practice:
    1.
    User must say his wallet before payment. Because after payment anybody can see any addresses in blockchain
    2.
    User can do mistake with his address wallet
    3.
    User can do mistake with amount
Thus, users will have incorrect operations. You should check them in manual mode. It will be very difficult for you to verify incorrect transactions in the blockchain.
More good practice it is generate new income address for each payment. It is more secure.
​
​
​
​
​
​
​
Last modified 2yr ago