Bitcoin Forum
May 02, 2024, 07:16:01 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin RPC send error code -3 - Invalid Amount  (Read 106 times)
willmorrison (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 1


View Profile
October 17, 2022, 11:13:03 PM
 #1

Hello, I'm having a problem with Bitcoin RPC's send method. Here is my RPC call:

{"jsonrpc":"2.0","method":"send","params":[[{"3NKnXgAuRZ52uUMgDztyQM1aNsXoyoxM7D":0.0002462028}],6,"economical",null,{"change_position":1,"subtract_fee_from_outputs":[0],"inputs":[{"txid":"69c77704508f14949448a989b2b5662292128f92cad9620961118f767799d1be","vout":0,"sequence":0}]}]}

This is the RPC response:

{"result":null,"error":{"code":-3,"message":"Invalid amount"},"id":null}

I'm aware of the other question on this forum that says -3 is a type error that only appears when amount is negative or zero, but that is not the case as you can see above in the call body.

As you can see on a chain explorer, this transaction ID has more than the send amount at that index. As a test, I removed the additional options to see if it would send without them and it results in the same error.

I've tried specifying the amount as a string and a number, neither work.

Any help would be appreciated. Thanks.
Transactions must be included in a block to be properly completed. When you send a transaction, it is broadcast to miners. Miners can then optionally include it in their next blocks. Miners will be more inclined to include your transaction if it has a higher transaction fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714634161
Hero Member
*
Offline Offline

Posts: 1714634161

View Profile Personal Message (Offline)

Ignore
1714634161
Reply with quote  #2

1714634161
Report to moderator
1714634161
Hero Member
*
Offline Offline

Posts: 1714634161

View Profile Personal Message (Offline)

Ignore
1714634161
Reply with quote  #2

1714634161
Report to moderator
1714634161
Hero Member
*
Offline Offline

Posts: 1714634161

View Profile Personal Message (Offline)

Ignore
1714634161
Reply with quote  #2

1714634161
Report to moderator
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5818


not your keys, not your coins!


View Profile WWW
October 17, 2022, 11:58:26 PM
 #2

Can you share the whole cURL or code snippet you're using to submit that request?

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
BitMaxz
Legendary
*
Offline Offline

Activity: 3248
Merit: 2955


Block halving is coming.


View Profile WWW
October 17, 2022, 11:59:23 PM
 #3

How about using createrawtransaction instead of send call?

I search a bit in google there might be issue in your rpc command so try other commands like generating raw transaction and broadcast them manually.

Read this https://bitcoin.stackexchange.com/questions/58727/unable-to-create-raw-transaction-with-json-rpc-command

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
willmorrison (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 1


View Profile
October 18, 2022, 12:24:10 AM
 #4

Can you share the whole cURL or code snippet you're using to submit that request?

It's hard to get that because I'm using my own RPC library. The JSON body I put in the post is printing from inside the library right before it makes the request. Here's the TypeScript code that's trying to send:

Code:
const response = await bitcoin.send(
    [{ [output]: sending.toString() }],
    6, // conf_target
    "economical",
    undefined, // fee_rate
    {
      "change_position": 1,
      "subtract_fee_from_outputs": [0],
      "inputs": [input],
    },
  );

Again, I have run it without the options object and have the same result. Additionally, this code works on the testnet but not the mainnet if that helps.
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10522



View Profile
October 18, 2022, 04:00:00 AM
Merited by NeuroticFish (2), ABCbits (1)
 #5

0.0002462028

{"result":null,"error":{"code":-3,"message":"Invalid amount"},"id":null}

I'm aware of the other question on this forum that says -3 is a type error that only appears when amount is negative or zero, but that is not the case as you can see above in the call body.
The error message is already telling you what the problem is and it is not just about being negative or zero, it is about being an "invalid" value for amount which could be for many different reasons like not being a number; in this case the problem is that the value has more decimal places than defined in Bitcoin (10 instead of 8).

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
willmorrison (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 1


View Profile
October 18, 2022, 01:10:41 PM
Merited by xandry (1)
 #6

0.0002462028

{"result":null,"error":{"code":-3,"message":"Invalid amount"},"id":null}

I'm aware of the other question on this forum that says -3 is a type error that only appears when amount is negative or zero, but that is not the case as you can see above in the call body.
The error message is already telling you what the problem is and it is not just about being negative or zero, it is about being an "invalid" value for amount which could be for many different reasons like not being a number; in this case the problem is that the value has more decimal places than defined in Bitcoin (10 instead of Cool.

Thank you, this solved the problem. Here's the new code:

Code:
const response = await bitcoin.send(
    [{ [output]: sending.toFixed(8).toString() }],
    6, // conf_target
    "economical",
    undefined, // fee_rate
    {
      "change_position": 1,
      "subtract_fee_from_outputs": [0],
      "inputs": [input],
    },
  );
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!