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 🙏

© 2026 – Pkg Stats / Ryan Hefner

blockchain-gateway

v0.2.0

Published

Bitcoin and Ethereum transaction management

Readme

Blockchain Gateway

npm version

Usage

Library

npm install blockchain-gateway

Sending Bitcoin transactions is pretty easy. You don't need to deal with UTXOs and computing fees:

const { BitcoinNetwork } = require('blockchain-gateway');

const { BLOCKCYPHER_TOKEN, PRIVATE_KEY } = process.env;

// Connect to Bitcoin testnet3 with your BlockCypher Access Token
const bitcoin = new BitcoinNetwork({
  networkType: 'testnet',
  accessToken: BLOCKCYPHER_TOKEN,
});

(async () => {
  // Connect to your Bitcoin account with your compressed WIF private key
  await bitcoin.connect(PRIVATE_KEY);

  // Generate a random Bitcoin account
  const { address } = ethereum.generateKeypair();

  // Try to send 0.5 tBTC from your account to the generated account
  try {
    // Compute fees and select suitable transaction outputs
    const tx = await bitcoin.createTransaction(
      bitcoin.defaultAccount,
      address,
      0.5,
    );

    // Sign the transaction inputs
    const { rawTx, txHash } = await bitcoin.signTransaction(tx);
    console.log('Your transaction was successfully signed. txHash:', txHash);

    // Broadcast the raw transaction
    await bitcoin.broadcastTransaction(rawTx);

    // Check if the transaction has at least 1 confirmation
    await bitcoin.getTxStatus(txHash);
    console.log('Your transaction was successfully mined!', bitcoin.getTxLink(txHash));
  } catch (e) {
    console.log('Something went wrong!', e.message);
  }
})();

Ethereum transactions are sent in the same way:

import { EthereumNetwork } from 'blockchain-gateway';
// or import EthereumNetwork from 'blockchain-gateway/EthereumNetwork';

const { INFURA_PROJECT_ID, PRIVATE_KEY } = process.env;

// Connect to Ethereum mainnet with your Infura Project Id
const ethereum = new EthereumNetwork({
  networkType: 'mainnet',
  accessToken: INFURA_PROJECT_ID,
});

(async () => {
  // Connect to your Ethereum account with your private key
  await ethereum.connect(PRIVATE_KEY);

  // Generate a random Ethereum account
  const { address } = ethereum.generateKeypair();

  // Try to send 0.5 ETH from your account to the generated account
  try {
    // Compute fees and fetch the nonce
    const tx = await ethereum.createTransaction(
      ethereum.defaultAccount,
      address,
      0.5,
    );

    // Sign the transaction
    const { rawTx, txHash } = await ethereum.signTransaction(tx);
    console.log('Your transaction was successfully signed. txHash:', txHash);

    // Broadcast the raw transaction
    await ethereum.broadcastTransaction(rawTx);

    // Check if the transaction was mined
    await ethereum.getTxStatus(txHash);
    console.log('Your transaction was successfully mined!', ethereum.getTxLink(txHash));
  } catch (e) {
    console.log('Something went wrong!', e.message);
  }
})();

Also, signing Ethereum transactions using MetaMask is also supported. You don't have to pass the accessToken to the EthereumNetwork constructor if you are using a browser with installed MetaMask.

CLI

# Install blockchain-gateway globally
npm install -g blockchain-gateway

# Run in REPL CLI mode (https://nodejs.org/api/repl.html#repl_commands_and_special_keys)
blockchain-gateway

# Example of CLI usage
> const ethereum = new EthereumNetwork({ accessToken: 'YOUR_INFURA_PROJECT_ID' })
> ethereum.generateKeypair()
{ address: '0xa71F7F4611BA0c6E836671210a97DCD2DCcF1738',
  privateKey: '0x1c98fa0487eba75ea5819850759fbba0c3ff79a811b9bdcb541a36b0fc2dd286' }
> await ethereum.getBalance('0xa71F7F4611BA0c6E836671210a97DCD2DCcF1738')
'0'
> await ethereum.connect('0x1c98fa0487eba75ea5819850759fbba0c3ff79a811b9bdcb541a36b0fc2dd286')
[ '0xa71F7F4611BA0c6E836671210a97DCD2DCcF1738' ]
> await ethereum.createTransaction('0xa71F7F4611BA0c6E836671210a97DCD2DCcF1738', '0xa71F7F4611BA0c6E836671210a97DCD2DCcF1738', '0.5')
Uncaught TransactionError: Insufficient Funds
  at Proxy.createTransaction (/Users/user/.nvm/versions/node/v12.18.3/lib/node_modules/blockchain-gateway/EthereumNetwork.js:216:13)
  at processTicksAndRejections (internal/process/task_queues.js:97:5)

Testing and Development

# Install project
git clone https://github.com/scifier/blockchain-gateway.git
cd blockchain-gateway
npm install

# Prepare your testing environment
echo "BLOCKCYPHER_TOKEN=$YOUR_BLOCKCYPHER_TOKEN" > .env
echo "INFURA_TOKEN=$YOUR_INFURA_PROJECT_ID" >> .env
echo "NETWORK_TYPE=mainnet" >> .env
# Variables required by test/bitcoin-transactions
echo "BTC_PRIVATE_KEY=$COMPRESSED_WIF_PRIVATE_KEY" >> .env
echo "BTC_ADDRESS=$BITCOIN_RECIPIENT_ADDRESS" >> .env
echo "BTC_AMOUNT=$BTC_AMOUNT_TO_SEND" >> .env
# Variables required by test/ethereum-transactions
echo "ETH_PRIVATE_KEY=$ETHEREUM_PRIVATE_KEY" >> .env
echo "ETH_ADDRESS=$ETHEREUM_RECIPIENT_ADDRESS" >> .env
echo "ETH_AMOUNT=$ETH_AMOUNT_TO_SEND" >> .env
# KMS variables are required by test/wallet-pkey-management
echo "KMS_KEY_ARN=$KMS_KEY_ARN" >> .env
echo "KMS_ACCESS_KEY=$KMS_ACCESS_KEY" >> .env
echo "KMS_SECRET_KEY=$KMS_SECRET_KEY" >> .env
echo "KMS_ENCRYPTION_KEY=$KMS_ENCRYPTION_KEY" >> .env
echo "KMS_REGION=$KMS_REGION" >> .env

# Run tests
npm run test

# Run specific test
node test/bitcoin-transactions
node test/ethereum-transactions
node test/wallet-pkey-management

# Also you can run blockchain-gateway in CLI mode
npm run start

Authors

  • Niţa Radu - Initial work - scifier

License

This project is licensed under the MIT License - see the LICENSE file for details