New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bitcoin-propagator

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcoin-propagator

Bitcoin transaction propagator and blockchain access

  • 0.2.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bitcoin-propagator

Access multiple bitcoin remote nodes APIs with one single call.

The Bitcoin Propagator implements an interface for several APIs and join all in the Propagator.

Propagator

Each method call, on a Propagator instance, makes a request on an API for the result, and if any request error occurr, it automatically tries the next API, and the next.

The multiple calls, when needed, are hidden from the user, that only receives a Promise that is resolved when a request is successful, of rejected if any are.

Network support

The Propagator has support for bitcoin testnet and mainnet.

Instantiating

The network must be given to the Propagator constructor.

const Propagator = require('bitcoin-propagator');
const propagator = new Propagator('testnet');

There are two options, timeout and attempts.

  • timeout refers to the request timeout.
  • ettempts refers to the number of attempts a method will try when it receives erros from all the APIS.

Methods

Every method returns promises. Below, return value will refer to the argument of the function for resolved promise.

Get unspent transactions

This method requires the address from where the unspent transactions are associated. The return value is the array of unspent transactions.

propagator.getUnspent(address)
  .then(unspent => {
    // ...
  })
  .catch(error => {
    // Handle error
  });

Broadcast a transaction

This method broadcast a transaction that must be passed serialized as argument. The return value is the transaction ID.

propagator.broadcast(transaction)
  .then(transactionId => {
    // ...
  })
  .catch(error => {
    // Handle error
  });

Get data from a transaction

This method returns the transaction data from the transaction with ID passed as argument.

propagator.getTransaction(transactionId)
  .then(transaction => {
    // ...
  })
  .catch(error => {
    // Handle error
  });

The return value has 3 attributes:

  • data: The data stored in the OP_RETURN.
  • time: The time of the transaction.
  • confirmations: The number of confirmations the block has received.
{
  data: <string>,
  time: <Date>,
  confirmations: <int>
}

Example

const Propagator = require('bitcoin-propagator');

const propagator = new Propagator('testnet');
const address = ... // A valid address

// Get the unspent transactions from the address
propagator.getUnspent(address)
  // Received an array of unspent transactions
  .then(unspent => {
    // Create a transaction with the unspent transactions data
    const transaction = ...
    // Broadcast the serialized transaction
    return propagator.broadcast(transaction);
  })
  // Received the transaction ID
  .then(transactionId => {
    // Get the transaction data with the transactionId
    return propagator.getTransaction(transactionId);
  })
  // Received the transaction data
  .then(data => {
    // Do something with the transaction data
  })
  // Received error
  .catch(error => {
    // Handle error
  });

Keywords

FAQs

Package last updated on 28 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc