|
| 1 | +--- |
| 2 | +title: Direct Mint FXRP with Tag |
| 3 | +tags: [intermediate, fassets] |
| 4 | +slug: fassets-direct-minting-tag |
| 5 | +description: Mint FXRP using a reserved XRPL destination tag. |
| 6 | +keywords: [fassets, fxrp, direct-minting, minting-tag, flare-network, xrpl] |
| 7 | +sidebar_position: 6 |
| 8 | +--- |
| 9 | + |
| 10 | +import CodeBlock from "@theme/CodeBlock"; |
| 11 | +import FAssetsDirectMintingTag from "!!raw-loader!/examples/developer-hub-javascript/fassetsDirectMintingTag.ts"; |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +This guide walks you through minting FXRP using [direct minting](/fassets/direct-minting) with an **XRPL destination tag** reserved on Flare that maps to a recipient (and optionally an executor). |
| 16 | +Once a tag is reserved and bound, every XRPL payment to the [Core Vault](/fassets/core-vault) carrying that destination tag mints FXRP to the configured recipient — no per-payment memo required. |
| 17 | + |
| 18 | +The complete runnable example is available in the [flare-viem-starter](https://github.com/flare-foundation/flare-viem-starter/blob/main/src/fassets/direct-mint-tag.ts) repository. |
| 19 | + |
| 20 | +## Tag vs. memo |
| 21 | + |
| 22 | +Compared to the [memo-based direct minting](/fassets/developer-guides/fassets-direct-minting), the tag flow is better suited for repeat minters: |
| 23 | + |
| 24 | +- **One-time setup**: reserve a tag once via [`MintingTagManager`](/fassets/reference/IMintingTagManager) — pay the [`reservationFee`](/fassets/reference/IMintingTagManager#reservationfee) in native token and bind the recipient with [`setMintingRecipient`](/fassets/reference/IMintingTagManager#setmintingrecipient). |
| 25 | +- **Reusable**: every subsequent XRPL payment with the same destination tag routes to the bound recipient without rebuilding a memo. |
| 26 | +- **Transferable**: tags are [ERC-721 NFTs](https://ethereum.org/developers/docs/standards/tokens/erc-721/) and can be transferred to another owner with [`transfer`](/fassets/reference/IMintingTagManager#transfer). |
| 27 | +- **Optional preferred executor**: the tag owner may restrict execution via `setAllowedExecutor`. |
| 28 | + After [`othersCanExecuteAfterSeconds`](/fassets/reference/IAssetManager#getdirectmintingotherscanexecuteafterseconds), anyone can finalize. |
| 29 | + |
| 30 | +## Prerequisites |
| 31 | + |
| 32 | +- [Flare smart account](/smart-accounts/overview) controlled by your XRPL wallet. |
| 33 | +- Native FLR (or C2FLR on Coston2) on the Flare wallet to cover the tag reservation fee. |
| 34 | +- Testnet XRP on the XRP Ledger Testnet — get it from the [XRP Testnet Faucet](https://xrpl.org/resources/dev-tools/xrp-faucets). |
| 35 | +- Environment variables: |
| 36 | + - `XRPL_TESTNET_RPC_URL` — XRPL Testnet RPC endpoint. |
| 37 | + - `XRPL_SEED` — seed for the XRPL wallet that will send the payment. |
| 38 | + - `MINTING_TAG` — _optional_. |
| 39 | + If set, the script reuses this tag instead of reserving a new one. |
| 40 | + |
| 41 | +## Direct Minting Tag Script |
| 42 | + |
| 43 | +<CodeBlock language="typescript" title="src/fassets/direct-mint-tag.ts"> |
| 44 | + {FAssetsDirectMintingTag} |
| 45 | +</CodeBlock> |
| 46 | + |
| 47 | +## Code Breakdown |
| 48 | + |
| 49 | +1. `reserveTag` function reads the [`reservationFee`](/fassets/reference/IMintingTagManager#reservationfee) from [`MintingTagManager`](/fassets/reference/IMintingTagManager) contract and calls [`reserve`](/fassets/reference/IMintingTagManager#reserve) with the fee. |
| 50 | + The contract assigns the next available tag and returns it. |
| 51 | +2. `setMintingRecipient` function binds the tag to a recipient address via [`setMintingRecipient`](/fassets/reference/IMintingTagManager#setmintingrecipient). |
| 52 | + Payments arriving at the [Core Vault](/fassets/core-vault) with this destination tag will mint FXRP to that recipient. |
| 53 | +3. `getMintingRecipient` reads the [`mintingRecipient`](/fassets/reference/IMintingTagManager#mintingrecipient) currently configured for a tag. |
| 54 | +4. `getOrReserveTag` reuses `MINTING_TAG` from the `.env` variables if set; otherwise, it reserves a new tag and binds it to the recipient. |
| 55 | +5. Set the net FXRP amount to mint in XRP. |
| 56 | + Minting and executor fees are added to the the XRPL payment amount. |
| 57 | +6. Connect to the XRPL Testnet using `XRPL_TESTNET_RPC_URL` and load the sender wallet from `XRPL_SEED`. |
| 58 | +7. Resolve the recipient — the Flare [`PersonalAccount`](/smart-accounts/reference/IPersonalAccount) for the XRPL wallet — via [`getPersonalAccountAddress`](/smart-accounts/reference/IPersonalAccount), and look up `AssetManagerFXRP` through the [Flare Contract Registry](/network/guides/flare-contracts-registry) using [`getContractAddressByName`](/network/guides/flare-contracts-registry). |
| 59 | +8. Resolve the [`MintingTagManager`](/fassets/reference/IMintingTagManager) contract address from the `AssetManager` using [`getMintingTagManager`](/fassets/reference/IAssetManager#getmintingtagmanager). |
| 60 | +9. Reserve a new tag (or reuse one from `MINTING_TAG`) and confirm the configured recipient. |
| 61 | +10. Read three values in parallel: |
| 62 | + - `getDirectMintingPaymentAddress` — the Core Vault XRPL address that receives the payment. |
| 63 | + - `getFxrpBalance` — the recipient's FXRP balance before minting. |
| 64 | + - `computeDirectMintingPaymentAmountXrp` — the gross XRP amount equal to the net mint amount plus the minting fee and the executor fee, as quoted by the `AssetManagerFXRP` contract. |
| 65 | +11. Send the XRPL payment to the [Core Vault](/fassets/core-vault) with `destinationTag: Number(tag)` — no memo required. |
| 66 | +12. Wait for the [`DirectMintingExecuted`](/fassets/reference/IAssetManagerEvents#directmintingexecuted) event on `AssetManagerFXRP` using the `waitForDirectMintingExecuted` function. |
| 67 | + The event's `mintedAmountUBA`, `mintingFeeUBA`, and `executorFeeUBA` describe how the underlying payment was split. |
| 68 | +13. Read the final FXRP balance and log the delta. |
| 69 | + |
| 70 | +## Important Notes |
| 71 | + |
| 72 | +- **Reservations cost native currency.** |
| 73 | + Tag reservation pays a fee in native token. |
| 74 | + Tags are assigned sequentially. |
| 75 | +- **Executor changes are not immediate.** After calling the `setAllowedExecutor` function, the new executor only becomes active after a 10-minute cooldown to protect in-flight FDC proofs. |
| 76 | + See [Executor Restrictions](/fassets/direct-minting#executor-restrictions). |
| 77 | +- **Transferring a tag resets it.** |
| 78 | + When ownership changes, the recipient is reset to the new owner, and the executor is reset to the zero address. |
| 79 | +- **Rate limits may delay execution.** |
| 80 | + If the minting hits hourly, daily, or large-minting thresholds, [`DirectMintingDelayed`](/fassets/reference/IAssetManagerEvents#directmintingdelayed) is emitted instead of [`DirectMintingExecuted`](/fassets/reference/IAssetManagerEvents#directmintingexecuted), with an `executionAllowedAt` timestamp. |
| 81 | + |
| 82 | +:::tip[What's next] |
| 83 | + |
| 84 | +To continue your FAssets development journey, you can: |
| 85 | + |
| 86 | +- Read the protocol details in [Direct Minting](/fassets/direct-minting). |
| 87 | +- Mint without a reserved tag using [memo-based direct minting](/fassets/developer-guides/fassets-direct-minting). |
| 88 | +- Check current limits and fees in [Operational Parameters](/fassets/operational-parameters). |
| 89 | + |
| 90 | +::: |
0 commit comments