- run node on server
- create a bitcoin core instance
const Client = require("bitcoin-core");
const client = new Client({
network: "testnet",
host: "116.202.196.59",
port: "8332",
username: "btcuser",
password: "btcpassword",
version: "0.18.1",
});
- generate a new address
const getNewAddr = async () => {
const newAddr = await client.getNewAddress();
return newAddr;
};
- get total balance
const getTotalBal = async () => {
const balance = await client.getBalance("*", 0);
return balance;
};
- get trx details
const getTxnDetails = async (txId) => {
const txn = await client.getTransaction(txId);
return txn;
};
- get blocks
const getBlock = async (blockHash) => {
const block = await client.getBlock(blockHash);
return block;
};
- transfer bitcoin
const transfer = async (toAddr, amt) => {
const txn = await client.sendToAddress(toAddr, amt);
return txn;
};
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.