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:

CSS typography in white on a vibrant red geometric background. Article will focus on the CSS backdrop-filter property and its various functions, including blur, grayscale, brightness, and drop-shadow.

How to use the CSS backdrop-filter property

Backdrop and background have similar meanings, as they both refer to the area behind something. The main difference is that […]

Oscar Jite-Orimiono
Oct 4, 2024 ⋅ 10 min read
6 AI Tools For API Testing And Development

6 AI tools for API testing and development

AI tools like IBM API Connect and Postbot can streamline writing and executing API tests and guard against AI hallucinations or other complications.

Frank Joseph
Oct 3, 2024 ⋅ 12 min read
Patterns For Efficient DOM Manipulation With Vanilla JavaScript

Patterns for efficient DOM manipulation with vanilla JavaScript

Explore DOM manipulation patterns in JavaScript, such as choosing the right querySelector, caching elements, improving event handling, and more.

Joe Attardi
Oct 2, 2024 ⋅ 8 min read
Integrating Chrome's New `Window.ai` API In A Vue App

Integrating AI features in Vue using Chrome’s `window.ai` API

`window.ai` integrates AI capabilities directly into the browser for more sophisticated client-side functionality without relying heavily on server-side processing.

Emmanuel John
Oct 1, 2024 ⋅ 10 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