-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@fuel-ts/utils": patch | ||
--- | ||
|
||
chore: integrate vitest matchers globally |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
--- | ||
|
||
docs: add docs for splitting UTXOs, `maxOutputs` and `maxInputs` |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// #region max-outputs | ||
import { Provider } from 'fuels'; | ||
|
||
import { LOCAL_NETWORK_URL } from '../../../env'; | ||
|
||
const provider = await Provider.create(LOCAL_NETWORK_URL); | ||
|
||
const { maxInputs, maxOutputs } = | ||
provider.getChain().consensusParameters.txParameters; | ||
|
||
// #endregion max-outputs | ||
console.log('Max Inputs', maxInputs); | ||
console.log('Max Outputs', maxOutputs); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// #region splitting-utxos | ||
import { Provider, Wallet } from 'fuels'; | ||
|
||
import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; | ||
|
||
const provider = await Provider.create(LOCAL_NETWORK_URL); | ||
// This is the wallet that will fund the sending wallet | ||
const fundingWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); | ||
|
||
// This is the wallet that will send the funds | ||
const wallet = Wallet.generate({ provider }); | ||
// This is the wallet that will receive the funds | ||
const destinationWallet = Wallet.generate({ provider }); | ||
|
||
// Let's fund the sending wallet with 1000 of the base asset | ||
const fundingTx = await fundingWallet.transfer( | ||
wallet.address, | ||
1000, | ||
provider.getBaseAssetId() | ||
); | ||
await fundingTx.waitForResult(); | ||
|
||
// We can fetch the coins to see how many UTXOs we have and confirm it is 1 | ||
const { coins: initialCoins } = await wallet.getCoins( | ||
provider.getBaseAssetId() | ||
); | ||
console.log('Initial Coins Length', initialCoins.length); | ||
// 1 | ||
|
||
// Now we can split the large 1000 UTXO into 5 UTXOs of 200 each, | ||
// Including the address to send the funds to and the assetId we want to send | ||
const splitTxns = new Array(5).fill({ | ||
amount: 200, | ||
assetId: provider.getBaseAssetId(), | ||
destination: destinationWallet.address, | ||
}); | ||
|
||
// We will also need add some funds to the wallet to cover the fee | ||
// We could have also spent less than 200 for each UTXO, but this is just an example | ||
const fundTx = await fundingWallet.transfer( | ||
wallet.address, | ||
500, | ||
provider.getBaseAssetId() | ||
); | ||
await fundTx.waitForResult(); | ||
|
||
console.log('Split UTXOs', splitTxns); | ||
// [ | ||
// { amount: 200, assetId: '0x0', destination : '0x...' }, | ||
// { amount: 200, assetId: '0x0', destination: '0x...' }, | ||
// { amount: 200, assetId: '0x0', destination: '0x...' }, | ||
// { amount: 200, assetId: '0x0', destination: '0x...' }, | ||
// { amount: 200, assetId: '0x0', destination: '0x...' } | ||
// ] | ||
|
||
// Then we can send the transactions using the batchTransfer function | ||
const batchTx = await wallet.batchTransfer(splitTxns); | ||
await batchTx.waitForResult(); | ||
// #endregion splitting-utxos |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Splitting UTXOs | ||
|
||
There may be times when you want to split one large UTXO into multiple smaller UTXOs. This can be useful if you want to send multiple concurrent transactions without having to wait for them to be processed sequentially. | ||
|
||
> **Note:** Depending on how many smaller UTXOs you want to create, you may need to fund the wallet with additional funds to cover the fees. As we see in the example below, we fund the sending wallet with 500 to cover the fees for the batch transfer. | ||
<<< @./snippets/splitting-utxos.ts#splitting-utxos{ts:line-numbers} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# Checking balances | ||
|
||
To check the balance of a specific asset, you can use [`getBalance`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_account.Account.html#getbalance) method. This function aggregates the amounts of all unspent coins of the given asset in your wallet. | ||
To check the balance of a specific asset, you can use [`getBalance`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_account.Account.html#getBalance) method. This function aggregates the amounts of all unspent coins of the given asset in your wallet. | ||
|
||
<<< @./snippets/checking-balances.ts#checking-balances-1{ts:line-numbers} | ||
|
||
To retrieve the balances of all assets in your wallet, use the [`getBalances`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_account.Account.html#getbalances) method, it returns an array of [`CoinQuantity`](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_account.html#coinquantity). This is useful for getting a comprehensive view of your holdings. | ||
To retrieve the balances of all assets in your wallet, use the [`getBalances`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_account.Account.html#getBalances) method, it returns an array of [`CoinQuantity`](https://fuels-ts-docs-api.vercel.app/types/_fuel_ts_account.CoinQuantity.html). This is useful for getting a comprehensive view of your holdings. | ||
|
||
<<< @./snippets/checking-balances-two.ts#checking-balances-2{ts:line-numbers} |