7.5 KiB
html, parent, blurb, labels
| html | parent | blurb | labels | ||||
|---|---|---|---|---|---|---|---|
| py-authorize-minter.html | quickstart-python.html | Authorize another account to mint NFTs for you. |
|
Assign an Authorized Minter (Python)
You can assign another account permission to mint NFTs for you.
This example shows how to:
- Authorize an account to create NFTs for your account.
- Mint an NFT for another account, when authorized.
Usage
You can download the Quickstart Samples{.github-code-download} archive to try the sample in your own browser.
Get Accounts
- Open and run
py-authorize-minter.md. - Get accounts.
- If you have existing test account seeds:
- Paste a seed in the Standby Seed field.
- Click Get Standby Account.
- Click Get Standby Account Info.
- Paste a seed in the Operational Seed field.
- Click Get Operational Account.
- Click Get Operational Account info.
- If you do not have existing test accounts:
- Click Get Standby Account.
- Click Get Standby Account Info.
- Click Get Operational Account.
- Click Get Operational Account Info.
- If you have existing test account seeds:
Authorize an Account to Create NFTs
To authorize another account to create NFTs for your account (for example, allow the operational account to mint NFTs for the standby account):
- Copy the Operational Account value.
- Paste the Operational Account value in the standby Authorized Minter field.
- Click Set Minter.
Mint an NFT for Another Account
This example uses the Operational account, which was authorized in the previous step, to mint a token on behalf of the Standby account.
To mint a non-fungible token for another account:
- Set the Flags field. For testing purposes, we recommend setting the value to 8.
- Enter the NFT URI. This is a URI that points to the data or metadata associated with the NFT. You can use the sample URI provided if you do not have one of your own.
- Enter the Transfer Fee, a percentage of the proceeds that the original creator receives from future sales of the NFT. 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.
- Enter a Taxon for the NFT. If you don't have a use for the field, set it to 0.
- Copy the Standby Account value.
- Paste the Standby Account value in the Operational account Issuer field.
- Click the Operational account Mint Other button.
Once the item is minted, the authorized minter can sell the NFT normally. The proceeds go to the authorized minter, less the transfer fee. The minter and the issuer can settle up on a division of the price separately.
Create a Sell Offer
To create a NFT sell offer:
- On the Operational account side, enter the Amount of the sell offer in drops (millionths of an XRP), for example 100000000 (100 XRP).
- Set the Flags field to 1.
- Enter the NFT ID of the minted NFT you want to sell.
- Optionally, enter a number of seconds until Expiration.
- Click Create Sell Offer.
The important piece of information in the response is the NFT Offer Index, labeled as nft_offer_index, which is used to accept the sell offer.
Accept Sell Offer
Once a sell offer is available, you can create a new account to accept the offer and buy the NFT.
To accept an available sell offer:
- Clear the Standby Seed field.
- Click Get Standby Account.
- Click Get Standby Account Info.
- Enter the NFT Offer Index (labeled as
nft_offer_indexin the NFT offer results. This is different from thenft_id). - Click Accept Sell Offer.
The Buyer account was debited the 100 XRP price plus 10 drops as the transaction cost. The Seller (Authorized Minter) account is credited 90 XRP. the Issuer and the Seller can divide the proceeds per their agreement in a separate transaction. The original Standby account receives a transfer fee of 10 XRP.
Code Walkthrough
You can download the Quickstart Samples{.github-code-download} archive to try each of the samples.
mod6.py
mod6.py contains the new business logic for this example, the set_minter and mint_other methods.
Import dependencies and define the testnet_url global variable.
import xrpl
import json
from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
testnet_url = "https://s.altnet.rippletest.net:51234"
Set Minter
This function sets the authorized minter for an account. Each account can have 0 or 1 authorized minter that can mint NFTs in its stead.
Get the wallet of the account granting permission and instantiate a client.
def set_minter(_seed, _minter):
granter_wallet = Wallet(_seed, sequence = 16237283)
client = JsonRpcClient(testnet_url)
Define the AccountSet transaction that grants permission to another account to mint tokens on behalf of the granter account.
set_minter_tx = xrpl.models.transactions.AccountSet(
account = granter_wallet.classic_address,
nftoken_minter = _minter,
set_flag = xrpl.models.transactions.AccountSetFlag.ASF_AUTHORIZED_NFTOKEN_MINTER
)
Sign the transaction
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
set_minter_tx, granter_wallet, client)
Submit the transaction and return the results.
try:
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}"
return response.result
mint_other
Get the minter wallet and instantiate a client connection to the XRP ledger.
def mint_other(_seed, _uri, _flags, _transfer_fee, _taxon, _issuer):
minter_wallet = Wallet(_seed, sequence = 16237283)
client = JsonRpcClient(testnet_url)
Define the NFTokenMint transaction. The new parameter in this method is the issuer field, identifying the account on whose behalf the token is being minted.
mint_other_tx = xrpl.models.transactions.NFTokenMint(
account = minter_wallet.classic_address,
uri = xrpl.utils.str_to_hex(_uri),
flags = int(_flags),
transfer_fee = int(_transfer_fee),
nftoken_taxon = int(_taxon),
issuer = _issuer
)
Sign and fill the transaction.
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
mint_other_tx, minter_wallet, client)
Submit the transaction and report the results.
try:
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}"
return response.result





