2

I installed a BCOIN full node and I would like to calculate estimated fees for Bitcoin transactions. This functionality works perfectly in the CLI. For example:

bcoin-cli fee 3

Anyway things go wrong when I use the JS api inside my express client app:

const result = await client.estimateFee(3);

The API doesn't throw any error and no response is given back. This was copied from the official API documentation.

Please note that client and options are properly configured. It works all fine in other express routes where I use the bcoin JS API to get blockchain info, lists of transactions etc.

What's wrong? Perhaps the API changed and documentation is outdated ?

Regards

Murch
  • 71,155
  • 33
  • 180
  • 600
  • What version of bcoin have you installed? We recently fixed an issue with fee API. Please ensure you're running the master branch from github. If you want to chat, we can help you on IRC #bcoin (freenode) or slack: https://bcoin.io/slack-signup – pinhead Jan 04 '20 at 23:45
  • @pinhead thanks for the support. Both my node and my express client are running BCOIN 2.0.0-dev. I installed the default version that one automatically gets cutting and pasting commands from the instructions provided in this guide: https://bcoin.io/guides/vps-setup.html (which seems to be unavailable today....) – Mario Mazzola Jan 05 '20 at 04:47
  • @Anonymous, I appreciate your concern, but I ve already told you in another thread that Bitcoin Core doesn't have the features I need (BCOIN does....) and, most importantly, I will not use my BCOIN node to generate and manage private keys. – Mario Mazzola Jan 05 '20 at 04:50
  • You never said what those features are. – Claris Jan 05 '20 at 04:52
  • @MarioMazzola yes that guide had outdated information (like the minimum required version of nodejs). The bug I think you are facing was fixed in this PR, not too long ago. Just check that your bcoin install is recent enough to include it, maybe pull from master again https://github.com/bcoin-org/bcoin/pull/889 – pinhead Jan 05 '20 at 04:57
  • @Anonymous, I need to query the blockchain to get all TXs (not only UTXOs) for addresses which are not part of an internal wallet. To my knowledge, Bitcoin Core doesn't do that on the fly.... I even opened a specific thread here last summer on this issue. – Mario Mazzola Jan 05 '20 at 05:00
  • @pinhead I just performed a git log in the BCOIN folder and I saw the commits you are referring too, made in NOV2019. As I am in the head of the master branch, I guess I can safely assume that my node is running the patched version of BCOIN. Would you agree? By the way, I thought of the following workaround. If I get last block data I know how much fees were paid to miners and block size in bits. Then I can calculate average fee per byte and (assuming normal bell distribution) I can come up with some aproximate fee brackets to display in my app. Do you see any major pitfall in this approach? – Mario Mazzola Jan 05 '20 at 05:04
  • @MarioMazzola thanks for checking. I just ran the example from the API docs locally in regtest and got a response (-1 due to empty mempool, but still a response) . There may be another issue in your exact implementation. – pinhead Jan 05 '20 at 05:49
  • @MarioMazzola That's not quite how fee estimation works - the estimator actually tacks transactions from when they enter the mempool until they get confirmed. The fee of each TX is compared to the number blocks that were added to the chain until the TX was included. – pinhead Jan 05 '20 at 05:51
  • @pinhead, the BCOIN approach makes sense! I know my approach is not ideal. I'd rather say it's quick, dirty, and ugly.... but it still allows me to get an estimation of what fees should be in order to get transactions in within a reasonable amount of time. Anyway, I ll keep trying to make it work as it's supposed to. Thanks a lot!! – Mario Mazzola Jan 05 '20 at 06:48
  • I've removed some off-topic comments from this question. Please use comments to ask for clarification on the question or to provide transient information related to the topic of the question. The comments were [moved to chat](https://chat.stackexchange.com/rooms/102893/discussion-between-pinhead-and-anonymous). – Murch Jan 06 '20 at 23:40

1 Answers1

1

Evebtually I decide to do it the curl way.

By having my express app to make a simple GET http request to the bitcoin node, I managed to get the job done. Doing this with the request npm module is súper simple.

It doesn't solve the issue with the JS api, but allows me to properly leverage on the éstimate fee feature of Bcoin.