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 Provider doc section for cacheUtxo #2598

Merged
merged 29 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
61440b0
add code snippet
Torres-ssf Jun 24, 2024
02610d4
add doc section to provider doc page
Torres-ssf Jun 24, 2024
7abc8de
add empty changeset
Torres-ssf Jun 24, 2024
2961b7f
fix changeset
Torres-ssf Jun 24, 2024
0941eaa
fix doc sentence
Torres-ssf Jun 24, 2024
e4c172c
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 24, 2024
8524d74
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 24, 2024
a3a8b3f
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 25, 2024
b26f010
edit doc paragraph
Torres-ssf Jun 25, 2024
08c5981
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 26, 2024
f9c8948
improve doc paragraph
Torres-ssf Jun 26, 2024
d37c3c2
add link to UTXOs section
Torres-ssf Jun 26, 2024
1455dee
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
petertonysmith94 Jun 26, 2024
a21dec9
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 27, 2024
d6a46b6
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 27, 2024
96d5972
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 28, 2024
1503b19
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 28, 2024
22640cc
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
maschad Jun 28, 2024
a8516bd
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jun 29, 2024
896b090
fix link
Torres-ssf Jul 1, 2024
905dec6
fix link
Torres-ssf Jul 1, 2024
a3b9b49
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jul 1, 2024
7eb6e96
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jul 1, 2024
fa7331d
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
danielbate Jul 2, 2024
a18c3fc
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jul 2, 2024
9e45c0b
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jul 2, 2024
ec370c9
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
danielbate Jul 2, 2024
29109a1
Merge branch 'master' into st/docs/add-cache-utxo-to-provider-section
Torres-ssf Jul 2, 2024
7e0889d
trigger CI
Torres-ssf Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/sour-forks-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

docs: add `Provider` doc section for `cacheUtxo`
10 changes: 10 additions & 0 deletions apps/docs-snippets/src/guide/provider/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ describe('Provider', () => {
// #endregion options-fetch
});

it('options: cacheUtxo', async () => {
// #region options-cache-utxo
const provider = await Provider.create(FUEL_NETWORK_URL, {
cacheUtxo: 5000, // cache UTXO for 5 seconds
});
// #endregion options-cache-utxo

expect(provider).toBeDefined();
});

it('fetches the base asset ID', async () => {
const recipientAddress = Address.fromRandom();

Expand Down
22 changes: 22 additions & 0 deletions apps/docs/src/guide/provider/provider-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ Provide a custom `fetch` function that'll replace the default fetch call.
_Note: If defined, `requestMiddleware`, `timeout` and `retryOptions` are applied to this custom `fetch` function as well._

<<< @/../../docs-snippets/src/guide/provider/provider.test.ts#options-fetch{ts:line-numbers}

### `cacheUtxo`

When using the SDK, it may be necessary to submit multiple transactions from the same account in a short period. In such cases, the SDK creates and funds these transactions, then submits them to the node.

However, if a second transaction is created before the first one is processed, there is a chance of using the same UTXO(s) for both transactions. This happens because the UTXO(s) used in the first transaction are still unspent until the transaction is fully processed.

danielbate marked this conversation as resolved.
Show resolved Hide resolved
If the second transaction attempts to use the same UTXO(s) that the first transaction has already spent, it will result in the following error:

```console
Transaction is not inserted. UTXO does not exist: 0xf5...
```

This error indicates that the UTXO(s) used by the second transaction no longer exist, as the first transaction already spent them.

To prevent this issue, you can use the `cacheUtxo` flag. This flag sets a TTL (Time-To-Live) for caching UTXO(s) used in a transaction, preventing them from being reused in subsequent transactions within the specified time.
maschad marked this conversation as resolved.
Show resolved Hide resolved

<<< @/../../docs-snippets/src/guide/provider/provider.test.ts#options-cache-utxo{ts:line-numbers}

It's important to note that you can only submit multiple transactions from the same account without waiting for the previous transactions to complete if your account has multiple UTXOs available. If you only have one UTXO, the first transaction will spend it, and any remaining amount will be converted into a new UTXO with a different ID.
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved

By ensuring your account has multiple UTXOs, you can effectively use the `cacheUtxo` flag to manage transactions without conflicts.
Loading