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:

master state management hydration Nuxt usestate

Nuxt state management and hydration with useState

useState can effectively replace ref in many scenarios and prevent Nuxt hydration mismatches that can lead to unexpected behavior and errors.

Yan Sun
Jan 20, 2025 ⋅ 8 min read
React Native List Components: FlashList, FlatList, And More

React Native list components: FlashList, FlatList, and more

Explore the evolution of list components in React Native, from `ScrollView`, `FlatList`, `SectionList`, to the recent `FlashList`.

Chimezie Innocent
Jan 16, 2025 ⋅ 4 min read
Building An AI Agent For Your Frontend Project

Building an AI agent for your frontend project

Explore the benefits of building your own AI agent from scratch using Langbase, BaseUI, and Open AI, in a demo Next.js project.

Ivaylo Gerchev
Jan 15, 2025 ⋅ 12 min read
building UI sixty seconds shadcn framer ai

Building a UI in 60 seconds with Shadcn and Framer AI

Demand for faster UI development is skyrocketing. Explore how to use Shadcn and Framer AI to quickly create UI components.

Peter Aideloje
Jan 14, 2025 ⋅ 6 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