How to get Unspent Transaction Outputs in Bitcoin
UTXO stands for Unspent Transaction (TX) Output. In fact, this means the amount of remaining cryptocurrency “little things” that you receive as a change from each transaction. In one of the previous articles, we covered the high-level distinction between UTXO and the Account-based model that is used in Ethereum (and some other blockchain networks).
Let’s consider how a typical crypto transaction occurs. We use Bitcoin as an example, as it is the most popular cryptocurrency using UTXO.
UTXO Transaction Example
When you check your Bitcoin wallet, you see your balance. For example, let’s assume that you have 100 Bitcoins. Although you only see the amount in the account, your balance consists of several UTXOs. You can have four UTXOs of 25 BTC, two UTXOs of 50 or, for example, a UTXO set of 20, 37, 30 and 13 Bitcoins. The cost of each UTXO does not matter, but their amount in our case will always be 100 BTC.
Continuing our example, let’s assume that we went to buy a new car. Having discarded the stereotyped version of Lamborghini, you opt for Porsche for 35 Bitcoins. However, in your wallet, there is UTXO with a value of only 20, 37, 30 and 13 BTC and there is no “banknote” with a value of 35 Bitcoins. UTXO cannot be divided, so you just can’t give away exactly 35 Bitcoins.
Instead, you will give back 40 BTC, at the place of which the network will create two new UTXOs with a value of 35 and 5 Bitcoins. The car dealer will receive 35 BTC, and you will receive your change in the amount of 5 BTC.
You can also spend your UTXO in 17 and 28 Bitcoins, receiving 10 Bitcoins as a change. A transaction can use any combination of UTXO and you do not have the opportunity to influence its choice.
By paying in the same way, you can combine several UTXOs in a larger transaction, reducing their number on the network.
Getting UTXO in Bitcoin using NOWNodes
To find a UTXO of inputs given a bitcoin transaction, you need first to get xPub.
xPub is the extended public part of the wallet key. Your wallet has a primary xPub, and each account you create is an extension of this primary xPub.
To get xPub, you need to execute https://btc.nownodes.io/api/v2/xpub/<xpub>/
Use also need to apply header:
Then, once you get your xPub, you can get UTXO;
The same header should be applied here.
You can also take a look at our API Description in Postman.