Skip to content

Commit b73e27e

Browse files
authored
fix(docs): update FAssets settings Node guide (#887)
1 parent cf2d1b6 commit b73e27e

File tree

1 file changed

+74
-55
lines changed

1 file changed

+74
-55
lines changed

docs/fassets/developer-guides/4-fassets-settings-node.mdx

Lines changed: 74 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ExploringAdditionalParameters from "./_exploring-additional-parameters.md
1111

1212
## Overview
1313

14-
In this guide, you will build a TypeScript script that connects to the [Songbird Testnet Coston](/network/solidity-reference) and:
14+
In this guide, you will build a TypeScript script that connects to the [Flare Testnet Coston2](/network/solidity-reference) and:
1515

1616
- Fetches [FAssets configuration settings](/fassets/operational-parameters) and gets the [lot size](/fassets/minting#lots) for FXRP
1717
- Retrieves the XRP/USD price from the [FTSO](/ftso/overview)
@@ -87,13 +87,13 @@ For convenience, add the Typescript build and type generation commands to the `s
8787
```json
8888
"scripts": {
8989
"build": "tsc",
90-
"generate-types": "typechain --target ethers-v6 --out-dir typechain './node_modules/@flarenetwork/flare-periphery-contract-artifacts/coston/artifacts/contracts/**/*.json'"
90+
"generate-types": "typechain --target ethers-v6 --out-dir typechain './node_modules/@flarenetwork/flare-periphery-contract-artifacts/coston2/artifacts/contracts/**/*.json'"
9191
}
9292
```
9393

9494
The `build` script will compile the TypeScript code.
9595

96-
Using the Coston network artifacts, the `typechain` generates TypeScript types from the Flare Periphery contracts, which are provided through a [package](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contract-artifacts) containing the necessary contract artifacts.
96+
Using the Coston2 network artifacts, the `typechain` generates TypeScript types from the Flare Periphery contracts, which are provided through a [package](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contract-artifacts) containing the necessary contract artifacts.
9797

9898
Change the `package.json` file to use the `module` type to use ES modules and avoid issues with the `import` statement:
9999

@@ -109,7 +109,7 @@ To generate the TypeScript types, run the following command:
109109
npm run generate-types
110110
```
111111

112-
It will generate the types TypeScript types in the `typechain` directory.
112+
It will generate the TypeScript types in the `typechain` directory.
113113

114114
## Implementation
115115

@@ -132,49 +132,58 @@ Import the ethers library to interact with the blockchain:
132132
import { ethers } from "ethers";
133133
```
134134

135-
You need to import the FAssets asset manager contract factory type:
135+
You need to import the [Flare Contracts Registry](/network/guides/flare-contracts-registry) and the [FAssets asset manager](/fassets/reference/IAssetManager) contract factory types:
136136

137137
```typescript
138138
import { IAssetManager__factory } from "../typechain/factories/IAssetManager__factory.js";
139+
import { IFlareContractRegistry__factory } from "../typechain/factories/IFlareContractRegistry__factory.js";
139140
```
140141

141142
### Define Constants
142143

143144
Define two constants:
144145

145-
- `COSTON_RPC_URL`: The RPC URL for the Coston network.
146-
- `ASSET_MANAGER_ADDRESS`: The address of the FAssets asset manager contract. In this case, it is the XRP asset manager address on the Coston network.
146+
- `COSTON2_RPC_URL`: The RPC URL for the Coston2 network.
147+
- `FLARE_CONTRACT_REGISTRY_ADDRESS`: The address of the [Flare Contract Registry](/network/guides/flare-contracts-registry).
147148

148149
```typescript
149-
const COSTON_RPC = "https://coston-api.flare.network/ext/C/rpc";
150-
const ASSET_MANAGER_ADDRESS = "0xeEd82b8390880af0b6Cb6Dd398a7E361cc30E8e2";
150+
const COSTON2_RPC = "https://coston-api.flare.network/ext/C/rpc";
151+
const FLARE_CONTRACT_REGISTRY_ADDRESS =
152+
"0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019";
151153
```
152154

153-
### Implement Settings Retrieval
155+
### Get the FAssets FXRP Asset Manager Address
154156

155-
Next, you need to create an asynchronous function that will fetch the FAssets configuration settings and call in the script.
157+
You can get the FAssets FXRP Asset Manager address by calling the `getAssetManagerFXRP` function of the Flare Contract Registry.
158+
After that, create a new ethers provider, connect to the Coston2 network, and connect to the FAssets asset manager contract.
156159

157-
Inside the `getSettings` function, you create a new ethers provider, connect to the Coston network, and connect to the FAssets asset manager contract.
160+
```typescript
161+
const provider = new ethers.JsonRpcProvider(COSTON2_RPC);
158162

159-
After that, you must fetch the FAssets configuration settings using the [`getSettings`](/fassets/reference/IAssetManager#getsettings) function of the FAssets asset manager contract.
163+
const flareContractRegistry = IFlareContractRegistry__factory.connect(
164+
FLARE_CONTRACT_REGISTRY_ADDRESS,
165+
provider,
166+
);
160167

161-
The last step is to get the lot size of FXRP in XRP and print it to the console.
168+
const assetManagerAddress =
169+
await flareContractRegistry.getContractAddressByName("AssetManagerFXRP");
170+
const assetManager = IAssetManager__factory.connect(
171+
assetManagerAddress,
172+
provider,
173+
);
174+
```
162175

163-
```typescript title="scripts/fassets-settings.ts"
164-
async function getSettings() {
165-
const provider = new ethers.JsonRpcProvider(COSTON_RPC);
166-
const assetManager = IAssetManager__factory.connect(
167-
ASSET_MANAGER_ADDRESS,
168-
provider,
169-
);
176+
### Implement Settings Retrieval
170177

171-
const settings = await assetManager.getSettings();
172-
const lotSizeFXRP =
173-
Number(settings.lotSizeAMG) / Math.pow(10, Number(settings.assetDecimals));
174-
console.log("Lot Size (FXRP):", lotSizeFXRP);
175-
}
178+
Next, you must fetch the FAssets configuration settings using the [`getSettings`](/fassets/reference/IAssetManager#getsettings) function of the FAssets asset manager contract.
176179

177-
getSettings();
180+
The last step is to get the lot size of FXRP in XRP and print it to the console.
181+
182+
```typescript
183+
const settings = await assetManager.getSettings();
184+
const lotSizeFXRP =
185+
Number(settings.lotSizeAMG) / Math.pow(10, Number(settings.assetDecimals));
186+
console.log("Lot Size (FXRP):", lotSizeFXRP);
178187
```
179188

180189
:::info
@@ -187,19 +196,17 @@ To convert the lot size to USD you need to use the [FTSO](/ftso/overview) to get
187196

188197
### Import Dependencies
189198

190-
Import the `IFlareContractRegistry__factory` and `FtsoV2Interface__factory` types which are the factories for the [Flare Contract Registry](/network/solidity-reference/IFlareContractRegistry) and the [FTSO contracts](/ftso/solidity-reference/FtsoV2Interface).
199+
Import the `FtsoV2Interface__factory` type which is the factories for the [FTSO contracts](/ftso/solidity-reference/FtsoV2Interface).
191200

192201
```typescript
193-
import { IFlareContractRegistry__factory } from "../typechain/factories/IFlareContractRegistry__factory.js";
194202
import { FtsoV2Interface__factory } from "../typechain/factories/FtsoV2Interface__factory.js";
195203
```
196204

197205
### Define Constants
198206

199-
Define the constants for the [registry address](/network/guides/flare-for-javascript-developers#querying-a-contract) and the [XRP/USD feed ID](/ftso/scaling/anchor-feeds).
207+
Define the constants for the [XRP/USD feed ID](/ftso/scaling/anchor-feeds).
200208

201209
```typescript
202-
const REGISTRY_ADDRESS = "0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019";
203210
const XRP_USD_FEED_ID = "0x015852502f55534400000000000000000000000000";
204211
```
205212

@@ -209,17 +216,18 @@ You can get the price feed XRP/USD by calling the [`getFeedById`](/ftso/solidity
209216

210217
```typescript
211218
const registry = IFlareContractRegistry__factory.connect(
212-
REGISTRY_ADDRESS,
219+
FLARE_CONTRACT_REGISTRY_ADDRESS,
213220
provider,
214221
);
215-
const ftsoAddress = await registry.getContractAddressByName("FtsoV2");
222+
const ftsoAddress =
223+
await flareContractRegistry.getContractAddressByName("FtsoV2");
216224
const ftsoV2 = FtsoV2Interface__factory.connect(ftsoAddress, provider);
217225
const priceFeed = await ftsoV2.getFeedById.staticCall(XRP_USD_FEED_ID);
218226
```
219227

220228
### Convert Lot Size to USD
221229

222-
Convert the lot size to USD, by multiplying the lot size by the price of XRP in USD.
230+
Convert the lot size to USD by multiplying the lot size by the price of XRP in USD.
223231

224232
```typescript
225233
const xrpUsdPrice = Number(priceFeed[0]) / Math.pow(10, Number(priceFeed[1]));
@@ -232,29 +240,38 @@ console.log("Timestamp:", priceFeed[2].toString());
232240

233241
## Putting All Together
234242

235-
To put all together you have the following code:
243+
To put all together, you have the following code:
236244

237-
```typescript
245+
```typescript title="scripts/fassets-settings.ts"
238246
// Importing necessary modules and contract factories
239247
import { ethers } from "ethers";
240-
241248
import { IAssetManager__factory } from "../typechain/factories/IAssetManager__factory.js";
242249
import { IFlareContractRegistry__factory } from "../typechain/factories/IFlareContractRegistry__factory.js";
243250
import { FtsoV2Interface__factory } from "../typechain/factories/FtsoV2Interface__factory.js";
244251

245252
// Constants for RPC endpoint and contract addresses
246-
const COSTON_RPC = "https://coston-api.flare.network/ext/C/rpc"; // RPC URL for the Coston network
247-
const ASSET_MANAGER_ADDRESS = "0xeEd82b8390880af0b6Cb6Dd398a7E361cc30E8e2"; // Address of the Asset Manager contract
248-
const REGISTRY_ADDRESS = "0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019"; // Address of the Flare Contract Registry
253+
const COSTON2_RPC = "https://coston2-api.flare.network/ext/C/rpc"; // RPC URL for the Coston2 network
254+
const FLARE_CONTRACT_REGISTRY_ADDRESS =
255+
"0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019"; // Address of the Flare Contract Registry
249256
const XRP_USD_FEED_ID = "0x015852502f55534400000000000000000000000000"; // Feed ID for XRP/USD price https://dev.flare.network/ftso/scaling/anchor-feeds
250257

251258
async function getSettings() {
252259
// Create a provider for interacting with the blockchain
253-
const provider = new ethers.JsonRpcProvider(COSTON_RPC);
260+
const provider = new ethers.JsonRpcProvider(COSTON2_RPC);
261+
262+
// Connect to the Flare Contract Registry
263+
const flareContractRegistry = IFlareContractRegistry__factory.connect(
264+
FLARE_CONTRACT_REGISTRY_ADDRESS,
265+
provider,
266+
);
267+
268+
// Get the address of the FXRP Asset Manager
269+
const assetManagerAddress =
270+
await flareContractRegistry.getContractAddressByName("AssetManagerFXRP");
254271

255-
// Connect to the Asset Manager contract
272+
// Connect to the FXRP Asset Manager
256273
const assetManager = IAssetManager__factory.connect(
257-
ASSET_MANAGER_ADDRESS,
274+
assetManagerAddress,
258275
provider,
259276
);
260277

@@ -266,14 +283,9 @@ async function getSettings() {
266283
Number(settings.lotSizeAMG) / Math.pow(10, Number(settings.assetDecimals));
267284
console.log("Lot Size (FXRP):", lotSizeFXRP);
268285

269-
// Connect to the Flare Contract Registry
270-
const registry = IFlareContractRegistry__factory.connect(
271-
REGISTRY_ADDRESS,
272-
provider,
273-
);
274-
275286
// Fetch the address of the FtsoV2 contract from the registry
276-
const ftsoAddress = await registry.getContractAddressByName("FtsoV2");
287+
const ftsoAddress =
288+
await flareContractRegistry.getContractAddressByName("FtsoV2");
277289

278290
// Connect to the FtsoV2 contract
279291
const ftsoV2 = FtsoV2Interface__factory.connect(ftsoAddress, provider);
@@ -305,12 +317,19 @@ node dist/scripts/fassets-settings.js
305317
You should see the following output:
306318

307319
```bash
308-
Lot Size (FXRP): 20
309-
XRP/USD Price: 2.1346
310-
Lot value in USD: 42.69199999999999
311-
Timestamp: 1743513507
320+
Lot Size (FXRP): 10
321+
XRP/USD Price: 2.843861
322+
Lot value in USD: 28.43861
323+
Timestamp: 1756977702
312324
```
313325

314-
Congratulations! You have built a TypeScript script that connects to the Coston network and retrieves the FAsset configuration settings and the price of XRP in USD.
326+
Congratulations! You have built a TypeScript script that connects to the Coston2 network and retrieves the FAsset configuration settings and the price of XRP in USD.
315327

316328
<ExploringAdditionalParameters />
329+
330+
## Next Steps
331+
332+
To continue your FAssets development journey, you can:
333+
334+
- Learn how to [mint FXRP](/fassets/developer-guides/fassets-mint).
335+
- Understand how to [redeem FXRP](/fassets/developer-guides/fassets-redeem).

0 commit comments

Comments
 (0)