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

Work with FAssets Agents

Agents hold collateral and pay redemptions. These examples use the FXRP Asset Manager on Coston2.

List agents​

AssetManager exposes three list functions:

Public Core Vault minting does not ask the user to pick an agent. These lists are for agent UIs, monitoring, and the archived collateral-reservation flow.

Each function takes _start and _end and returns _agents plus _totalLength. _start is inclusive and _end is exclusive. getAllAgents(0, 3) returns agents at indexes 0, 1, and 2.

Prerequisites​

Script​

Fetch available agents in chunks so a long list does not time out the RPC.

scripts/fassets/listAgents.ts
import { getAssetManagerFXRP } from "../utils/getters";

/**
* Script to list all available FAssets agents in chunks
*
* This script demonstrates how to iterate through all agents in the FAssets system
* by fetching them in chunks to avoid overwhelming the RPC endpoint with large requests.
*
* Run with: yarn hardhat run scripts/fassets/listAgents.ts --network coston2
*/

async function main() {
// 1. Get the FAssets FXRP asset manager contract instance
const assetManager = await getAssetManagerFXRP();

// 2. Define how many agents to fetch per request
// Using smaller chunks (e.g., 3) helps avoid RPC timeout issues
const chunkSize = 3;

// 3. Fetch the first chunk and get the total count
// The _totalLength property tells us how many agents exist in total
console.log("Fetching first chunk with offset 0 and chunk size " + chunkSize);
const firstChunk = await assetManager.getAvailableAgentsList(0, chunkSize);
console.log(firstChunk._agents);

const totalLength = Number(BigInt(firstChunk._totalLength).toString());
console.log(`Total number of agents: ${totalLength}`);

// 4. Iterate through remaining agents in chunks
// The getAvailableAgentsDetailedList(start, end) function uses:
// - start: inclusive start index (0-based)
// - end: exclusive end index (like array slicing)
// Example: (0, 3) returns agents at indices 0, 1, 2
for (let offset = chunkSize; offset < totalLength; offset += chunkSize) {
// Calculate end index, ensuring we don't exceed totalLength
const endIndex = Math.min(offset + chunkSize, totalLength);
console.log(
`\n--- Fetching agents ${offset} to ${endIndex - 1} (end index ${endIndex} exclusive) ---`,
);

// Fetch the chunk of agents
const agents = await assetManager.getAvailableAgentsList(offset, endIndex);
console.log(agents._agents);
}

console.log(`\nCompleted processing all ${totalLength} agents`);
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
  1. Resolve the FXRP Asset Manager with getAssetManagerFXRP() from the periphery package.
  2. Set chunkSize to 3. Raise or lower it for your RPC.
  3. Call getAvailableAgentsList(0, chunkSize). _totalLength is the full count.
  4. Walk the rest of the list from offset = chunkSize, with endIndex = min(offset + chunkSize, totalLength).

The same paging works for getAllAgents and getAvailableAgentsDetailedList.

yarn hardhat run scripts/fassets/listAgents.ts --network coston2

Read agent details​

AgentOwnerRegistry stores the public profile for an agent's management address:

The registry address is getSettings().agentOwnerRegistry on the Asset Manager.

import {IAssetManager} from "@flarenetwork/flare-periphery-contracts/coston2/IAssetManager.sol";
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
import {IAgentOwnerRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/IAgentOwnerRegistry.sol";

IAssetManager assetManager = ContractRegistry.getAssetManagerFXRP();
IAgentOwnerRegistry registry = IAgentOwnerRegistry(
assetManager.getSettings().agentOwnerRegistry
);
function getAgentDetails(address _managementAddress)
external
view
returns (
string memory name,
string memory description,
string memory iconUrl,
string memory termsOfUseUrl
)
{
IAssetManager assetManager = ContractRegistry.getAssetManagerFXRP();
IAgentOwnerRegistry registry = IAgentOwnerRegistry(
assetManager.getSettings().agentOwnerRegistry
);

name = registry.getAgentName(_managementAddress);
description = registry.getAgentDescription(_managementAddress);
iconUrl = registry.getAgentIconUrl(_managementAddress);
termsOfUseUrl = registry.getAgentTermsOfUseUrl(_managementAddress);
}

The Flare Hardhat Starter Kit includes a full example.