Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add doc section for UTXO model #2624

Merged
merged 10 commits into from
Jun 28, 2024
4 changes: 4 additions & 0 deletions .changeset/modern-bugs-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

docs: add doc section for `UTXO` model
6 changes: 6 additions & 0 deletions apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export default defineConfig({
},
],
},
{
text: 'The UTXO Model',
link: '/guide/the-utxo-model/',
collapsed: false,
items: [],
},
{
text: 'Creating a Fuel dApp',
link: '/guide/creating-a-fuel-dapp/',
Expand Down
34 changes: 34 additions & 0 deletions apps/docs/src/guide/the-utxo-model/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The UTXO Model

In UTXO (Unspent Transaction Output) based systems, each coin is unique, similar to how physical currency bills have different denominations.

A UTXO represents a coin with a specific amount, similar to having a $10 or $5 bill. It's crucial to understand this unique feature of UTXOs, as it differs significantly from Ethereum's account-based system.

In Ethereum, balances are tracked as cumulative totals, similar to a bank account, rather than as distinct 'coins' or 'bills'.

## Why UTXOs Matter

Each UTXO corresponds to a unique coin and has an associated amount. This model allows for greater transparency and control in cryptocurrency transactions. Understanding UTXOs is key for effectively managing and tracking your digital assets.

## How UTXOs Work

When you create a transaction, you will use UTXOs from your account to fund it. Here's a step-by-step explanation:

`1. Selecting UTXOs`: The SDK selects one or more UTXOs from your account that together are equal to or greater than the transaction amount plus the transaction fee.

`2. Spending UTXOs`: These selected UTXOs are used to fund the transaction and cover the transaction fee. For example, if you need to send $15 and the transaction fee is $1, and you have $10 and $6 UTXOs, both will be used.

`3. New UTXOs`: If the total value of the selected UTXOs exceeds the transaction amount plus the transaction fee, the difference is returned to your account as new UTXOs. For instance, if you spend a $20 UTXO for a $15 transaction with a $1 fee, a new UTXO worth $4 will be created as change and added back to your account.

In summary, the original UTXOs used in the transaction are marked as spent and cannot be used again. The new UTXOs are available for future transactions.

Suppose you have the following UTXOs in your account:

- $10 UTXO
- $20 UTXO

You want to send $15 to someone, and the transaction fee is $1. Here's what happens:

- The $20 UTXO is selected to fund the $15 transaction and cover the $1 fee.
- The transaction is completed and the $20 UTXO is spent.
- A new $15 UTXO is generated to the recipient, and a new $4 UTXO (change) is created and added to your account.
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 0 additions & 14 deletions apps/docs/src/guide/wallets/checking-balances.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
# Checking balances

## Understanding the UTXO Model

In UTXO (Unspent Transaction Output) based systems, each coin is unique, similar to how physical currency bills have different denominations.

A UTXO represents a coin with a specific amount, similar to having a $10 or $5 bill. It's crucial to understand this unique feature of UTXOs, as it differs significantly from Ethereum's account-based system.

In Ethereum, balances are tracked as cumulative totals, similar to a bank account, rather than as distinct 'coins' or 'bills'.

## Why UTXOs Matter

Each UTXO corresponds to a unique coin and has an associated amount. This model allows for greater transparency and control in cryptocurrency transactions. Understanding UTXOs is key for effectively managing and tracking your digital assets.

## Getting a Wallet's Balance

To check the balance of a specific asset, you can use [`getBalance`](../../api/Account/Account.md#getbalance) method. This function aggregates the amounts of all unspent coins of the given asset in your wallet.

<<< @/../../docs-snippets/src/guide/wallets/checking-balances.test.ts#checking-balances-1{ts:line-numbers}
Expand Down
Loading