Please note that it is BitcoinJS-Lib that makes most of these functions possible.
The framework currently supports the following blockchains (and their corrresponding testnets):
Blockchain | Homepage | Active Chain Code | Test-Net Code |
---|---|---|---|
Bitcoin | http://bitcoin.org | btc | btct |
Litecoin | http://litecoin.org | ltc | ltct |
Dogecoin | http://dogecoin.com | doge | doget |
Dash | http://dashpay.io | dash | dasht |
The Blockchains Module features the following functions:
$.fn.blockstrap.blockchains.check
(address)$.fn.blockstrap.blockchains.decode
(script_pub_key)$.fn.blockstrap.blockchains.empty
(private_key, to_address, chain, callback))$.fn.blockstrap.blockchains.key
(code)$.fn.blockstrap.blockchains.keys
(secret, blockchain, number_of_keys, indexes, raw)$.fn.blockstrap.blockchains.raw
(return_to, privkey, inputs, outputs, this_fee, amount_to_send, data, sign_tx, script)$.fn.blockstrap.blockchains.send
(to, amount, from, keys, callback, blockchain, data, fee)$.fn.blockstrap.blockchains.supported
(blockchain)$.fn.blockstrap.blockchains.validate
(address)$.fn.blockstrap.blockchains.which
(address)
blockchains.check
(address) - back to top
This function will return the first character of a validated address
.
blockchains.decode
(script_pub_key) - back to top
This function decodes the script_pub_key
from a valid OP_Return outgoing transaction into a readable text string.
blockchains.empty
(private_key, to_address, chain, callback) - back to top
This function checks the balance belonging to the provided private_key
and then sends all of the funds (minus the default network fee) to the required to_address
. The chain
variable is also required and the callback
function is initiated if provided.
blockchains.key
(code) - back to top
This function will return the BitcoinJS-Lib
formatted blockchain code if provided with the Blockstrap blockchain code
.
For example, btc
becomes bitcoin
and doget
becomes dogecointestnet
.
blockchains.keys
(secret, blockchain, number_of_keys, indexes, raw) - back to top
This function takes the secret
seed and blockchain
and returns an object containing the public and private keys generated from the secret
.
Please note that by default, Blockstrap DOES NOT store the private keys anywhere.
Multiple keys or specific HD derivative keys can be generated using the number_of_keys
and indexes
variables, where as the raw
variable can be used to also return the complete unfiltered keys and attach them to the returned object within a raw field.
blockchains.raw
(return_to, privkey, inputs, outputs, this_fee, amount_to_send, data, sign_tx, script) - back to top
This function returns a raw transaction Hex-string that can then be relayed.
It already requires you to have the inputs
and outputs
properly formed. The return_to
variable is the change address that should be used to send-back the left-over inputs. You need to set the amount_to_send
(as an integer) as well as the preferred mining fee by using this_fee
.
If you the raw transaction return to be signed, you need to provide the appropriate privkey
for the inputs
(currently assumes all inputs from same address). You can leave this false or null but should also set the sign_tx
variable to false
.
The data
variable is used to store additional information within the op_return field of the transaction and must conform to the relevant $.fn.settings.blockchains[chain].op_limit
.
The script
variable is used for multisignature transactions.
blockchains.send
(to, amount, from, keys, callback, blockchain, data, fee) - back to top
This function is used to construct a raw transaction and then relay it. Basic settings such as who to send the coins to with to
address, or how much to send with the amount
and blockchain
are clear enough. The from
will be used as the returning change address. The keys
should be a key object as returned by blockchains.keys
, which contains both the public and private keys. Before proceeding, we first check locally to see if the account belongs to this user and it has the necessary balance required to perform the transaction. If it does, the public key is used in reference to an api.unspents
call, the results from which are then used to construct the necessary available inputs. We then call blockchains.raw
and use the returned object as the required variable in an api.relay
call.
In order to attach aribitary data to the transaction via an OP_Return, simply add a data
variable, where custom transaction fees canalso be set using the fee
variable, which if left empty will then use the default fee structure instead.
blockchains.supported
(blockchain) - back to top
This function will return a boolean value confirming whether or not the selected blockchain
has API support or not.
blockchains.validate
(address) - back to top
This function returns a boolean and is used on conjunction with blockchains.check
to validate an address
.
blockchains.which
(address) - back to top
This function will return the blockchain code (or false) for a given address
.
However, please note that this IS NOT ACCURATE as it currently uses a very hacky method. Sorry about that.