|
| 1 | +--- |
| 2 | +title: Mint FAssets |
| 3 | +tags: [intermediate, fassets] |
| 4 | +slug: fassets-mint |
| 5 | +description: Learn how to mint FAssets |
| 6 | +keywords: [fassets, flare-network] |
| 7 | +sidebar_position: 3 |
| 8 | +--- |
| 9 | + |
| 10 | +import CodeBlock from "@theme/CodeBlock"; |
| 11 | +import Remix from "@site/src/components/remix"; |
| 12 | +import FAssetsReserveCollateral from "!!raw-loader!/examples/developer-hub-javascript/fassetsReserveCollateral.ts"; |
| 13 | +import FAssetsCreateXrpPayment from "!!raw-loader!/examples/developer-hub-javascript/fassetsCreateXrpPayment.ts"; |
| 14 | +import FAssetsExecuteMinting from "!!raw-loader!/examples/developer-hub-javascript/fassetsExecuteMinting.ts"; |
| 15 | + |
| 16 | +## Overview |
| 17 | + |
| 18 | +This guide walks you through the complete process of minting FAssets (e.g., FXRP) on the Flare network. |
| 19 | + |
| 20 | +Minting FAssets is the process of wrapping, for instance, XRP from the XRP Ledger into an FAsset, enabling it to be used within the Flare blockchain ecosystem. |
| 21 | + |
| 22 | +See the [Minting](/fassets/minting) overview for more details. |
| 23 | + |
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +- [Flare Hardhat Starter Kit](/network/guides/hardhat-foundry-starter-kit) |
| 27 | +- [Flare Network Periphery Contracts](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contracts) |
| 28 | + |
| 29 | +## Minting Process Steps |
| 30 | + |
| 31 | +The minting process is a multi-step process that involves the following steps: |
| 32 | + |
| 33 | +1. Reserve collateral from a suitable agent. |
| 34 | +2. Send the underlying asset (e.g., XRP) to the agent. |
| 35 | +3. Use [Flare Data Connector (FDC)](/fdc/overview) to generate proof of payment. |
| 36 | +4. Execute minting with the proof to receive FAssets. |
| 37 | + |
| 38 | +## Reserve Collateral |
| 39 | + |
| 40 | +The following code demonstrates how to reserve collateral by calling the [`reserveCollateral()`](/fassets/reference/IAssetManager#reservecollateral) function on the AssetManager contract. |
| 41 | + |
| 42 | +<CodeBlock language="typescript" title="scripts/fassets/reserveCollateral.ts"> |
| 43 | + {FAssetsReserveCollateral} |
| 44 | +</CodeBlock> |
| 45 | + |
| 46 | +### Collateral Reservation Script Breakdown |
| 47 | + |
| 48 | +1. Define constants |
| 49 | + |
| 50 | +- `ASSET_MANAGER_ADDRESS`: FXRP AssetManager address on Songbird Testnet (Coston). |
| 51 | +- `LOTS_TO_MINT`: Number of FAsset lots to reserve. |
| 52 | +- `UNDERLYING_ADDRESS`: Target XRP Ledger address for the minted asset. |
| 53 | +- `ZERO_ADDRESS`: Placeholder for `executor` (not used in this script). |
| 54 | + |
| 55 | +2. Retrieve and filter agents with enough free collateral and select the agent with the lowest fee and normal status. |
| 56 | +3. Parse [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event. |
| 57 | +4. Start the minting reservation process at the script's entry point. |
| 58 | +5. Call `findBestAgent()` with the required number of lots. |
| 59 | +6. Fetch agent metadata from [`getAgentInfo()`](/fassets/reference/IAssetManager#getagentinfo) to get the agent's `feeBIPS`, which is used to calculate the collateral reservation fee. |
| 60 | +7. Calculate the collateral reservation fee by calling [`collateralReservationFee()`](/fassets/reference/IAssetManager#collateralreservationfee). |
| 61 | +8. Reserve collateral from agent by calling [`reserveCollateral()`](/fassets/reference/IAssetManager#reservecollateral) |
| 62 | +9. Call `assetMintingDecimals()` to determine the XRP token's decimal precision. |
| 63 | +10. Parse the [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event. |
| 64 | +11. Calculate the total XRP value required for payment. |
| 65 | + |
| 66 | +## Send Payment on XRP Ledger |
| 67 | + |
| 68 | +The next step is to send the XRP Ledger payment to the agent, and you can use this script to do that. |
| 69 | + |
| 70 | +<CodeBlock language="typescript" title="scripts/fassets/xrpPayment.ts"> |
| 71 | + {FAssetsCreateXrpPayment} |
| 72 | +</CodeBlock> |
| 73 | + |
| 74 | +### XRP Payment Script Breakdown |
| 75 | + |
| 76 | +1. Install the `xrpl` package — it's not included in the Flare Hardhat Starter Kit by default. |
| 77 | +2. Define the needed constants. |
| 78 | +3. Create a client to connect to the XRP Ledger Testnet. |
| 79 | +4. Load the sender wallet. |
| 80 | +5. Construct the payment transaction. |
| 81 | +6. Sign and submit the transaction. |
| 82 | + |
| 83 | +## Generate Proof with Flare Data Connector |
| 84 | + |
| 85 | +Use the [FDC Payment](/fdc/guides/hardhat/payment) script to validate the XRP payment and generate a Merkle proof. |
| 86 | + |
| 87 | +## Execute Minting |
| 88 | + |
| 89 | +Once the XRP payment is validated, you can retrieve the FDC proof from the [Data Availability Layer](/fdc/overview#data-availability-layer) and call the [`executeMinting()`](/fassets/reference/IAssetManager#executeminting) function on the AssetManager contract. |
| 90 | + |
| 91 | +This script demonstrates how to retrieve the FDC proof and execute minting. |
| 92 | + |
| 93 | +<CodeBlock language="typescript" title="scripts/fassets/executeMinting.ts"> |
| 94 | + {FAssetsExecuteMinting} |
| 95 | +</CodeBlock> |
| 96 | + |
| 97 | +### Execute Minting Script Breakdown |
| 98 | + |
| 99 | +1. Get environment variables. |
| 100 | +2. Declare the constant `ASSET_MANAGER_ADDRESS` pointing to the FXRP AssetManager on the Songbird Testnet (Coston network). |
| 101 | + |
| 102 | +3. Set the collateral reservation ID to the previously reserved minting request. |
| 103 | +4. Set the Flare Data Connector (FDC) round ID to retrieve the proof. |
| 104 | +5. Prepare the FDC request payload data. |
| 105 | +6. Create a function to get the proof from the FDC. |
| 106 | + It sends a POST request to the [Flare Data Availability Layer](/fdc/overview#data-availability-layer) and returns a Merkle proof and attestation response from FDC. |
| 107 | +7. Retrieve the FDC proof from the Data Availability Layer. |
| 108 | +8. Call the [`executeMinting()`](/fassets/reference/IAssetManager#executeminting) function on the AssetManager contract and send a transaction to the Flare network to convert the attested XRP payment into FXRP (minting). |
| 109 | +9. On a successful transaction call `parseExecutemintingEvents()` to extract and log events [`RedemptionTicketCreated`](/fassets/reference/IAssetManagerEvents#redemptionticketcreated) and [`MintingExecuted`](/fassets/reference/IAssetManagerEvents#mintingexecuted). |
| 110 | + |
| 111 | +## Next Steps |
| 112 | + |
| 113 | +Now that you have successfully minted FAssets, you can use them in Flare dApps or transfer them to other users or smart contracts within the Flare ecosystem. |
| 114 | + |
| 115 | +:::tip Redeem |
| 116 | +To convert your FAssets (e.g., FXRP) back into the original asset (e.g., XRP), follow the steps in the [FAssets Redemption Guide](/fassets/developer-guides/fassets-redeem). |
| 117 | +::: |
0 commit comments