npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tealcoin-explorer-api

v1.1.2

Published

Module to query blockchain apis for Tealcoin.

Downloads

7

Readme

Blockchain APIs for Tealcoin Insight Explorer

NPM Package Build Status Coverage Status

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 = require('tealcoin-explorer-api');
var insight = new explorers.Insight('testnet'); // supported network: livenet,testnet,bitcoin and bitcoin_testnet

insight.getUtxos('tKpkm7WGLWdEaKUU9UCvyb917jE2nxLDCB', function(err, utxos) {
  if (err) {
    // Handle errors...
  } else {
    // Maybe use the UTXOs to create a transaction
  }
});

Get Address Info

var explorers = require('tealcoin-explorer-api');
var insight = new explorers.Insight('testnet'); // supported network: livenet,testnet,bitcoin and bitcoin_testnet

insight.address('fmLYw2BuhCQ9T1pyJZkYXi8pCq7bAvfN1a', function(err, addrinfo) {
  if (err) {
    console.log('e:'+err);
  } else {
    console.log(addrinfo);
  }
});

Get Transaction

var explorers = require('tealcoin-explorer-api');
var insight = new explorers.Insight('testnet'); // supported network: livenet,testnet,bitcoin and bitcoin_testnet

insight.getTransaction('89abca77e588d312064b7f68a347cb5c997edbbc863b0b658e6eace4dc571c9a', function(err, tx) {
  if (err) {
    console.log(err);
  } else {
    console.log(tx);
  }
});

Broadcasting a Transaction

var explorers = require('tealcoin-explorer-api');
var insight = new explorers.Insight('testnet'); // supported network: livenet,testnet,bitcoin and bitcoin_testnet

var insight = new Insight('testnet');
insight.broadcast(tx, function(err, returnedTxId) {
  if (err) {
    // Handle errors...
  } else {
    // Mark the transaction as broadcasted
  }
});

Create & send a Transaction

var explorers = require('tealcoin-explorer-api');
var useNetwork = 'testnet'; // supported network: livenet, testnet, bitcoin, bitcoin_testnet
var insight = new explorers.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 = addrList[5];
var toAddr = addrList[0];

if(explorers.bip38.verify(fromAddr.privatekey)) {
	if(typeof fromAddr.bip38Passphrase !== 'undefined') {
		fromAddr.privatekey = explorers.bip38.decrypt(fromAddr.privatekey, fromAddr.bip38Passphrase, function(status) {
			console.log(status);
		}).privateKey;
	} else {
		console.log('Error: No bip38Passphrase...');
		return;
	}
}

var err = explorers.litecore_tealcoin_lib.PrivateKey.getValidationError(fromAddr.privatekey,useNetwork);
if(err) {
	console.log(err);
	return;
}

var privateKey = new explorers.litecore_tealcoin_lib.PrivateKey(fromAddr.privatekey,useNetwork);
// console.log(privateKey.toWIF());
// console.log(privateKey.toAddress().toString());
if(privateKey.toAddress().toString() !== fromAddr.addr) {
	console.log('Error: Private Key not match!');
	return;
}

insight.getUtxos(fromAddr.addr, function(err, utxos) { // tealcoin testnet
  if (err) {
    console.log(err);
  } else {
	//console.log(utxos);
	var transaction = new explorers.litecore_tealcoin_lib.Transaction()
		.from(utxos)          // Feed information about what unspent outputs one can use
		.to(toAddr.addr, 100000000)  // Add an output with the given amount of satoshis
		.fee(fee)
		.change(fromAddr.addr)      // Sets up a change address where the rest of the funds will go
		.sign(privateKey)     // Signs all the inputs it can

	//console.log(transaction);
	var txSerialized = transaction.serialize(true);
	//console.log(txSerialized);
	//console.log(transaction.getChangeOutput());
	insight.broadcast(txSerialized, function(err, returnedTxId) {
	  if (err) {
		console.log(err);
	  } else {
		console.log("Success with txid: " + returnedTxId);
	  }
	});
  }
});

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 broserify
npm install --global uglify-js
npm install tealcoin-explorer-api

cd tealcoin-explorer-api
browserify --require ./index.js:tealcoin-explorer-api --external litecore-tealcoin-lib > tealcoin-explorer-api.js
uglifyjs --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.