bitcoincore-node v1.0.0
bitcoincore-node
A comprehensive Node.js package for interacting with Bitcoin Core via RPC. Easily create, sign, and broadcast Bitcoin transactions, manage wallets, and access blockchain data through a simple and easy-to-use API interface. Perfect for developers building cryptocurrency applications, wallets, or integrating Bitcoin functionality into their services.
Features
- Create Bitcoin transactions: Create, sign, and broadcast transactions directly from your Node.js application.
- Wallet management: Manage Bitcoin wallets, import/export private keys, and perform backup and encryption operations.
- Blockchain data: Access various blockchain data including block hashes, block headers, and transaction details.
- Bitcoin Core RPC: Interact with Bitcoin Core via JSON-RPC, supporting a wide range of commands.
Installation
To install the package, use npm:
npm install bitcoincore-node
Usage
To use the package, require the module and create a new instance of the BitcoinCore
class.
Follow official Bitcoin Core documentation for more details on available commands.
Import Library
const BitcoinCore = require('bitcoincore-node');
ES6
import { BitcoinCore } from 'bitcoincore-node';
Example
// Create a new instance of BitcoinCore
const client = new BitcoinCore({
network: 'test'
host: '127.0.0.1',
port: 18332,
username: 'rpcusername',
password: 'rpcpassword',
});
All RPC methods are available as promises in camelCase
BlockchainRPC
const blockHash = await client.BlockchainRPC.getBestBlockhash();
ControlRPC
const info = await client.ControlRPC.getMemoryInfo();
GeneratingRPC
const info = await client.GeneratingRPC.generateBlock(...);
MiningRPC
const info = await client.MiningRPC.getBlockTemplate();
NetworkRPC
const info = await client.NetworkRPC.getNetworkInfo();
RawTransactionRPC
const info = await client.RawTransactionRPC.getRawTransaction(...);
UtilRPC
const info = await client.UtilRPC.getIndexInfo(...);
WalletRPC
const info = await client.WalletRPC.getBalance(...);
Sample
Run bitcoin core
Download and install bitcoincore in your machine
Follow official Bitcoin Core documentation for more details instruction.
Create wallet
return await client.WalletRPC.createWallet('your_wallet_name');
Get wallet information
return await client.WalletRPC.getWalletInfo({
wallet: 'your_wallet_name',
});
Wallet balance
return await client.WalletRPC.getBalance({
wallet: 'your_wallet_name',
});
Create address
return await client.WalletRPC.getNewAddress({
wallet: 'your_wallet_name',
});
Respose
tb1q30lhx0e00xql5gmwn59yvu3umf7s03p8tp4gdh
Get address info
return await client.WalletRPC.getAddressInfo(
'tb1q30lhx0e00xql5gmwn59yvu3umf7s03p8tp4gdh'
);
Take payment
Send test bitcoin to the address. You can send test bitcoin using various testnet faucet for free. Then you can check your wallet balance to confirm that the payment has been received.
Monitor payment
return await client.WalletRPC.getReceivedByAddress(
{
wallet: 'your_wallet_name',
},
'tb1q30lhx0e00xql5gmwn59yvu3umf7s03p8tp4gdh'
);
License
This package is released under the MIT License.