From d569082c3e0c304db2a9eef306889024d8fede57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:48:05 -0300 Subject: [PATCH 1/5] create doc section for UTXO model --- apps/docs/.vitepress/config.ts | 4 +++ apps/docs/src/guide/utxo-model/index.md | 34 +++++++++++++++++++ .../src/guide/wallets/checking-balances.md | 14 -------- 3 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 apps/docs/src/guide/utxo-model/index.md diff --git a/apps/docs/.vitepress/config.ts b/apps/docs/.vitepress/config.ts index 6fa86a740d6..7ac062f7c9d 100644 --- a/apps/docs/.vitepress/config.ts +++ b/apps/docs/.vitepress/config.ts @@ -70,6 +70,10 @@ export default defineConfig({ }, ], }, + { + text: 'UTXO Model', + link: '/guide/utxo-model/', + }, { text: 'Creating a Fuel dApp', link: '/guide/creating-a-fuel-dapp/', diff --git a/apps/docs/src/guide/utxo-model/index.md b/apps/docs/src/guide/utxo-model/index.md new file mode 100644 index 00000000000..cfdf94ce6bb --- /dev/null +++ b/apps/docs/src/guide/utxo-model/index.md @@ -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. diff --git a/apps/docs/src/guide/wallets/checking-balances.md b/apps/docs/src/guide/wallets/checking-balances.md index f93872e22de..ff112bb7446 100644 --- a/apps/docs/src/guide/wallets/checking-balances.md +++ b/apps/docs/src/guide/wallets/checking-balances.md @@ -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} From 4e21f24fa441c35848e0653a93496551c098249e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:51:39 -0300 Subject: [PATCH 2/5] add changeset --- .changeset/modern-bugs-exist.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changeset/modern-bugs-exist.md diff --git a/.changeset/modern-bugs-exist.md b/.changeset/modern-bugs-exist.md new file mode 100644 index 00000000000..bd2241f469b --- /dev/null +++ b/.changeset/modern-bugs-exist.md @@ -0,0 +1,4 @@ +--- +--- + +docs: add doc section for `UTXO` model From 29ec02c8ea91186845fe4bcade1ed4d350439cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:16:08 -0300 Subject: [PATCH 3/5] fix doc section name --- apps/docs/.vitepress/config.ts | 4 ++-- apps/docs/src/guide/{utxo-model => the-utxo-model}/index.md | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename apps/docs/src/guide/{utxo-model => the-utxo-model}/index.md (100%) diff --git a/apps/docs/.vitepress/config.ts b/apps/docs/.vitepress/config.ts index 7ac062f7c9d..76e4ce976bd 100644 --- a/apps/docs/.vitepress/config.ts +++ b/apps/docs/.vitepress/config.ts @@ -71,8 +71,8 @@ export default defineConfig({ ], }, { - text: 'UTXO Model', - link: '/guide/utxo-model/', + text: 'The UTXO Model', + link: '/guide/the-utxo-model/', }, { text: 'Creating a Fuel dApp', diff --git a/apps/docs/src/guide/utxo-model/index.md b/apps/docs/src/guide/the-utxo-model/index.md similarity index 100% rename from apps/docs/src/guide/utxo-model/index.md rename to apps/docs/src/guide/the-utxo-model/index.md From 00cb52b9f955c753bf2410e32b359ae3fbcce00a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 26 Jun 2024 11:13:06 -0300 Subject: [PATCH 4/5] edit configs --- apps/docs/.vitepress/config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/docs/.vitepress/config.ts b/apps/docs/.vitepress/config.ts index 76e4ce976bd..7a8e4053c44 100644 --- a/apps/docs/.vitepress/config.ts +++ b/apps/docs/.vitepress/config.ts @@ -73,6 +73,8 @@ export default defineConfig({ { text: 'The UTXO Model', link: '/guide/the-utxo-model/', + collapsed: false, + items: [], }, { text: 'Creating a Fuel dApp', From 9138271cbfaf6e35d5e3adb174c65ffa77706262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:03:02 -0300 Subject: [PATCH 5/5] trigger CI