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:

Rxjs Adoption Guide: Overview, Examples, And Alternatives

RxJS adoption guide: Overview, examples, and alternatives

Get to know RxJS features, benefits, and more to help you understand what it is, how it works, and why you should use it.

Emmanuel Odioko
Jul 26, 2024 ⋅ 13 min read
Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 ⋅ 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 ⋅ 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 ⋅ 5 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