Thursday, February 20, 2025
HomeBitcoinbitcoin core - Error in sending transaction:Inadequate funds

bitcoin core – Error in sending transaction:Inadequate funds


import Consumer from "bitcoin-core";
import fs from "fs";
const consumer = new Consumer({
  community: "regtest",
  username: "alice",
  password: "password",
  host: "http://alice:password@localhost:18443",
});
const SENDER_ADDRESS = "bcrt1qq2yshcmzdlznnpxx258xswqlmqcxjs4dssfxt2";

async operate setTransactionFee() {
  strive {
    const success = await consumer.setTxFee(0.00001);
    console.log("Transaction price price set to 21 sats/vB");
  } catch (error) {
    console.log("Error setting price price:", error);
  }
}
async operate important() {
  // await consumer.loadWallet("testwallet");
  strive {
    const deal with = await consumer.getNewAddress();
    console.log("Handle:", deal with);
    await consumer.generateToAddress(103, deal with);
    const steadiness = await consumer.getBalance();
    console.log(steadiness);
    const txid1 = await consumer.sendToAddress(SENDER_ADDRESS, 100);
    console.log("Despatched 100 BTC, TXID:", txid1);

    // 6. Get uncooked transaction particulars
    const txDetails = await consumer.getRawTransaction(txid1, true);

    // 7. Assemble Uncooked Transaction
    const rawTx = await consumer.createRawTransaction(
      [
        {
          txid: txid1,
          vout: 0,
        },
      ],
      {
        bcrt1qq2yshcmzdlznnpxx258xswqlmqcxjs4dssfxt2: 100,
        information: Buffer.from("We're all Satoshi!!", "utf8").toString("hex"),
      }
    );

    // 8. Fund the uncooked transaction with required price price
    const fundedTx = await consumer.fundRawTransaction(rawTx, { fee_rate: 21 });
    console.log("Funded TX:", fundedTx);

    // 9. Signal the transaction
    const signedTx = await consumer.signRawTransactionWithWallet(fundedTx.hex);
    console.log("Signed TX:", signedTx);

    // 10. Broadcast the transaction
    const finalTxid = await consumer.sendRawTransaction(signedTx.hex);
    console.log("Closing Transaction ID:", finalTxid);

    // 11. Write TXID to a file
    fs.writeFileSync("../out.txt", finalTxid);
    console.log("Transaction ID written to out.txt");
  } catch (err) {
    console.error("Error:", err);
  }
}
strive {
  important();
} catch (e) {
  console.log("Error:", e);
}

I’m attempting to run this transaction
however getting the next error

Handle: bcrt1q930lz38fuqaw83ujh8s050yyntaev2ll6xrzvu
11649.99941734
Despatched 100 BTC, TXID: d6f19c05ec6f5022907b38c521ac387d8c3186f30ecef81d2bd1a40703d52eed
Error: RpcError: Inadequate funds

I’ve sufficient steadiness as u can see what am i doing improper right here?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments