|
| 1 | +--- |
| 2 | +title: Mint FAssets using the Executor |
| 3 | +tags: [intermediate, fassets] |
| 4 | +slug: fassets-mint-executor |
| 5 | +description: Learn how to mint FAssets using the executor |
| 6 | +keywords: [fassets, flare-network] |
| 7 | +sidebar_position: 6 |
| 8 | +--- |
| 9 | + |
| 10 | +import CodeBlock from "@theme/CodeBlock"; |
| 11 | +import Remix from "@site/src/components/remix"; |
| 12 | +import FAssetsReserveCollateralWithExecutor from "!!raw-loader!/examples/developer-hub-javascript/fassetsReserveCollateralWithExecutor.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 using the [executor](/fassets/minting#executor-role). |
| 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 | +The minting process can be executed by an external actor that monitors pending requests. |
| 23 | +Executors are incentivized but have no special permissions. |
| 24 | +If they fail to execute in time, the request expires, and minting must be restarted. |
| 25 | + |
| 26 | +See the [Minting](/fassets/minting) overview for more details. |
| 27 | + |
| 28 | +## Prerequisites |
| 29 | + |
| 30 | +- [Flare Hardhat Starter Kit](/network/guides/hardhat-foundry-starter-kit) |
| 31 | +- [Flare Network Periphery Contracts](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contracts) |
| 32 | + |
| 33 | +## Minting Process Steps |
| 34 | + |
| 35 | +The minting process is a multi-step process that involves the following steps: |
| 36 | + |
| 37 | +1. Reserve collateral from a suitable agent and nominate an executor. |
| 38 | +2. Send the underlying asset (e.g., XRP) to the agent. |
| 39 | +3. Use [Flare Data Connector (FDC)](/fdc/overview) to generate proof of payment. |
| 40 | +4. Execute minting with the proof to receive FAssets. |
| 41 | + |
| 42 | +## Reserve Collateral |
| 43 | + |
| 44 | +The following code demonstrates how to reserve collateral by calling the [`reserveCollateral()`](/fassets/reference/IAssetManager#reservecollateral) function on the AssetManager contract. |
| 45 | + |
| 46 | +<CodeBlock language="typescript" title="scripts/fassets/reserveCollateral.ts"> |
| 47 | + {FAssetsReserveCollateralWithExecutor} |
| 48 | +</CodeBlock> |
| 49 | + |
| 50 | +### Collateral Reservation Script Breakdown |
| 51 | + |
| 52 | +1. Define constants |
| 53 | + |
| 54 | +- `ASSET_MANAGER_ADDRESS`: FXRP AssetManager address on Songbird Testnet (Coston). |
| 55 | +- `LOTS_TO_MINT`: Number of FAssets lots to reserve. |
| 56 | +- `UNDERLYING_ADDRESS`: Target XRP Ledger address for the minted asset. |
| 57 | +- `EXECUTOR_ADDRESS`: Executor address that will execute the minting process and provide the proof of underlying asset payment. |
| 58 | + |
| 59 | +2. Retrieve and filter agents with enough free collateral and select the agent with the lowest fee and normal status. |
| 60 | +3. Parse [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event. |
| 61 | +4. Start the minting reservation process at the script's entry point. |
| 62 | +5. Call `findBestAgent()` with the required number of lots. |
| 63 | +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. |
| 64 | +7. Calculate the collateral reservation fee by calling [`collateralReservationFee()`](/fassets/reference/IAssetManager#collateralreservationfee). |
| 65 | +8. Set the executor fee the same as the collateral reservation fee to make this example simpler. |
| 66 | +9. Reserve collateral from agent by calling [`reserveCollateral()`](/fassets/reference/IAssetManager#reservecollateral) with the executor address. |
| 67 | + The executor fee is on top of the collateral reservation fee in native tokens. |
| 68 | + The fee is agreed between the minter and the executor. |
| 69 | +10. Call `assetMintingDecimals()` to determine the XRP token's decimal precision. |
| 70 | +11. Parse the [`CollateralReserved`](/fassets/reference/IAssetManagerEvents#collateralreserved) event to get the collateral reservation ID and other important collateral reservation details. |
| 71 | +12. Calculate the total XRP value required for payment. |
| 72 | + |
| 73 | +## Send Payment on XRP Ledger |
| 74 | + |
| 75 | +The next step is to send the XRP Ledger payment to the agent, and you can use this script to do that. |
| 76 | + |
| 77 | +<CodeBlock language="typescript" title="scripts/fassets/xrpPayment.ts"> |
| 78 | + {FAssetsCreateXrpPayment} |
| 79 | +</CodeBlock> |
| 80 | + |
| 81 | +### XRP Payment Script Breakdown |
| 82 | + |
| 83 | +1. Install the `xrpl` package — it's not included in the Flare Hardhat Starter Kit by default. |
| 84 | +2. Specify the correct constants from the reserve collateral script: |
| 85 | + - `AGENT_ADDRESS` - Agent's XRP Ledger address. |
| 86 | + - `AMOUNT_XRP` - XRP amount to send. |
| 87 | + - `PAYMENT_REFERENCE` - Payment reference from the the reserve collateral script. |
| 88 | +3. Create a client to connect to the XRP Ledger Testnet. |
| 89 | +4. Load the sender's wallet. |
| 90 | +5. Construct the payment transaction. |
| 91 | +6. Sign and submit the transaction. |
| 92 | + |
| 93 | +## Generate Proof with Flare Data Connector |
| 94 | + |
| 95 | +The executor will use the [Flare Data Connector Payment](/fdc/guides/hardhat/payment) to validate the XRP payment and generate a Merkle proof. |
| 96 | + |
| 97 | +## Execute Minting |
| 98 | + |
| 99 | +Once the XRP payment is validated, executor 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. |
| 100 | +Once the minting is executed, the executor will receive the executor fee in native tokens. |
| 101 | +If the executor fails to execute in time, the request expires, and minting must be restarted. |
| 102 | + |
| 103 | +This script demonstrates how to retrieve the FDC proof and execute minting. |
| 104 | + |
| 105 | +<CodeBlock language="typescript" title="scripts/fassets/executeMinting.ts"> |
| 106 | + {FAssetsExecuteMinting} |
| 107 | +</CodeBlock> |
| 108 | + |
| 109 | +### Execute Minting Script Breakdown |
| 110 | + |
| 111 | +1. Get environment variables. |
| 112 | +2. Declare the constant `ASSET_MANAGER_ADDRESS` pointing to the FXRP AssetManager on the Songbird Testnet (Coston network). |
| 113 | + |
| 114 | +3. Set the collateral reservation ID to the previously reserved minting request. |
| 115 | +4. Set the Flare Data Connector (FDC) round ID to retrieve the proof. |
| 116 | +5. Prepare the FDC request payload data. |
| 117 | +6. Create a function to get the proof from the FDC. |
| 118 | + 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. |
| 119 | +7. Retrieve the FDC proof from the Data Availability Layer. |
| 120 | +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). |
| 121 | +9. On a successful transaction call `parseExecutemintingEvents()` to extract and log events [`RedemptionTicketCreated`](/fassets/reference/IAssetManagerEvents#redemptionticketcreated) and [`MintingExecuted`](/fassets/reference/IAssetManagerEvents#mintingexecuted). |
| 122 | + |
| 123 | +## Next Steps |
| 124 | + |
| 125 | +Now that you have successfully minted FAssets using the executor, you can use them in Flare dApps or transfer them to other users or smart contracts within the Flare ecosystem. |
| 126 | + |
| 127 | +:::tip Redeem |
| 128 | +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). |
| 129 | +::: |
0 commit comments