# Mint and Burn NFTs Using JavaScript This example shows how to: 1. Mint new Non-fungible Tokens (NFTs). 2. Get a list of existing NFTs. 3. Delete (Burn) an NFT. [![Mint NFTs Tester](/assets/mt-mint-token-1-empty-form.9ceb9e85f45fe6a431a3b3b5bf56462b4b4e39f1de6e6a343bc9a270f1d8b5ef.ac57e6ef.png)](/assets/mt-mint-token-1-empty-form.9ceb9e85f45fe6a431a3b3b5bf56462b4b4e39f1de6e6a343bc9a270f1d8b5ef.ac57e6ef.png) # Usage You can download the [NFT Modular Tutorials](/assets/nft-modular-tutorials.0f7eb22b2ca15eaf6397b7c614a7c020f1ab844da76fa9bf842e720bfc80f1fe.4057f33c.zip) archive to try the sample in your own browser. ## Get Accounts 1. Open `mint-nfts.html` in a browser. 2. Choose your preferred test network (**Devnet** or **Testnet**). 3. Get test accounts. 1. If you copied the gathered information from another tutorial: 1. Paste the gathered information to the **Result** field. 2. Click **Distribute Account Info**. 2. If you have an existing account seed: 1. Paste the account seed to the **Account 1 Seed** or **Account 2 Seed** field. 2. Click **Get Account 1 from Seed** or **Get Account 2 from Seed**. 3. If you do not have existing accounts: 1. Click **Get New Account 1**. 2. Click **Get New Account 2**. [![Get accounts](/assets/mt-mint-token-2-accounts.be3263e5b9afd633a55063af9b15cf7040bcd6769331643a6857a335edf8c5c9.ac57e6ef.png)](/assets/mt-mint-token-2-accounts.be3263e5b9afd633a55063af9b15cf7040bcd6769331643a6857a335edf8c5c9.ac57e6ef.png) ## Mint an NFT To mint a non-fungible token object: 1. Click the Account 1 or Account 2 radio button. The account information populates the uneditable fields of the form. 2. Set the **Flags** field. For testing purposes, we recommend setting the value to *8*. This sets the *tsTransferable* flag, meaning that the NFT object can be transferred to another account. Otherwise, the NFT object can only be transferred back to the issuing account. 3. Enter the **NFT URL**. This is a URI that points to the data or metadata associated with the NFT object. You can use the sample URI provided if you do not have one of your own. 4. Enter the **Transfer Fee**, a percentage of the proceeds from future sales of the NFT that will be returned to the original creator. This is a value of 0-50000 inclusive, allowing transfer rates between 0.000% and 50.000% in increments of 0.001%. If you do not set the **Flags** field to allow the NFT to be transferrable, set this field to 0. If you impose a transfer fee, your NFT can only be traded for tokens for which your account has a trust line. See [Trust Lines](/docs/concepts/tokens/fungible-tokens#trust-lines). 5. Enter an **NFT Taxon**. This is a required value, but if you are not using the field to create an integer-based taxon entry, you can set the value to 0. 6. (Optional) You can set an expected price for the NFT. To set a price in XRP, enter the amount in drops in the **Amount** field. To use an issued currency, enter the **Currency**, **Issuer**, and **Amount**. 7. Optionally, you can enter a **Destination** address that will be the only account authorized to purchase the NFT. 8. Optionally, you can enter an **Expiration** value in days, after which the offer will no longer be available. 9. Click **Mint NFT**. [![Mint NFT fields](/assets/mt-mint-token-3-mint-token.2b95d6af2179fb5cb955dc541cea5969325f60bd0292cc7528ceee21fcf27ec0.ac57e6ef.png)](/assets/mt-mint-token-3-mint-token.2b95d6af2179fb5cb955dc541cea5969325f60bd0292cc7528ceee21fcf27ec0.ac57e6ef.png) ## Get Tokens Click **Get NFTs** to get a list of NFTs owned by the currently selected account. [![Get NFTs](/assets/mt-mint-token-4-get-tokens.850c69cb07290d2d0dfb56d6e2d9353fba21876fcebc530b7b1efb1d538ba91e.ac57e6ef.png)](/assets/mt-mint-token-4-get-tokens.850c69cb07290d2d0dfb56d6e2d9353fba21876fcebc530b7b1efb1d538ba91e.ac57e6ef.png) ## Burn a Token The current owner of an NFT can always destroy (or *burn*) an NFT object. To permanently destroy an NFT: 1. Enter or select the account that owns the NFT. 2. Enter the **NFT ID**. 3. Click **Burn NFT**. [![Burn NFTs](/assets/mt-mint-token-5-burn-token.890a23ebdf1b05b385952fe7213e732d0d07a0407d238b1bffb2b567f61795b3.ac57e6ef.png)](/assets/mt-mint-token-5-burn-token.890a23ebdf1b05b385952fe7213e732d0d07a0407d238b1bffb2b567f61795b3.ac57e6ef.png) # Code Walkthrough You can download the [NFT Modular Tutorials](/assets/nft-modular-tutorials.0f7eb22b2ca15eaf6397b7c614a7c020f1ab844da76fa9bf842e720bfc80f1fe.4057f33c.zip) archive to examine the code samples. ## mint-nfts.js ### Mint NFT Get the account wallet and connect to the XRP Ledger. ```javascript async function mintNFT() { const wallet = xrpl.Wallet.fromSeed(accountSeedField.value); const net = getNet(); const client = new xrpl.Client(net); let results = `\n=== Connected. Minting NFT ===`; resultField.value = results; try { await client.connect(); ``` Prepare the transaction parameters. ```javascript const transactionParams = { TransactionType: "NFTokenMint", Account: wallet.classicAddress, URI: xrpl.convertStringToHex(nftURLfield.value), Flags: parseInt(flagsField.value, 10), // Parse to integer TransferFee: parseInt(transferFeeField.value, 10), // Parse to integer NFTokenTaxon: parseInt(nftTaxonField.value, 10), // Parse to integer }; ``` Add optional fields. ```javascript // Add optional fields if (amountField.value) { transactionParams.Amount = configureAmount(amountField.value); } if (expirationField.value) { transactionParams.Expiration = configureExpiration(expirationField.value); } if (destinationField.value) { transactionParams.Destination = destinationField.value; } ``` Log the transaction parameters before submission. ```javascript console.log("Mint NFT Transaction Parameters:", transactionParams); ``` Submit the transaction. ```javascript const tx = await client.submitAndWait(transactionParams, { wallet }); ``` Get the current list of NFTs owned by the account. ```javascript const nfts = await client.request({ method: "account_nfts", account: wallet.classicAddress, }); ``` Report the results of the transaction. ```javascript results = `\n\n=== Transaction result: ${tx.result.meta.TransactionResult} ===`; results += `\n\n=== NFTs: ${JSON.stringify(nfts, null, 2)} ===`; results += `\n\n=== XRP Balance: ${await client.getXrpBalance(wallet.address)} ===`; // Await here resultField.value = results; ``` Catch and report any errors. ```javascript } catch (error) { console.error("Error minting NFT:", error); results += `\n\n=== Error minting NFT: ${error.message} ===`; // Use error.message resultField.value = results; ``` Disconnect from the XRP Ledger. ```javascript } finally { if (client && client.isConnected()) { // Check if connected before disconnecting await client.disconnect(); } } } // End of mintToken() ``` ### Get NFTs Get the wallet and connect to the XRP Ledger. ```javascript async function getNFTs() { const wallet = xrpl.Wallet.fromSeed(accountSeedField.value); const net = getNet(); const client = new xrpl.Client(net); let results = '\n=== Connected. Getting NFTs. ==='; resultField.value = results; try { await client.connect(); ``` Prepare and send the `account_nfts` request. ```javascript const nfts = await client.request({ method: "account_nfts", account: wallet.classicAddress, }); ``` Report the results. ```javascript results = '\n=== NFTs:\n ' + JSON.stringify(nfts, null, 2) + ' ==='; resultField.value = results; ``` Catch and report any errors. ```javascript } catch (error) { console.error("Error getting NFTs:", error); results += `\n\n=== Error getting NFTs: ${error.message} ===`; resultField.value = results; ``` Disconnect from the XRP Ledger. ```javascript } finally { if (client && client.isConnected()) { await client.disconnect(); } } } // End of getNFTs() ``` ### Burn NFT Get the account wallet and connect to the XRP Ledger. ```javascript async function burnNFT() { const wallet = xrpl.Wallet.fromSeed(accountSeedField.value); const net = getNet(); const client = new xrpl.Client(net); let results = '\n=== Connected. Burning NFT. ==='; resultField.value = results; try { await client.connect(); ``` Prepare the `NFTokenBurn` transaction. ```javascript const transactionBlob = { TransactionType: "NFTokenBurn", Account: wallet.classicAddress, NFTokenID: nftIdField.value, }; console.log("Burn NFT Transaction Parameters:", transactionBlob); // Log before submit ``` Submit the transaction and wait for the results. ```javascript const tx = await client.submitAndWait(transactionBlob, { wallet }); const nfts = await client.request({ // Get nfts after burning. method: "account_nfts", account: wallet.classicAddress, }); ``` Report the results. ```javascript results = `\n=== Transaction result: ${tx.result.meta.TransactionResult} ===`; results += '\n\n=== Balance changes: ' + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) + ' ==='; results += '\n\n=== NFTs: \n' + JSON.stringify(nfts, null, 2) + ' ==='; resultField.value = results; xrpBalanceField.value = (await client.getXrpBalance(wallet.address)); // Await ``` Catch and report any errors. ```javascript } catch (error) { console.error("Error burning NFT:", error); results = `\n\n=== Error burning NFT: ${error.message} ===`; // User friendly resultField.value = results; ``` Disconnect from the XRP Ledger. ```javascript } finally { if (client && client.isConnected()) { await client.disconnect(); } } } ``` ## mint-nfts.html ```html Mint NFTs

Mint NFTs

Choose your ledger instance:      



  





```