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
- Solidity
TypeScript
This script connects to Coston2 and:
- Reads FAssets settings, including FXRP asset decimals.
- Reads the XRP/USD price from the FTSO.
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
{
"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
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
Solidity
Deploy a helper that reads FXRP asset decimals through ContractRegistry, then call it from Hardhat on Coston2.
Prerequisites
- Flare Hardhat Starter Kit
- Flare Network Periphery Contracts
- Node.js, TypeScript, and a Hardhat config with Coston2
Contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
// 1. Import the Flare Contract Registry
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
// 2. Import the AssetManager interface
import {IAssetManager} from "@flarenetwork/flare-periphery-contracts/coston2/IAssetManager.sol";
// 3. Contract for accessing FAssets settings from the asset manager
contract FAssetsSettings {
// 4. Read how many decimal places FXRP uses.
// FAssets Operation Parameters https://dev.flare.network/fassets/operational-parameters
function getAssetDecimals() public view returns (uint8 assetDecimals) {
// 5. Get the AssetManager contract from the Flare Contract Registry
IAssetManager assetManager = ContractRegistry.getAssetManagerFXRP();
// 6. Read asset decimals from the AssetManager settings
assetDecimals = assetManager.getSettings().assetDecimals;
return assetDecimals;
}
}
- Import the ContractRegistry library.
- Import
IAssetManagerfrom@flarenetwork/flare-periphery-contracts. FAssetsSettingsresolves the FXRP Asset Manager and callsgetSettings.getAssetDecimalsreturnsassetDecimals. The full settings list is on FAssets Operational Parameters.
Deploy and read
// yarn hardhat run scripts/fassets/getAssetDecimals.ts --network coston2
const FAssetsSettings = artifacts.require("FAssetsSettings");
async function main() {
const fAssetsSettings = await FAssetsSettings.new();
console.log("FAssetsSettings deployed to:", fAssetsSettings.address);
const assetDecimals = await fAssetsSettings.getAssetDecimals();
console.log("Asset decimals:", assetDecimals.toString());
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
yarn hardhat run scripts/fassets/getAssetDecimals.ts --network coston2
Compiled 1 Solidity file successfully (evm target: cancun).
Deploying FAssetsSettings...
FAssetsSettings deployed to: 0x40deEaA76224Ca9439D4e1c86F827Be829b89D9E
Asset decimals: 6
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.
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.