Code Monkey home page Code Monkey logo

electrs-client-node's Introduction

electrs-client-node

A javascript client for communicating with Blockstream's electrs HTTP api

import { Client } from "electrs-client-node";

const client = new Client({
  ELECTRUM_SERVER_URL: "http://localhost:30000",
});

Transactions

// GET a transaction
const tx = await client.transaction.get(txId);

// GET transaction status
const txStatus = await client.transaction.status(txId);

// GET transaction  hex
const hex = await client.transaction.hex(txId);

// GET transaction raw
const raw = await client.transaction.raw(txId);

// GET merkle inclusion proof(using bitcoind's merkleblock format)
const merkleBlockProof = await client.transaction.merkleBlockProof(txId);

// GET merkle inclusion proof( using Electrum's blockchain.transaction.get_merkle format)
const merkleProof = await client.transaction.merkleProof(txId);

// GET spending status of a transaction output
const spendingStatus = await client.transaction.outputSpend(txId, vout);

// GET spending status of all transaction output
const spendingStatus = await client.transaction.outputsSpend(txId);

// CREATE a transaction
const tx = await client.transaction.create(hex);

Addresses

// GET address information
const addressInfo = await client.address.getInfo(address);

// Get transaction history for the specified address/scripthash, sorted with newest first. Returns 25 transactions per page.
const addressTransactions = await client.address.getTransactions(address);

// More can be requested by specifying the last txid seen by the previous query.
const moreTransactions = await client.address.getTransactions(address, lastSeenTxId);

// Get unconfirmed transaction history for the specified address/scripthash.
// Returns up to 50 transactions (no paging)
const mempoolTxs = await client.address.getMempoolTransactions(address);

// Get the list of unspent transaction outputs associated with the address
const utxos = await client.address.getUtxo(address);

// Search for addresses beginning with :prefix.
// Returns a JSON array with up to 10 results.
const addresses = await client.address.getByPrefix(address);

Blocks

// GET block information
const blockInfo = await client.block.get(blockHash);

// GET the hex-encoded block header.
const blockHeader = await client.block.getHeader(blockHash);

// GET the block status
const blockStatus = await client.block.getStatus(blockHash);

// Returns a list of transactions in the block (up to 25 transactions beginning)
const transactions = await client.block.getTransactions(blockHash);

// for a block with more than 25 transactions, the `startIndex`(which must be a multiple of 25 e.g 0, 25, 50, 75, 100 ... ) can be used for pagination.
const moreTransactions = await client.block.getTransactions(blockHash, startIndex);

// Returns list of all txids in the block
const transactionsIds = await client.block.getTransactionsIds(blockHash);

// Returns the transaction at index :index within the specified block.
const txIdAtIndex = await client.block.getTransactionIdAtIndex(blockHash, 1);

// Returns the hash of the block currently at height.
const hash = await client.block.getHash(height);

// Returns the 10 newest blocks starting at the tip or at start_height if specified.
const blocksList = await client.block.list();
const blocksListFromStartingHeight = await client.block.list(startHeight);

// Returns the height of the last block
const latestBlockHeight = await client.block.getLatestHeight();

// Returns the hash of the last block.
const latestBlockHash = await client.block.getLatestHash();

Mempool

// Get mempool backlog statistics.
const mempoolStats = await client.mempool.getStats();

// Get the full list of txids in the mempool as an array.
const mempoolTxIds = await client.mempool.getTxIds();

// Get a list of the last 10 transactions to enter the mempool.
const recentTxs = await client.mempool.getRecentTxs();

Fee

// GET fee-estimates
const feeEstimate = await client.fee.getEstimate();

Note: Build artifacts are committed to the repository (see dist folder) because the project is in active development.

I'll undo this as soon the project is stable and ready to be published to npm.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.