🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More →
Socket
Book a DemoSign in
Socket

@devgrid/bitcoin-core

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devgrid/bitcoin-core

Bitcoin Core API client for Node.js

Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
29
866.67%
Maintainers
1
Weekly downloads
 
Created
Source

@devgrid/bitcoin-core

A strongly-typed Bitcoin Core RPC client for Node.js with full TypeScript support.

Features

  • 🚀 Full TypeScript support with comprehensive type definitions
  • đź’Ş Strong type checking for all RPC methods and responses
  • đź”’ Secure connection handling with SSL/TLS support
  • ⚡ Promise-based API
  • 🔄 Automatic request batching
  • 🎯 Detailed error handling
  • 📝 Extensive documentation

Installation

npm install @devgrid/bitcoin-core
# or
yarn add @devgrid/bitcoin-core

Quick Start

import { BitcoinCore } from '@devgrid/bitcoin-core';

const client = new BitcoinCore({
  host: 'localhost',
  port: 8332,
  username: 'your-username',
  password: 'your-password',
  ssl: true
});

// Get blockchain info
const info = await client.getBlockchainInfo();
console.log(info);

// Get transaction by ID
const tx = await client.getTransaction('txid');
console.log(tx);

API Documentation

Configuration

interface BitcoinConfig {
  host: string;
  port: number;
  username: string;
  password: string;
  ssl?: boolean;
  timeout?: number;
  headers?: Record<string, string>;
}

Core Methods

Blockchain

  • getBlockchainInfo(): Get blockchain info
  • getBlock(hash: string): Get block by hash
  • getBlockHash(height: number): Get block hash by height
  • getBlockCount(): Get current block count

Transactions

  • getTransaction(txid: string): Get transaction details
  • sendTransaction(hex: string): Send raw transaction
  • decodeTransaction(hex: string): Decode raw transaction

Wallet

  • getBalance(): Get wallet balance
  • listUnspent(): List unspent transactions
  • sendToAddress(address: string, amount: number): Send to address

Error Handling

try {
  await client.getTransaction('invalid-txid');
} catch (error) {
  if (error.code === RPCErrorCode.INVALID_PARAMS) {
    console.error('Invalid transaction ID');
  }
}

Batch Requests

const batch = client.batch();
batch.getBlockCount();
batch.getBlockchainInfo();
const [count, info] = await batch.execute();

Advanced Usage

Custom Headers

const client = new BitcoinCore({
  // ... other config
  headers: {
    'User-Agent': 'MyApp/1.0.0'
  }
});

SSL/TLS Configuration

const client = new BitcoinCore({
  // ... other config
  ssl: true,
  sslOptions: {
    ca: fs.readFileSync('ca.pem'),
    cert: fs.readFileSync('cert.pem'),
    key: fs.readFileSync('key.pem')
  }
});

Timeout Configuration

const client = new BitcoinCore({
  // ... other config
  timeout: 30000 // 30 seconds
});

Error Codes

CodeDescription
-32600Invalid Request
-32601Method not found
-32602Invalid params
-32603Internal error
-32700Parse error

Contributing

Contributions are welcome! Please read our contributing guidelines first.

Testing

npm test
# or
yarn test

License

MIT

Credits

Built with TypeScript and Node.js.

Keywords

bitcoin

FAQs

Package last updated on 29 Mar 2025

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