Author

Topic: Bitcoin RPC send error code -3 - Invalid Amount (Read 136 times)

newbie
Activity: 3
Merit: 1
October 18, 2022, 08:10:41 AM
#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],
    },
  );
legendary
Activity: 3472
Merit: 10611
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).
newbie
Activity: 3
Merit: 1
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.
legendary
Activity: 3472
Merit: 3217
Happy New year 🤗
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
hero member
Activity: 924
Merit: 5943
not your keys, not your coins!
Can you share the whole cURL or code snippet you're using to submit that request?
newbie
Activity: 3
Merit: 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.
Jump to: