Blockchain APIs for Tealcoin Insight Explorer
A module for Tealcoin Insight Explorer that implements HTTP requests to different Web APIs to query the state of the blockchain.
Getting started
Be careful! When using this module, the information retrieved from remote servers may be compromised and not reflect the actual state of the blockchain.
npm install tealcoin-explorer-api
This API support for both tealcoin and bitcoin blockchain network. You can query both tealcoin and bitcoin blockchain data. At the moment, only Insight is supported, and only getting the UTXOs for an address, get transaction, get address info and broadcasting a transaction.
Get UTXOs
var explorers = ;var insight = 'testnet'; // supported network: livenet,testnet,bitcoin and bitcoin_testnet insight;
Get Address Info
var explorers = ;var insight = 'testnet'; // supported network: livenet,testnet,bitcoin and bitcoin_testnet insight;
Get Transaction
var explorers = ;var insight = 'testnet'; // supported network: livenet,testnet,bitcoin and bitcoin_testnet insight;
Broadcasting a Transaction
var explorers = ;var insight = 'testnet'; // supported network: livenet,testnet,bitcoin and bitcoin_testnet var insight = 'testnet';insight;
Create & send a Transaction
var explorers = ;var useNetwork = 'testnet'; // supported network: livenet, testnet, bitcoin, bitcoin_testnetvar insight = useNetwork; var addrList = 'addr':'tCFP3aT27sweFAUxUnnGKCM5Fy2scCYhzj' 'privatekey':'b62G44H6uJm72ur2rT3TkQ9LJaZH2KFf1XeRDK1Mu9TRKn6PvaVm' 'addr':'tLHcDJrA1xE1p9mAf2DKaKQ74MiAkHbKTX' 'privatekey':'b4iMFnSJ2FaF9i7Zzg2GJQcbUV37pLgQkQqZpeUjc2juXzdagWXE' 'addr':'t9gaehJdDQFG8hBh9UYdtsgG46U7aQ5Xx4' 'privatekey':'b4vgTGAxc36yrVZcWmtgX5ugQwfcon4TmB2BrVmQy2CqxP7EhXMF' 'addr':'tMxzJ8kUkFUJPssgC2y7XrFCavaujKWvTL' 'privatekey':'8jdMiNDh4XrHGncGwJnFp2SKPSoj8x15QwctpRpEuS12oxBKRoH' 'addr':'tJXgQZSpm4U87dnPxsaxyL1NSxAaBz2ivE' 'privatekey':'b9JJZd93vK9qriasqSEmze756nvazmrhtoLgLPzyS1rf77oHAYQu' 'addr':'tS7SqUMfhmkwKHeu8qr17CKXQE5wpcgHm1' 'privatekey':'6PfRigXELtB4H52gHnssPLM9BoCquZN725MvKamFb7Hv1mXnFjyX2L84Ei' // bip38 encrypted 'bip38Passphrase': 'testingtesting' ; var fee = 5000000;var fromAddr = addrList5;var toAddr = addrList0; ifexplorersbip38 iftypeof fromAddrbip38Passphrase !== 'undefined' fromAddrprivatekey = explorersbip38privateKey; else console; return; var err = explorerslitecore_tealcoin_libPrivateKey;iferr console; return; var privateKey = fromAddrprivatekeyuseNetwork;// console.log(privateKey.toWIF());// console.log(privateKey.toAddress().toString());ifprivateKey !== fromAddraddr console; return; insight;
Some possible error: Error: Cannot find module 'safe-buffer'
, try to solve with:
cd tealcoin-explorer-api/node_modules/bip38
npm install safe-buffer
Building the Browser Bundle
To build a tealcoin-explorer-api full bundle for the browser:
npm install --global broserifynpm install --global uglify-jsnpm install tealcoin-explorer-api cd tealcoin-explorer-apibrowserify --require ./index.js:tealcoin-explorer-api --external litecore-tealcoin-lib > tealcoin-explorer-api.jsuglifyjs --compress --mangle --rename tealcoin-explorer-api.js > tealcoin-explorer-api.min.js
This will generate files named tealcoin-explorer-api.js
and tealcoin-explorer-api.min.js
.
Use it in browser example: Require bundled litecore-tealcoin-lib, see Tealcoin Litecore Lib for bundle instructions.
<html>
<body>
</body>
<script src='./litecore-tealcoin-lib.min.js'></script>
<script src='./tealcoin-explorer-api.min.js'></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var bitcore = require('litecore-tealcoin-lib');
var api = require('tealcoin-explorer-api');
// generate a private & address example
var privateKey = new bitcore.PrivateKey('testnet');
var wif = privateKey.toWIF();
var address = privateKey.toAddress();
console.log(privateKey.toString());
console.log(wif);
console.log(address.toString());
// get UTXOs
var insight = new api.Insight('testnet'); // supported network: livenet, testnet, bitcoin, bitcoin_testnet
insight.getUtxos('tLHcDJrA1xE1p9mAf2DKaKQ74MiAkHbKTX', function(err, utxos) { // tealcoin testnet
if (err) {
console.log(err);
} else {
console.log(utxos);
}
});
}, false);
</script>
</html>
Contributing
See CONTRIBUTING.md on the main bitcore repo for information about how to contribute.
License
Code released under the MIT license.
Copyright 2013-2015 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc.