API Module
In order to demonstrate the flexibility of the framework, it is configured to supports several different API providers, but not all of the framework functionality can be provided by all providers - with the following matrix used as a summary:
API Provider | Homepage | Provider ID | Blockchains | Markets | Pagination | Addresses | DNKeys |
---|---|---|---|---|---|---|---|
Blockstrap | http://blockstrap.com | blockstrap | 8 | Y | Y | Y | Y |
SoChain | http://chain.so | sochain | 6 | N | N | N | N |
Blockr | http://blockr.io | blockr | 4 | N | N | N | N |
HelloBlock | http://helloblock.io | helloblock | 1 | N | Y | Y | N |
A brief explanation of the columns listed above:
- Provider ID is used in configuration to set the desired API using
api_service
- Blockchains attribute listed above refers to the number of supported blockchains
- Markets refers to support for the market conditions plugin included with the framework
- Pagination refers to the ability to paginate transactions within addresses
- Addresses refers to the ability to check multiple addresses with one call (used for prioritizer theme)
- DNKeys refers to the ability to check publicly listed addresses using the DNKey specification
API Functions & Variables
The API Module features the following functions:
$.fn.blockstrap.api.address
(hash, blockchain, callback, service, return_raw)$.fn.blockstrap.api.addresses
(hashes, blockchain, callback, service)$.fn.blockstrap.api.balance
(hash, blockchain, callback, service)$.fn.blockstrap.api.block
(height, blockchain, callback, service, return_raw)$.fn.blockstrap.api.dnkey
(id, blockchain, callback, service, return_raw)$.fn.blockstrap.api.dnkeys
(id, blockchain, callback, service, return_raw)$.fn.blockstrap.api.map
(blockchain)$.fn.blockstrap.api.market
(blockchain, stat, callback, service, return_raw)$.fn.blockstrap.api.request
(url, callback, type, data, blockchain, call, username, password)$.fn.blockstrap.api.relay
(hash, blockchain, callback, service, return_raw)$.fn.blockstrap.api.results
(defaults, results, blockchain, request, callback)$.fn.blockstrap.api.transaction
(txid, blockchain, callback, service, return_raw)$.fn.blockstrap.api.transactions
(address, blockchain, callback, service, return_raw, count, skip)$.fn.blockstrap.api.unspents
(address, blockchain, callback, confirms, service, return_raw)$.fn.blockstrap.api.url
(action, key, blockchain)
You may also want to learn about API Mapping.
api.address
(hash, blockchain, callback, service, return_raw) - back to top
This function uses the selected API to get information pertaining to an address.
The information it is able to map (with the corresponding defaults) includes:
{
address: 'N/A',
hash: 'N/A',
tx_count: 0,
blockchain: blockchain,
received: 0,
balance: 0
}
Example usage of this function could look like:
var api = $.fn.blockstrap.modules.api;
api.address('1121cQLqCsDsLPAkJW5ddTCREZ7Bp4ufrk', 'btc', function(results)
{
// Your callback
console.log(results)
});
Which should provide the following results:
{
address: "1121cQLqCsDsLPAkJW5ddTCREZ7Bp4ufrk",
balance: 0,
blockchain: "btc",
hash: "0030ececbad05ffcdff89f3f26e38ca3d735a8de",
received: 5000000000,
tx_count: 2
}
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
If return_raw
is set to true, the raw results will be returned through callback
instead of passing through api.results
.
api.addresses
(hashes, blockchain, callback, service) - back to top
This function uses the selected API to get information pertaining to multiple addresses.
The information it is able to map (with the corresponding defaults) includes:
{
address: 'N/A',
hash: 'N/A',
tx_count: 0,
blockchain: blockchain,
received: 0,
balance: 0
}
Example usage of this function could look like:
var api = $.fn.blockstrap.modules.api;
api.addresses(
['1121cQLqCsDsLPAkJW5ddTCREZ7Bp4ufrk, 12higDjoCCNXSA95xZMWUdPvXNmkAduhWv'],
'btc', function(results)
{
// Your callback
console.log(results)
}
);
Which should provide the following results:
{
address: "1121cQLqCsDsLPAkJW5ddTCREZ7Bp4ufrk",
balance: 0,
blockchain: "btc",
hash: "0030ececbad05ffcdff89f3f26e38ca3d735a8de",
received: 5000000000,
tx_count: 2
},
{
address: "12higDjoCCNXSA95xZMWUdPvXNmkAduhWv",
balance: 0,
blockchain: "btc",
hash: "12ab8dc588ca9d5787dde7eb29569da63c3a238c",
received: 7762439255612,
tx_count: 75
}
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
api.balance
(hash, blockchain, callback, service) - back to top
This function uses the selected API to get the balance of an address.
Example usage of this function could look like:
var api = $.fn.blockstrap.modules.api;
api.balance('1121cQLqCsDsLPAkJW5ddTCREZ7Bp4ufrk', 'btc', function(results)
{
// Your callback
console.log(results)
});
Which should provide the results as an integer.
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
api.dnkey
(id, blockchain, callback, service, return_raw) - back to top
This function uses the selected id
and blockchain
to search for the publicly listed DNKey and returns the relevant address (public key) if it is listed with the associated DNS TXT record.
api.dnkeys
(id, blockchain, callback, service, return_raw) - back to top
This function uses the selected id
to search for the publicly listed DNKeys whilst ignoring the blockchain
and blockstrap
variables with hard-coded corresponding values of multi
and blockstrap
. To be honest, it's a complete hack and should not really be here, but we really wanted to ship 0.5 as early as possible.
api.block
(height, blockchain, callback, service, return_raw) - back to top
This function uses the selected API to get information pertaining to a block.
The information it is able to map (with the corresponding defaults) includes:
{
blockchain: blockchain,
height: 'N/A',
hash: 'N/A',
prev: 'N/A',
tx_count: 0,
time: 0
}
Example usage of this function could look like:
var api = $.fn.blockstrap.modules.api;
api.block('15968', 'btc', function(results)
{
// Your callback
console.log(results)
});
Which should provide the following results:
{
blockchain: "btc",
hash: "00000000201016a83272835468d457d15965d57f57c0da5944dc94ea9389f360",
height: 15968,
prev: "00000000abae6b44fa98526e865a08820f4528eda46cad40445de3690c502ae8",
time: 1243609567,
tx_count: 2
}
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
If return_raw
is set to true, the raw results will be returned through callback
instead of passing through api.results
.
api.map
(blockchain) - back to top
This function is used internally to share API end-points.
api.market
(blockchain, stat, callback, service, return_raw) - back to top
This function is used to return the current market conditions of the defined blockchain
. By default it will return the entire object as follows:
{
btc_to_usd: 0,
daily_txs: 0,
daily_sent: 0,
hash_rate: 0,
btc_discovered: 0,
market_cap: 0
}
If a valid stat
is defined, it will instead return the results of that stat.
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
If return_raw
is set to true, the raw results will be returned through callback
instead of passing through api.results
.
api.request
(url, callback, type, data, blockchain, call, username, password) - back to top
This function is used internally by other functions within this class to route requests and should not be directly used.
api.relay
(hash, blockchain, callback, service, return_raw) - back to top
This function uses the selected API to relay a raw transaction.
The information it is able to map (with the corresponding defaults) includes:
{
blockchain: blockchain,
txid: 'N/A'
}
Example usage of this function could look like:
var api = $.fn.blockstrap.modules.api;
api.relay('__RAW_TX__', 'btc', function(results)
{
// Your callback
console.log(results)
});
Which should provide the following results:
{
blockchain: "btc",
txid: "00000000201016a83272835468d457d15965d57f57c0da5944dc94ea9389f360"
}
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
If return_raw
is set to true, the raw results will be returned through callback
instead of passing through api.results
.
api.results
(defaults, results, blockchain, request, callback) - back to top
This function is used internally by other functions within this class to format requested results and should not be directly used.
api.transaction
(txid, blockchain, callback, service, return_raw) - back to top
This function uses the selected API to get information pertaining to a transaction.
The information it is able to map (with the corresponding defaults) includes:
{
url: '#',
blockchain: blockchain,
txid: 'N/A',
size: 'N/A',
block: 'N/A',
time: 0,
input: 0,
output: 0,
fees: 0
}
Example usage of this function could look like:
var api = $.fn.blockstrap.modules.api;
api.transaction(
'06032a172f88ba823785f87341eab26ee7a2eb2de9d2f105220d6580e3affc16',
'btc', function(results)
{
// Your callback
console.log(results)
}
);
Which should provide the following results:
{
block: 15968,
blockchain: "btc",
fees: 0,
input: 300000000000,
output: 300000000000,
size: 6883,
time: 1243609567,
txid: "06032a172f88ba823785f87341eab26ee7a2eb2de9d2f105220d6580e3affc16",
url: "#transaction?txid=06032a172f88ba823785f87341eab26ee7a2eb2de9d2f105220d6580e3affc16"
}
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
If return_raw
is set to true, the raw results will be returned through callback
instead of passing through api.results
.
api.transactions
(address, blockchain, callback, service, return_raw, count, skip) - back to top
This function uses the selected API to get information pertaining to all the transactions of a single address.
The information it is able to map (with the corresponding defaults) includes:
{
url: '#',
blockchain: blockchain,
txid: 'N/A',
size: 'N/A',
block: 'N/A',
time: 0,
input: 0,
output: 0,
fees: 0
}
Example usage of this function could look like:
var api = $.fn.blockstrap.modules.api;
api.transactions('1121cQLqCsDsLPAkJW5ddTCREZ7Bp4ufrk', 'btc', function(results)
{
// Your callback
console.log(results)
});
Which should provide the following results:
{
block: 15968,
blockchain: "btc",
fees: 0,
input: 300000000000,
output: 300000000000,
size: 6883,
time: 1243609567,
txid: "06032a172f88ba823785f87341eab26ee7a2eb2de9d2f105220d6580e3affc16",
url: "#transaction?txid=06032a172f88ba823785f87341eab26ee7a2eb2de9d2f105220d6580e3affc16"
},
block: 15169,
blockchain: "btc",
fees: 0,
input: 0,
output: 5000000000,
size: 135,
time: 1242853427,
txid: "7f065b4a2a7f5393a5d1b74e8f340ac961d21bb7e8b77a59c9db580eeaf78d03",
url: "#transaction?txid=7f065b4a2a7f5393a5d1b74e8f340ac961d21bb7e8b77a59c9db580eeaf78d03"
}
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
If return_raw
is set to true, the raw results will be returned through callback
instead of passing through api.results
.
Use count
and skip
for pagination, to control how many records are returned or skipped (if support by selected API).
api.unspents
(address, blockchain, callback, confirms, service, return_raw) - back to top
This function uses the selected API to check an address for unspent inputs.
The information it is able to map (with the corresponding defaults) includes:
{
txid: 'N/A',
index: 0,
value: 0,
script: 'N/A'
}
Example usage of this function could look like:
var api = $.fn.blockstrap.modules.api;
api.unspents('1121cQLqCsDsLPAkJW5ddTCREZ7Bp4ufrk', 'btc', function(results)
{
// Your callback
console.log(results)
});
The service
variable allows you to override the default API service for individual calls by providing one listed in configuration.
If return_raw
is set to true, the raw results will be returned through callback
instead of passing through api.results
.
api.url
(action, key, blockchain) - back to top
This function is used internally by other functions within this class to help construct URLs prior to API requests and should not be directly used.
API Mapping - back to top
Blockstrap does not lock you in to a specific API provider. We provide functionality that allows you to map each and every API call we make to a specific API end-point of your choosing. For example, if you wanted to map our wallet to the Hello Block API you would supply the following map:
{
"blockchains": {
"btc": {
"blockchain": "Bitcoin",
"lib": "bitcoin",
"apis": {
"blockstrap": "http://api.blockstrap.com/v0/btc/",
"helloblock": "https://mainnet.helloblock.io/v1/"
},
"fee": 0.0001
},
"multi": {
"private": true,
"apis": {
"blockstrap": "http://api.blockstrap.com/v0/multi/"
}
}
},
"apis": {
"btc": {
"helloblock": {
"functions": {
"to": {
"address": "addresses/",
"addresses": "addresses?addresses=",
"transaction": "transactions/",
"transactions": "addresses/$call/transactions?limit=100",
"block": "blocks/",
"relay": "transactions/",
"relay_param": "rawTxHex",
"unspents": "addresses/$call/unspents?limit=100"
},
"from": {
"address": {
"key": "address",
"address": "address",
"hash": "hash160",
"tx_count": "txsCount",
"received": "confirmedReceivedValue",
"balance": "balance"
},
"addresses": {
"key": "addresses",
"delimiter": "&addresses=",
"address": "address",
"hash": "hash160",
"tx_count": "txsCount",
"received": "confirmedReceivedValue",
"balance": "balance"
},
"transaction": {
"key": "transaction",
"txid": "txHash",
"size": "size",
"block": "blockHeight",
"time": "blockTime",
"input": "totalInputsValue",
"output": "totalOutputsValue",
"value": "estimatedTxValue",
"fees": "fees"
},
"transactions": {
"key": "transactions",
"txid": "txHash",
"size": "size",
"block": "blockHeight",
"time": "blockTime",
"input": "totalInputsValue",
"inputs": "inputs",
"output": "totalOutputsValue",
"outputs": "outputs",
"value": "estimatedTxValue",
"fees": "fees"
},
"block": {
"key": "block",
"height": "blockHeight",
"hash": "blockHash",
"prev": "prevBlockHash",
"tx_count": "txsCount",
"time": "blockTime"
},
"relay": {
"txid": "txHash",
"inner": "transaction"
},
"unspents": {
"key": "unspents",
"confirmations": "confirmations",
"txid": "txHash",
"index": "index",
"value": "value",
"script": "scriptPubKey"
}
}
}
}
}
}
}
As you can see from line 13 above it is also possible to include blockchains that can be used privately, and DO NOT show up in drop-down selections.
Please note the we currently support the following APIs (from default configuration):
- Blockchains.io (6 Chains): select
blockstrap
as service choice - SoChain.io (6 Chains): select
sochain
as service choice - Blockr.io (4 Chains): select
blockr
as service choice - HelloBlock.io (BTC only): select
helloblock
as service choice
- Related Articles
- Back to Modules
- Accounts
- API
- Buttons
- Contacts
- Blockchains
- Data
- Filters
- Forms
- Security
- Styles
- Templates
- Table of Contents