|
| 1 | +--- |
| 2 | +title: Get FXRP Asset Manager Address |
| 3 | +tags: [intermediate, fassets] |
| 4 | +slug: fassets-asset-manager-address-contracts-registry |
| 5 | +description: Get FXRP asset manager address from the Flare contract registry |
| 6 | +keywords: [fassets, flare-network, fxrp, asset-manager] |
| 7 | +sidebar_position: 1 |
| 8 | +--- |
| 9 | + |
| 10 | +import CodeBlock from "@theme/CodeBlock"; |
| 11 | +import Remix from "@site/src/components/remix"; |
| 12 | +import AssetManagerRegistry from "!!raw-loader!/examples/developer-hub-solidity/FAssetsAssetManagerRegistry.sol"; |
| 13 | +import ExploringAdditionalParameters from "./_exploring-additional-parameters.mdx"; |
| 14 | + |
| 15 | +## Overview |
| 16 | + |
| 17 | +When building on the Flare Network, it is important to **avoid hardcoding contract addresses**, especially for key components such as the FXRP Asset Manager. |
| 18 | +These addresses can change between Flare testnets and mainnet deployments, and relying on fixed values can lead to broken integrations. |
| 19 | + |
| 20 | +Instead, you should dynamically fetch the FXRP Asset Manager address using the [Flare Contract Registry](/network/guides/flare-contracts-registry), the trusted source for obtaining contract addresses on any Flare network. |
| 21 | + |
| 22 | +In this guide, you will learn: |
| 23 | + |
| 24 | +- How to retrieve the [Asset Manager Controller](/fassets/reference/IAssetManagerController) using the Flare Contract Registry. |
| 25 | +- How to find the specific FXRP [Asset Manager](/fassets/reference/IAssetManager). |
| 26 | +- A sample Solidity contract that encapsulates this logic. |
| 27 | + |
| 28 | +## Sample code |
| 29 | + |
| 30 | +To get the [FAssets asset manager](/fassets/reference/IAssetManager) address, you can use the following smart contract that retrieves the [Asset Manager Controller](/fassets/reference/IAssetManagerController) address from the [Flare contract registry](/network/guides/flare-contracts-registry). |
| 31 | + |
| 32 | +<CodeBlock language="solidity" title="contracts/AssetManagerRegistry.sol"> |
| 33 | + {AssetManagerRegistry} |
| 34 | +</CodeBlock> |
| 35 | + |
| 36 | +{/* prettier-ignore */} |
| 37 | +<Remix fileName="FAssetsAssetManagerRegistry.sol">Open in Remix</Remix> |
| 38 | +<br></br> |
| 39 | + |
| 40 | +### Contract Breakdown |
| 41 | + |
| 42 | +1. Imports the necessary interfaces and libraries from the [Flare Periphery Contracts package](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contracts). |
| 43 | +2. Defines a constant `TXRP_HASH` that is the hash of the string `TXRP`. |
| 44 | + This is used to identify the FXRP asset manager. |
| 45 | +3. Implements a function `getFxrpAssetManager` that returns the FXRP [Asset Manager](/fassets/reference/IAssetManager) address. |
| 46 | +4. Uses the `ContractRegistry` library from the Flare Periphery Contracts package to get the [Asset Manager Controller](/fassets/reference/IAssetManagerController) address from the Flare contract registry. |
| 47 | +5. Uses the `IAssetManagerController` interface from the Flare Periphery Contracts package to get all the asset managers from the Asset Manager Controller. |
| 48 | +6. Iterates over the asset managers and returns the FXRP Asset Manager address. |
| 49 | +7. Gets the settings of the asset manager. |
| 50 | +8. Checks if the pool token suffix is `TXRP` and if true returns the FXRP Asset Manager address. |
| 51 | + |
| 52 | +You can find out this sample code in the [Flare starter kit](/network/guides/hardhat-foundry-starter-kit). |
| 53 | + |
| 54 | +:::tip Reusable Library |
| 55 | + |
| 56 | +To reuse this code to get the FXRP Asset Manager address in other smart contracts, you can wrap it in a reusable library. |
| 57 | +This is useful if you want to use the FXRP Asset Manager address in multiple smart contracts and avoid repeating the same code. |
| 58 | + |
| 59 | +::: |
| 60 | + |
| 61 | +## Next Steps |
| 62 | + |
| 63 | +In this guide, you learned how to get the FXRP Asset Manager address for the FAssets system by interacting with the `AssetManager` contract using the [`IAssetManager`](/fassets/reference/IAssetManager) interface. |
| 64 | + |
| 65 | +You should not hardcode the FXRP Asset Manager address in your smart contracts. |
| 66 | + |
| 67 | +To continue your FAssets development journey, you can: |
| 68 | + |
| 69 | +- Learn how to [mint FXRP](/fassets/developer-guides/fassets-mint). |
| 70 | +- Understand how to [redeem FXRP](/fassets/developer-guides/fassets-redeem). |
| 71 | +- Explore [FAssets system settings](/fassets/operational-parameters). |
0 commit comments