Skip to content

Commit

Permalink
docs: added assets guide (#3189)
Browse files Browse the repository at this point in the history
* docs: added asset docs

* chore: changeset

* chore: lint

* docs: added further docs
  • Loading branch information
petertonysmith94 authored Sep 20, 2024
1 parent 48db506 commit 8930417
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changeset/serious-carrots-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

docs: added assets guide
39 changes: 39 additions & 0 deletions apps/docs-snippets/src/guide/utilities/using-assets.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { Asset, AssetFuel } from 'fuels';
import { assets, CHAIN_IDS, getAssetFuel, Wallet } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

/**
* @group node
* @group browser
*/
describe('using-assets', () => {
it('should be able to use `getAssetFuel`', async () => {
using launched = await launchTestNode();
const {
provider,
wallets: [sender],
} = launched;

// #region using-assets-1
// #import { Wallet, Asset, AssetFuel, assets, getAssetFuel };

const recipient = Wallet.generate({ provider });

// Find the asset with symbol 'ETH'
const assetEth: Asset = assets.find((asset) => asset.symbol === 'ETH')!;

// Get all the metadata for ETH on Fuel Test Network
const chainId: number = CHAIN_IDS.fuel.testnet;
const assetEthOnFuel: AssetFuel = getAssetFuel(assetEth, chainId)!;

// Send a transaction (using the asset on Fuel Test Network)
const transaction = await sender.transfer(recipient.address, 100, assetEthOnFuel.assetId);
const result = await transaction.waitForResult();
// #endregion using-assets-1

expect(result.isStatusSuccess).toBe(true);
expect(assetEthOnFuel).toBeDefined();
expect(assetEthOnFuel).toBeDefined();
});
});
4 changes: 4 additions & 0 deletions apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ export default defineConfig({
text: 'Unit conversion',
link: '/guide/utilities/unit-conversion',
},
{
text: 'Using assets',
link: '/guide/utilities/using-assets',
},
],
},
{
Expand Down
6 changes: 5 additions & 1 deletion apps/docs/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,8 @@ incentivise
URI
walletsConfig
reuploaded
Vite
Vite
USDT
USD
USDC
WETH
14 changes: 14 additions & 0 deletions apps/docs/src/guide/utilities/using-assets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Assets

We export an array of [`Asset`](https://docs.fuel.network/docs/fuels-ts/account/#asset) objects, that can be useful when creating your dApp. The `Asset` object has useful metadata about the different assets that are available on blockchain networks (Fuel and Ethereum).

Included assets such as:

- Ethereum (ETH)
- Tether (USDT)
- USD Coin (USDC)
- Wrapped ETH (WETH)

The helper functions `getAssetFuel` and `getAssetEth` can be used to get an asset's details relative to each network. These return a combination of the asset, and network information (the return types are [`AssetFuel`](../../api/Account/index.md#assetfuel) and [`AssetEth`](../../api/Account/index.md#asseteth) respectively).

<<< @/../../docs-snippets/src/guide/utilities/using-assets.test.ts#using-assets-1{ts:line-numbers}

0 comments on commit 8930417

Please sign in to comment.