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:


API Functions & Variables

The API Module features the following functions:

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.

- back to top


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.

- back to top


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.

- back to top


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.

- back to top


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.

- back to top


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.

- back to top


api.map(blockchain) - back to top

This function is used internally to share API end-points.

- back to top


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.

- back to top


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.

- back to top


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.

- back to top


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.

- back to top


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.

- back to top


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).

- back to top


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.

- back to top


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.

- back to top


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"
                        }
                    }
                }
            }
        }
    }
}

- back to top

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):


  1. Related Articles
  2. Back to Modules
  3. Accounts
  4. API
  5. Buttons
  6. Contacts
  7. Blockchains
  8. Data
  9. Filters
  10. Forms
  11. Security
  12. Styles
  13. Templates
  14. Table of Contents