Agent documentation index: llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Skip to main content

Read FAssets Settings

Read FXRP settings from getSettings on AssetManagerFXRP. Examples below use Coston2.

The TypeScript tab calls the Asset Manager with viem and reads the XRP/USD price from the FTSO. The Solidity tab deploys a helper that reads the same asset decimals.

Resolve the Asset Manager from the registry first. See Resolve Asset Manager and FXRP.

TypeScript​

This script connects to Coston2 and:

Prerequisites​

Project setup​

Create a directory and initialize npm:

mkdir fassets-settings-ftso
cd fassets-settings-ftso
npm init -y

Install the dependencies:

npm install --save-dev \
typescript \
viem \
@flarenetwork/flare-wagmi-periphery-package

Create tsconfig.json:

npx tsc --init
tsconfig.json
{
"compilerOptions": {
"rootDir": "./scripts",
"outDir": "./dist",
"module": "esnext",
"moduleResolution": "node",
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"types": ["node"],
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": ["scripts/**/*.ts"],
"exclude": ["node_modules"]
}

In package.json, use ES modules and add a build script:

"type": "module",
"scripts": {
"build": "tsc"
}

Script​

mkdir scripts
touch scripts/fassets-settings.ts

Import viem and the coston2 namespace from @flarenetwork/flare-wagmi-periphery-package:

import { createPublicClient, http } from "viem";
import { flareTestnet } from "viem/chains";
import { coston2 } from "@flarenetwork/flare-wagmi-periphery-package";
const FLARE_CONTRACT_REGISTRY_ADDRESS =
"0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019" as const;
const XRP_USD_FEED_ID = "0x015852502f55534400000000000000000000000000" as const;
const client = createPublicClient({
chain: flareTestnet,
transport: http(),
});

Resolve AssetManagerFXRP from the Flare Contract Registry:

const assetManagerAddress = await client.readContract({
address: FLARE_CONTRACT_REGISTRY_ADDRESS,
abi: coston2.iFlareContractRegistryAbi,
functionName: "getContractAddressByName",
args: ["AssetManagerFXRP"],
});

Read getSettings and log the asset decimals:

const settings = await client.readContract({
address: assetManagerAddress,
abi: coston2.iAssetManagerAbi,
functionName: "getSettings",
});

console.log("Asset decimals:", settings.assetDecimals);

The same call returns the rest of the operational parameters.

Read the XRP/USD price​

Read the XRP/USD anchor feed from FTSO.

const ftsoAddress = await client.readContract({
address: FLARE_CONTRACT_REGISTRY_ADDRESS,
abi: coston2.iFlareContractRegistryAbi,
functionName: "getContractAddressByName",
args: ["FtsoV2"],
});

getFeedById is payable, so use simulateContract:

const {
result: [_value, _decimals, _timestamp],
} = await client.simulateContract({
address: ftsoAddress,
abi: coston2.ftsoV2InterfaceAbi,
functionName: "getFeedById",
args: [XRP_USD_FEED_ID],
value: 0n,
});
const xrpUsdPrice = Number(_value) / Math.pow(10, Number(_decimals));

console.log("XRP/USD Price:", xrpUsdPrice);
console.log("Timestamp:", _timestamp.toString());

Full script​

scripts/fassets-settings.ts
import { createPublicClient, http } from "viem";
import { flareTestnet } from "viem/chains";
import { coston2 } from "@flarenetwork/flare-wagmi-periphery-package";

const FLARE_CONTRACT_REGISTRY_ADDRESS =
"0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019" as const;
const XRP_USD_FEED_ID = "0x015852502f55534400000000000000000000000000" as const;

const client = createPublicClient({
chain: flareTestnet,
transport: http(),
});

const assetManagerAddress = await client.readContract({
address: FLARE_CONTRACT_REGISTRY_ADDRESS,
abi: coston2.iFlareContractRegistryAbi,
functionName: "getContractAddressByName",
args: ["AssetManagerFXRP"],
});

const settings = await client.readContract({
address: assetManagerAddress,
abi: coston2.iAssetManagerAbi,
functionName: "getSettings",
});

console.log("Asset decimals:", settings.assetDecimals);

const ftsoAddress = await client.readContract({
address: FLARE_CONTRACT_REGISTRY_ADDRESS,
abi: coston2.iFlareContractRegistryAbi,
functionName: "getContractAddressByName",
args: ["FtsoV2"],
});

const {
result: [_value, _decimals, _timestamp],
} = await client.simulateContract({
address: ftsoAddress,
abi: coston2.ftsoV2InterfaceAbi,
functionName: "getFeedById",
args: [XRP_USD_FEED_ID],
value: 0n,
});

const xrpUsdPrice = Number(_value) / Math.pow(10, Number(_decimals));

console.log("XRP/USD Price:", xrpUsdPrice);
console.log("Timestamp:", _timestamp.toString());

Run​

npm run build
node dist/fassets-settings.js
Asset decimals: 6
XRP/USD Price: 2.843861
Timestamp: 1756977702

Exploring Additional Parameters​

The FAssets asset manager exposes key parameters like collateral ratios, minting fees, and liquidation thresholds via the getSettings function. See the FAssets Operational Parameters for details.

FAssets demo dApp

The FAssets demo dApp showcases the FAssets system using the Flare wagmi periphery package. This app is a Next.js reference implementation for settings, minting, tags, transfer, and redeem functionality.

The source code is available in the fassets-demo-dapp repository.