UTXOs Accounting
UTXOs & Balances
If you are a developer coming from Ethereum, the biggest practical difference is that Hydra's account model is built on Bitcoin's UTXOs.
In Ethereum, you'd typically have an account with an unique address that holds a balance. You'd be sending/receiving money and interacting with Smart Contracts using one account.
In HYDRA, you don't really have accounts. Instead, you have a collection of UTXOs, each of which has its own address. An UTXO may be used only once when you send money or interact with a Smart Contract. If an UTXO has more value than you intend to use, it'd be split up into multiple UTXOs after a transaction.
In this chapter we'll explore the UTXO model by sending some money using the cli command, and peeking into the transaction data.
Later in Part II we'll see how HYDRA's Smart Contract implementation bridges Bitcoin's UTXO model with Ethereum's account model.
UTXO Address
With UTXO, you can reuse a payment address. For better anonymity, though, you'd typically generate new addresses for each payment you'd like to receive.
Let's generate an address:
hydra-cli getnewaddressYou get a new address:
HfsPCLrjjmqXptxWNXXg3wQruzC8bhPx63Get as many as you want:
> hydra-cli getnewaddress
HZWeFWECjKQ3KstHhCjxFj9hiM7jzXWw3p
> hydra-cli getnewaddress
HJbSKruSXWnjSRZvSXMf2Y33gEw9FqHMHf
> hydra-cli getnewaddress
Hdiqg2mp646KhSQjVud3whv6C34hNHQnL2An UTXO address is 20 bytes (160 bits) long, base58 encoded. This is the same length as Ethereum's address. We can convert it to an Ethereum compatible hexadecimal address:
And to convert it back to base58 UTXO address:
Send Money Transaction
Now let's send money to an UTXO address. You'd be sending money to yourself, but this is exactly the same process as when you send money to somebody else.
First generate a new receiving address:
(You should replace the following commands with the address you've generated.)
Next, send 10 Hydras to this address:
A transaction ID (txid) is returned for this transfer:
Wait for a minute or two for the transaction be be confirmed. You should see something like this in the container's log:
Use gettransaction to get some general information about this transaction:
This transaction had been confirmed twice so far:
Let's now use listunspent to list recently created UTXOs. List UTXOs that had been confirmed less than 20 times:
Note that both of these UTXOs share the same txid. In other words, one send money transaction created two new UTXOs:
hdiqg2mp646KhSQjVud3whv6C34hNHQnL2: Receiving address, holding value of 10.hddyh9oMU44qZ28bEY9WhCDbmCaALVDr1k: The original sender UTXO had 20k HYDRA, the amount generated. This a new UTXO created to hold the change, minus fees.
Decoding Transaction Data
We can dig a little deeper into the transaction data to see that HYDRA really shares the same UTXO data structure as Bitcoin. From the earlier gettransaction output, we got the raw transaction data in hexadecimals (i.e. 02000000017d2...ac90060000).
Let's decode the transaction data:
The decoded transaction:
As you can see, this is a Pay-to-PubkeyHash transaction!
Summary
HYDRA manages money using Bitcoin's UTXO model. Instead of using accounts to track balances, a HYDRA wallet keeps track of the collection of UTXOs. When a transaction is created, the wallet searches the collection to find UTXOs that add up to enough value to pay for the amount transferred and the fees.
Last updated
Was this helpful?