How to create an application which constructs a transaction using `bcoin` (javascript)?


I am new to development. I am working on a project and I am trying to use bcoin. I want to create an application which has a UI, where the user will be asked to enter Destination address and amount. And maybe the sender's public key as well, if it is not already entered. Then the application will fetch the UTXOs relevant to the sender's public key from some other Full Node. And based the UTXOs and the input data entered by the user, my application will construct a transaction HEX. I need the final outcome in XDR format. But I will try to do that on my own.

I will not be connecting to the Bitcoin network, I will connect with another network which has forked bitcoin code. I know this is a very silly question. But if anyone could guide me towards the right path on how to accomplish the above.


Posted 2019-02-13T10:29:07.773

Reputation: 23

I would help answer this question but I don't fully understand what you are after - do you want to manually create raw transactions using Bcoin? If so the "sender" in your case would need to be the Bcoin node you are running and you can fetch the unspent outputs and construct a transaction using outputs which are address amount pairs. – PW Kad – 2019-02-13T16:39:44.867

Yes, I want to create raw transactions using Bcoin, can you guide me with that? – Deb – 2019-02-14T14:03:09.310



This is a very complicated question. bcoin already has a built-in wallet that can do all of these operations for you. There is a well-documented RESTful HTTP API you can read through here: to get an idea of what's available. You can also write your own wallet application using the bcoin object classes directly.

Very broadly however, here's some tips that might interest you:

  • Enable Address indexing. This is a feature that is not currently available in bitcoind yet (so far I think only indexing by transaction ID is supported). This is switched on with indexAddress: true in bcoin.conf or --index-address on the command line. The address index will enable you to request the transactions associated with a specific address:

  • You will want to process that transaction data and maybe cross-check the UTXO set (so you know what has been spent already) with the API call

  • Check out the MTX and Coin objects to construct a transaction from the UTXO you recover. We have several guides on transaction handling, maybe read through this:

  • Signing transactions with private keys: I'm not sure how your application will work but it sounds like the users will have to sign the TX themselves?

I recomend you read through the bcoin API docs and the guides (and of course, the codebase!). And just focus on the default wallet process for coin selection, transaction composition, signing, and private key handling.


Posted 2019-02-13T10:29:07.773

Reputation: 4 072