Monday, March 9, 2026
HomeBitcointransaction charges - Switch all funds to a different pockets with node.js

transaction charges – Switch all funds to a different pockets with node.js

Relating to first query,

No, you do not have to run your individual node. What I do know is blockstream esplora gives public API with documentation you may work with.

Relating to second query,

It depends upon what sort of segwit deal with(p2wpkh, p2wsh, p2tr) it’s, however I assume what you need to spend could be the commonest segwit transaction, which is p2wpkh(single signature with public key).

For p2wpkh segwit spend, you may refer beneath code working for nodejs, which you will discover right here, too.

import * as bitcoin from 'bitcoin-sdk-js';

const privkey =
  'e6c58327b4bf1314296bba7adb66f94c36ea5611ac07830c229aa7ee6f9caac3';
const toAddress="tb1qmjqyknun9umlwlle5nuy8jz9ms7v85cp7k2nfe";
const toValue = 300000; // unit is satoshi
const txHash="8bcd197873dbff5cc67cb3e0b1cbbdf097c7af94b0e9365adecb424e408294bf";
const inputValue = 310981; // payment is enter worth - whole worth

const tx = new bitcoin.Transaction();

await tx.addInput({
  txHash: txHash,
  index: n, // it ought to be vout of utxo, index of utxo in transation
  worth: inputValue,
});
await tx.addOutput({
  deal with: toAddress,
  worth: toValue,
});
await tx.signInput(privkey, 0);

const txHex = await tx.getSignedHex();

For different kind of segwit deal with, it actually varies on unlocking script, so there’s probably not a technique resolution for it.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments