Skip to content

dylanparker/blockr-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

BlockrJS

About

A simple JavaScript wrapper for the Blockr.io v1 API

Retrieve coin, address, transaction and blockchain info for the following cryptocoins: Bitcoin, Bitcoin-Testnet, Litecoin, Digitalcoin, Quark, Peercoin and Megacoin.

Requirements

No JavaScript library requirements.

Note that this JS was originally written to be used within an Apache Cordova mobile application. If used directly in a browser it will surely fail while trying to make a cross-domain request to blockr.io


# Documentation

Coin Selection and HTTPS

The following coins are supported by this API: Bitcoin, Bitcoin-Testnet, Litecoin, Digitalcoin, Quark, Peercoin and Megacoin

Select the coin to query for by specifying the associated subdomain. The default is bitcoin (btc).

Blockr.setCoinSubdomain("btc");	// Bitcoin
Blockr.setCoinSubdomain("tbtc"); // Bitcoin (Testnet)
Blockr.setCoinSubdomain("ltc"); // litecoin
Blockr.setCoinSubdomain("dgc"); // Digitalcoin
Blockr.setCoinSubdomain("qrk"); // Quark
Blockr.setCoinSubdomain("ppc"); // Peercoin
Blockr.setCoinSubdomain("mec"); // Megacoin

By default all calls are made over HTTP. To use HTTPS, call setHttpsEnabled(bool).

Blockr.setHttpsEnabled(true);

## Blockr API Methods

All Blockr API calls utilize a single callback function to handle the returned data. The data is returned as an object in the JSend format. The JSend status field will indicate whether an error occurred. Read more about the JSend format here: http://labs.omniti.com/labs/jsend


### Coin Methods

Blockr.coin.info( callback )

Retrieve information about the currently selected coin and return that data via the callback function. The returned object will include info like: coin name, abbreviation, volume, last block number, next difficulty and some market prices.

Blockr.coin.info(function(o) {
	console.log( o.data.coin.name );	  // console displays "Bitcoin"
});

Live Example

See the Blockr API docs for specifics of the returned data.


### Exchange Rate Methods

####Blockr.exchangerate.current( callback )

Retrieve the current exchange rate used by Blockr.io and return that data via the callback function. All exchange rates are based on the USD. See the Blockr API docs for info on how to work with these numbers.

Blockr.exchangerate.current(function(o) {
	console.log( o.data[0].rates.CAD );	  // console displays "1.093001"
});

Live Example


Block Methods

Retrieve data about a specific block or set of blocks.

With each Block-related API call, the block parameter can be one of:


**`Blockr.block.info( block, callback )`**

Retrieve block general info.

Blockr.block.info(block, function(o) {
	console.log( o.data.confirmations );	  // console displays "312"
});

**`Blockr.block.txs( block, callback )`**

Retrieve transactions within a block.

Blockr.block.txs(block, function(o) {
	console.log( o.data.txs[0].fee );	  // console displays "0.0001"
});

**`Blockr.block.raw( block, callback )`**

Returns raw block data in the bitcoin format.

Blockr.block.raw(block, function(o) {
	console.log( o.data.tx[18] );	  // console displays "2b0239151…e07c1bd71b60"
});

See the Blockr API docs for specifics of the returned data.


Transaction Methods

Retrieve data about a specific transaction or set of transactions.

In each transaction-related method, the tx parameter is a hex transaction hash like: 60c1f1a3160042152114e2bba45600a5045711c3a8a458016248acec59653471

You can request data for multiple transactions by including multiple transaction hashes separated by commas.


**`Blockr.tx.info( tx, callback )`**

Returns transaction data for unconfirmed and normal blockchain transactions.

Blockr.tx.info(tx, function(o) {
	console.log( o.data.block );	  // console displays "233958"
});

**`Blockr.tx.raw( tx, callback )`**

Returns raw transaction data in the bitcoin format.

Blockr.tx.raw(tx, function(o) {
	console.log( o.data.tx.time );	  // console displays "1367355521"
});

See the Blockr API docs for specifics of the returned data.


Address Methods

Retrieve data about a specific address or set of addresses.

In each address-related method, the address parameter is a public address like: 198aMn6ZYAczwrE5NvNTUMyJ5qkfy4g3Hi

You can request data for multiple addresses by including multiple public addresses separated by commas.


**`Blockr.address.info( address, callback, opt_confs )`**

Retrieves general info about a specific public address.

The opt_confs parameter will filter any transactions with less than opt_confs confirmations. The maximum value for opt_confs is 15.

Blockr.address.info(address, function(o) {
	console.log( o.data.totalreceived );	  // console displays "123.001337"
}, confirmations);

**`Blockr.address.balance( address, callback, opt_confs )`**

Retrieves the balance for a specific public address.

The opt_confs parameter will filter any transactions with less than opt_confs confirmations. The maximum value for opt_confs is 15.

Blockr.address.balance(address, function(o) {
	console.log( o.data.balance );	  // console displays "123.001337"
}, confirmations);

**`Blockr.address.txs( address, callback )`**

Retrieves the most recent transactions (up to 200) for a specific public address.

Blockr.address.txs(address, function(o) {
	console.log( o.data.txs[3].amount );	  // console displays "0.5"
});

**`Blockr.address.unspent( address, callback )`**

Retrieves the unspent transactions for a specific public address.

Blockr.address.unspent(address, function(o) {
	console.log( o.data.unspent[0].confirmations );	  // console displays "2827"
});

**`Blockr.address.unconfirmed( address, callback )`**

Retrieves the unconfirmed transactions associated with a specific public address.

Blockr.address.unconfirmed(address, function(o) {
	console.log( o.data.unconfirmed[3].amount );	  // console displays "0.04"
});

See the Blockr API docs for specifics of the returned data.

About

A javascript wrapper for the Blockr.io v1 API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published