2021-02-26
2349
#vanilla javascript
Eze Sunday
34394
Feb 26, 2021 ⋅ 8 min read

Send bitcoin from your wallet using JavaScript

Eze Sunday Eze Sunday is a full-stack software developer and technical writer passionate about solving problems, one line of code at a time. Contact Eze at [email protected].

Recent posts:

Building a Full-Featured Laravel Admin Dashboard with Filament

Building a full-featured Laravel admin dashboard with Filament

Build scalable admin dashboards with Filament and Laravel using Form Builder, Notifications, and Actions for clean, interactive panels.

Kayode Adeniyi
Dec 20, 2024 ⋅ 5 min read
Working With URLs In JavaScript

Working with URLs in JavaScript

Break down the parts of a URL and explore APIs for working with them in JavaScript, parsing them, building query strings, checking their validity, etc.

Joe Attardi
Dec 19, 2024 ⋅ 6 min read
Lazy Loading Vs. Eager Loading

Lazy loading vs. Eager loading

In this guide, explore lazy loading and error loading as two techniques for fetching data in React apps.

Njong Emy
Dec 18, 2024 ⋅ 5 min read
Deno logo over an orange background

How to migrate your Node.js app to Deno 2.0

Deno is a popular JavaScript runtime, and it recently launched version 2.0 with several new features, bug fixes, and improvements […]

Yashodhan Joshi
Dec 17, 2024 ⋅ 7 min read
View all posts

20 Replies to "Send bitcoin from your wallet using JavaScript"

  1. Hi! Did you fixed “Error: Some inputs have not been fully signed” because I have the same problem

  2. Please drop the link for main Bitcoin API. Because i have searched for it , I could not find it. Since we can use the code for Bitcoin network as well. And not only btctest network alone. Yes the testnetwork worked perfectly. But I need the main BTC network Link. Where I am out my private key and wallet address

  3. Hi Desmond, I mentioned this -> “To send real bitcoin, you’ll need to change the network from BTCTEST to BTC and use your real bitcoin wallet’s private key and address.”

    So, you can do that.

  4. I see a small bug in the calculation of the fee in that final complete code panel. The bytes are being multiplied by 20 twice, via two separate lines of code:

    fee = transactionSize * 20
    transaction.fee(fee * 20);

  5. I really like this script!
    BTW, if anyone runs their own Bitcoin full node, you can comment out the final sochain.com POST statement and instead grab a copy of the final transaction hex string then send that directly to your own full node to get it into the blockchain. Just make sure you reconfigure your full node to use the TESTNET before doing it, otherwise you’ll post to MAINNET.

    1) Restart your fullnode to use the bitcoin TESTNET (swap in your config file location):
    % bitcoind -testnet -conf=/bitcoin/.bitcoin/bitcoin.conf -printtoconsole # change to location of your conf file!

    2) Post the transaction hex string using either the bitcoin REST APIs, or the bitcoin-cli
    % bitcoin-cli -testnet -conf=/bitcoin/.bitcoin/bitcoin.conf decoderawtransaction 0200000001a…c00000000

  6. Hello, please i am getting this error:

    (node:6480) UnhandledPromiseRejectionWarning: Invalid Argument: Amount is expected to be a positive integer

    I need help to correct this please.

  7. That last point in my previous post should be the “sendrawtransaction” command, not the “decoderawtransaction” command:

    % bitcoin-cli -testnet -conf=/bitcoin/.bitcoin/bitcoin.conf sendrawtransaction 0200000001a…c00000000

    Also worth noting that this script works for all of the main bitcoin address types, including both legacy addresses and segwit addresses. i.e. p2pkh (legacy), p2wpkh (native segwit), and p2sh_p2wpkh (nested segwit).

    This axios API is really awesome, but I would really love to get my hands on that sochain get_tx_unspent API .. that’s super nice!

  8. Your maths for the amounts is incorrect, so probably not enough satoshis to pay for your transaction. Check your totalAmountAvailable, satoshiToSend, fee (from transaction size) to see what the calculations show.

  9. I have an error, i tryed to use the function in my react app and i am getting transaction.sign(privateKey) error. assertion error. but when i run this alone my function works.

  10. Hi

    I got Assertion Faild issue, so could you please guide me how to resolve it?

    bitcore.min.js:1 Uncaught (in promise) Error: Assertion failed
    at assert (bitcore.min.js:1)
    at BN.toBuffer (bitcore.min.js:1)
    at Signature.toBuffer.Signature.toDER (bitcore.min.js:1)
    at PublicKeyHashInput.addSignature (bitcore.min.js:1)
    at Transaction.applySignature (bitcore.min.js:1)
    at bitcore.min.js:1
    at arrayEach (bitcore.min.js:1)
    at Function.forEach (bitcore.min.js:1)
    at Transaction.sign (bitcore.min.js:1)
    at sendBitcoin ((index):619)

    Line no: 619 transaction.sign(privateKey);

  11. Hi,
    Firstly thanks for this blog it’s really helpful. I have the following question:
    Is the fee structure defined above something standard?
    I see a 20 satoshi/byte mechanism has been followed. Do I need to adhere to this or can I reduce the fee or make it something constant as well like $1? Asking this because if someone is using a wallet which has had a lot of transactions previously, the transaction fee will just skyrocket even if the amount of bitcoins transferred is less as transaction size depends on input count.

    Thanks.

Leave a Reply