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

the-crypto-gate

v1.0.9

Published

The-crypto-gate: Blockchain API Library

Downloads

3

Readme

TheCryptoGate.com Blockchain API (BTC, ...)

https://www.npmjs.com/package/the-crypto-gate

npm version



Install:

npm i the-crypto-gate --save

Require && set-up apiKey:

const theCryptoGate = require('the-crypto-gate');

const TCG = new theCryptoGate({
  apiKey: '<my-key>',
});

Info: TheCryptoGate library is API-Ready

// express
app.get('/my-custom/api/address/get-balance/:address', async(req, res)=>{

  // ...

  const balanceRes = await TCG.getAddressBalance( address ));

  res.header('Content-Type', 'application/json');
  res.json( balanceRes );

  // ...

});
{
  "code": 200,
  "msg": "OK",
  "data": {
    "balance": 0.00137764,
    "confirmed": 0.00137764,
    "unconfirmed": 0
  }
}

Method: getAddressBalance

Logo Success


const balanceRes = await TCG.getAddressBalance( '15FZLWefShJjwAuDcGgMAhUXXHMgXPyjGb' ));

{
  "code": 200,
  "msg": "OK",
  "data": {
    "balance": 0.00137764,
    "confirmed": 0.00137764,
    "unconfirmed": 0
  }
}

Logo Error or Warning


const balanceRes = await TCG.getAddressBalance( 'WRONG-ADDRESS' ));

{
  "code": <int>, // !200
  "msg": "Description ...",
  "data": {}
}

Method: getAddressUnspent

Get all unspent transactions (UTXO) from Address

WARNING:
  Only for advanced users. You can lose all your Crypto

Logo Success


const res = await TCG.getAddressUnspent( '15FZLWefShJjwAuDcGgMAhUXXHMgXPyjGb' ));

{
  "code": 200,
  "msg": "OK",
  "data": [
    {
      "tx_hash": "c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935",
      "tx_pos": 1,
      "height": 575219,
      "value": 137764, // amount ins Sat.
      "balance": 0.00137764
    }
  ]
}

Logo Error or Warning

const res = await TCG.getAddressUnspent( 'WRONG-ADDRESS' ));

{
  "code": <int>, // !200
  "msg": "Description ...",
  "data": {}
}

Method: pushRawTransaction

Broadcast your created Transaction into the Blockchain

Logo Success


const res = await TCG.pushRawTransaction( '02000000016d97be4cf0fafccb85b37b ....' ));

{
  "code": 200,
  "msg": "OK",
  "data": {
    // Pushed transaction hash
    "hash": "c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935",
  }
}

Logo Error or Warning


const res = await TCG.pushRawTransaction( 'EXISTING TRANSACTION-HASH' ));

{
  "code": <code>, // !200
  "msg": "Transaction already in block chain",
  "data": {}
}

Method: getTransactionByHash

Fetch transaction from Blockchain by hash,

Logo Success


const res = await TCG.getTransactionByHash( 'c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935' ));

{
  "code": 200,
  "msg": "OK",
  "data": {
    "transaction": {
      "txid": "c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935",
      "hash": "c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935",
      "version": 2,
      "size": 226,
      "vsize": 226,
      "weight": 904,
      "locktime": 0,
      "vin": [
        ...
      ],
      ...
    }
  }
}

Logo Error or Warning


const res = await TCG.getTransactionByHash( 'WRONG-TRANSACTION-HASH' ));

{
  "code": 400,
  "msg": "Not valid Transaction Hash",
  "data": {}
}
{
  "code": 500,
  "msg": "No such mempool or blockchain transaction. Use gettransaction for wallet transactions",
  "data": {}
}

Method: getBlockByID

Logo Success


const res = await TCG.getBlockByID( 575217 );

{
  "code": 200,
  "msg": "OK",
  "data": {
    ...
  }
}

Logo Error or Warning

{
  "code": <int>, // !200
  "msg": "Description ...",
  "data": {}
}

Method: estimateSmartFee

Get the best transaction fee for the moment.
Within next blocks: Min 2, Max Inf.

The lower <withInNextBlocks>, the heigher <tx-fee> will be

Logo Success

const res = await TCG.estimateSmartFee( <With in next blocks> );

{
  "code": 200,
  "msg": "OK",
  "data": {
    "perKiloByte": 0.00081461,
    "perByte": 7.95518e-7,
    "avgTxBytes": 195,
    "avgTxCoastBtc": 0.00015513,
    "withInNextBlocks": 2
  }
}

Logo Error or Warning

{
  "code": <int>, // !200
  "msg": "Description ...",
  "data": {}
}

Method: getKeyPair

Create new (random) CryptoPair => Public && Private key

WARNING: 
  You must store it in your own database or you will lose all your Crypto 

Logo Success

const KeyPair = await TCG.getKeyPair();

{
  "code": 200,
  "msg": "OK",
  "data": {
    "symbol": "BTC",
    "sec_key": "L1xx81HHJhNFJdmU5soiL1SbYzmZ6Anu8GdtiUE7GDifzViy6rwj",
    "pub_key": "1MD1LWPp3uj53ithDs9ygMi2tFkB3vt27V",
    "encrypted": false
  }
}

Logo Error or Warning

{
  "code": <int>, // !200
  "msg": "Description ...",
  "data": {}
}

Info: Create && Broadcast Transaction

options (optional):

  • allowDust: Allow send vary small amount (dust)

  • feeType: Try send within next blocks. Can be any of ( 2,3,4,5,6 ). Default: 3

  • tryToFitTxFee: if amount plus Tx-Fee is less than total balance, it will try reduce dest. amount to fit transaction cost in transaction itself. NOTE: Works only if dest object contains 1 dest. address

Send to many ...
const sendOutToMany = [
  {address: '1GPwAmZFSZ3vFy1mfJqpDcNqrmXZjMxYV', amount: 0.034},
  {address: '1mfJqpDcNqrmXZjMxYV1GPwAmZFSZ3vFy', amount: 0.012},
  {address: '1mZFSZ3vFyfJqpDcNqrmXZjMxYVm1GPwA', amount: 0.787},
];
Send to one ...
const sendOutToOne = [
  {address: '1GPwAmZFSZ3vFy1mfJqpDcNqrmXZjMxYV', amount: (+aliceBalanceRes.data.balance) },
];
const aliceBalanceRes = await TCG.getAddressBalance( Keys.alice.pub_key );

// Optianal: options
const options = {
  allowDust: false,
  feeType: 3,
  tryToFitTxFee: true,
};

const sendOutToOne = [
  {address: '1GPwAmZFSZ3vFy1mfJqpDcNqrmXZjMxYV', amount: (+aliceBalanceRes.data.balance) },
];

const TxRes = await TCG.createRawTransaction( Keys.alice.sec_key, sendOutToOne, options );

{
  code: 200, 
  msg: 'Transaction is ready to be broadcasted',
  data: {
    raw_tx: 'abcd234569cdef......',
  }
}

if( TxRes.code !== 200 ){
  console.error( TxRes.msg );
  return;
}
Broadcast transaction into Blockchain
const pushRawTxRes = await TCG.pushRawTransaction( TxRes.data.raw_tx );

if( pushRawTxRes.code !== 200 ){
  console.error( TxRes.msg );
  return;
}

// Success
console.log( TxRes.data.hash );