Socket
Socket
Sign inDemoInstall

bitcoinjs-lib

Package Overview
Dependencies
Maintainers
3
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcoinjs-lib

Client-side Bitcoin JavaScript library


Version published
Weekly downloads
99K
decreased by-35.33%
Maintainers
3
Weekly downloads
 
Created

What is bitcoinjs-lib?

The bitcoinjs-lib npm package is a library for Bitcoin-related operations in JavaScript. It provides tools for creating, signing, and verifying Bitcoin transactions, as well as generating and managing Bitcoin addresses and keys.

What are bitcoinjs-lib's main functionalities?

Generate a Bitcoin Address

This feature allows you to generate a new Bitcoin address. The code creates a random key pair and derives a Bitcoin address from the public key.

const bitcoin = require('bitcoinjs-lib');
const keyPair = bitcoin.ECPair.makeRandom();
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
console.log(address);

Create a Bitcoin Transaction

This feature allows you to create a Bitcoin transaction. The code builds a transaction by adding inputs and outputs, and then signs it with the private key.

const bitcoin = require('bitcoinjs-lib');
const keyPair = bitcoin.ECPair.fromWIF('your-private-key');
const txb = new bitcoin.TransactionBuilder();
txb.addInput('previous-txid', 0); // Add input (previous transaction)
txb.addOutput('recipient-address', 100000); // Add output (recipient address and amount in satoshis)
txb.sign(0, keyPair); // Sign the transaction
const tx = txb.build().toHex();
console.log(tx);

Verify a Bitcoin Transaction

This feature allows you to verify a Bitcoin transaction. The code parses a transaction from its hexadecimal representation and checks if all inputs have valid scripts.

const bitcoin = require('bitcoinjs-lib');
const tx = bitcoin.Transaction.fromHex('transaction-hex');
const txb = bitcoin.TransactionBuilder.fromTransaction(tx);
const isValid = txb.inputs.every(input => input.script && input.script.length > 0);
console.log(isValid);

Other packages similar to bitcoinjs-lib

Keywords

FAQs

Package last updated on 02 Jul 2014

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