bitcoinjs / coinselect

An unspent transaction output (UTXO) selection module for bitcoin.
MIT License
178 stars 101 forks source link

Unable to spend money even with enough utxos. #39

Closed prathammehta closed 5 years ago

prathammehta commented 5 years ago

I'm experiencing a problem where my total bitcoin balance is 1238944 satoshis. Coin select is working perfectly to send 40000 satoshis or 20000 satoshis. It is unable to spend 30000 satoshis and returns undefined for the inputs and outputs. Here are the utxos:


[
    {
      "txId": "84e9748e60f4eeddf91b5c42c30f7c0a228bbcb6f72847ad62a3ce48bbcb5ea8",
      "vout": 0,
      "value": 100000
    },
    {
      "txId": "7f092d4d8b9d89db464b5fc9dfa2205bbb9f26a1f259da1d49139b0fc9a68297",
      "vout": 1,
      "value": 23000
    },
    {
      "txId": "3676d518060dccce621752153ea58ea659e40f6e40887166566b6ab3ab920032",
      "vout": 1,
      "value": 1000
    },
    {
      "txId": "127d54a7836486c3065dc4e26707976270c8f6b2d8b85f1629507288aba95f19",
      "vout": 0,
      "value": 10000
    },
    {
      "txId": "802b9507fcd4d13b204aa94d0e19e77669e925ef8f86b948af59faeb716c6f38",
      "vout": 0,
      "value": 100000
    },
    {
      "txId": "759bbe1b631207ac48342926c95d4b229eee04c6bf6c876e5f2ab52e25b60da8",
      "vout": 1,
      "value": 797319
    },
    {
      "txId": "4cd48916d574355b873f1db192df24dbcf6dcb4818a2317a873a9c95b55c4341",
      "vout": 1,
      "value": 207625
    }
  ]
prathammehta commented 5 years ago

Figured it out. I was sending a unrounded value (29999.999999 satoshis) in the target. Make sure you send integers to the library. Hope this helps someone in the future. :)

dcousens commented 5 years ago

PRs accepted!