用户
How do I mint an NFT on the XRPL?
How do I mint an NFT on the XRPL?
To mint an NFT on the XRP Ledger (XRPL), you need to follow these steps:
Set the Flags Field: You should set the value to 8 for testing purposes, which sets the tsTransferable flag. This means the NFT can be transferred to another account. If not set, the NFT can only be transferred back to the issuing account. There are other flags available for different functionalities【9†source】.
Enter the Token URL: This is a URI that points to the data or metadata associated with the NFT. You can use a sample URI if you don't have one【9†source】.
Enter the Transfer Fee: This is a percentage of the proceeds from future sales of the NFT that will be returned to the original creator. The value can range from 0 to 50000, allowing transfer rates between 0.000% and 50.000% in increments of 0.001%. If the NFT is not set to be transferable, set this field to 0【9†source】.
Click Mint Token: This action creates a non-fungible token and adds it to the relevant NFTokenPage object of the NFTokenMinter as an NFToken object. This is the only opportunity to specify any token fields that are defined as immutable【13†source】.
Additional Fields in the NFTokenMint Transaction:
NFTokenTaxon: An arbitrary taxon, or shared identifier, for a series or collection of related NFTs. To mint a series of NFTs, give them all the same taxon【14†source】.Issuer: (Optional) The issuer of the token, if the token is being issued on behalf of another account. This field is omitted if the account sending the transaction is the issuer【14†source】.TransferFee: Specifies the fee charged by the issuer for secondary sales of the NFToken, if allowed. The valid range is 0 to 50000, translating to transfer rates from 0.00% to 50.00%【14†source】.URI: A string of up to 256 bytes of arbitrary data, typically a URI pointing to the data or metadata associated with the NFT. The URI is not checked for validity【14†source】.NFTokenMint Flags:
tfBurnable: Allows the issuer or an authorized entity to destroy the minted NFToken. The NFToken’s owner can always do so.tfOnlyXRP: The minted NFToken can only be bought or sold for XRP. This is useful if the token has a transfer fee and the issuer doesn’t want to receive fees in non-XRP currencies【15†source】.These steps and fields are crucial for successfully minting an NFT on the XRPL.
How would I mint it in JavaScript?
To mint an NFT on the XRPL using JavaScript, you would typically follow these steps:
Connect to the XRPL Ledger and Get the Wallet: Create a connection to the XRPL network and prepare the wallet from which you'll mint the NFT.
Define the Transaction: Create a JSON object representing the NFTokenMint transaction. Key fields include:
TransactionType: Set to "NFTokenMint".Account: The classic address of the wallet minting the NFT.URI: The URI of the token, converted to hexadecimal format.Flags: Set this to 8 if you want the NFT to be transferable.TransferFee: A value from 0 to 50000, representing the transfer fee as a royalty percentage.NFTokenTaxon: An arbitrary value defined by the issuer, can be set to 0 if not used.Send the Transaction: Use the XRPL client to submit the transaction and wait for the response.
Request a List of NFTs Owned by the Account: This verifies the minting of the new NFT.
Report the Results and Disconnect: Show the transaction result and the list of NFTs, then disconnect from the XRPL ledger.
Here is an example function in JavaScript that encapsulates these steps:
async function mintToken() {
// Connect to the ledger and get the account wallets
let net = getNet()
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const client = new xrpl.Client(net)
await client.connect()
// Define the transaction
const transactionJson = {
"TransactionType": "NFTokenMint",
"Account": standby_wallet.classicAddress,
"URI": xrpl.convertStringToHex(standbyTokenUrlField.value),
"Flags": parseInt(standbyFlagsField.value),
"TransferFee": parseInt(standbyTransferFeeField.value),
"NFTokenTaxon": 0
}
// Send the transaction and wait for the response
const tx = await client.submitAndWait(transactionJson, { wallet: standby_wallet })
// Request a list of NFTs owned by the account
const nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress
})
// Report the results
standbyResultField.value = JSON.stringify(nfts, null, 2)
// Disconnect from the ledger
client.disconnect()
}
This script assumes that you have access to the xrpl.js library and that your environment is properly set up to interact with the XRPL network【23†source】.