Merge pull request #2107 from XRPLF/repostPython2Updates

Tutorial updates for xrpl-py2 library (post-IAv3)
This commit is contained in:
Dennis Dawson
2023-09-07 17:05:48 -07:00
committed by GitHub
28 changed files with 1425 additions and 361 deletions

View File

@@ -1,22 +1,19 @@
import xrpl import xrpl
import json
import xrpl.clients testnet_url = "https://s.altnet.rippletest.net:51234/"
import xrpl.wallet
def get_account(seed): def get_account(seed):
"""get_account""" """get_account"""
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/" client = xrpl.clients.JsonRpcClient(testnet_url)
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
if (seed == ''): if (seed == ''):
new_wallet = xrpl.wallet.generate_faucet_wallet(client) new_wallet = xrpl.wallet.generate_faucet_wallet(client)
else: else:
new_wallet = xrpl.wallet.Wallet(seed, sequence = 79396029) new_wallet = xrpl.wallet.Wallet.from_seed(seed)
return(new_wallet) return new_wallet
def get_account_info(accountId): def get_account_info(accountId):
"""get_account_info""" """get_account_info"""
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234' client = xrpl.clients.JsonRpcClient(testnet_url)
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
acct_info = xrpl.models.requests.account_info.AccountInfo( acct_info = xrpl.models.requests.account_info.AccountInfo(
account=accountId, account=accountId,
ledger_index="validated" ledger_index="validated"
@@ -25,20 +22,15 @@ def get_account_info(accountId):
return response.result['account_data'] return response.result['account_data']
def send_xrp(seed, amount, destination): def send_xrp(seed, amount, destination):
sending_wallet = xrpl.wallet.Wallet(seed, sequence = 16237283) sending_wallet = xrpl.wallet.Wallet.from_seed(seed)
testnet_url = "https://s.altnet.rippletest.net:51234"
client = xrpl.clients.JsonRpcClient(testnet_url) client = xrpl.clients.JsonRpcClient(testnet_url)
payment = xrpl.models.transactions.Payment( payment = xrpl.models.transactions.Payment(
account=sending_wallet.classic_address, account=sending_wallet.address,
amount=xrpl.utils.xrp_to_drops(int(amount)), amount=xrpl.utils.xrp_to_drops(int(amount)),
destination=destination, destination=destination,
) )
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction( try:
payment, sending_wallet, client) response = xrpl.transaction.submit_and_wait(payment, client, sending_wallet)
try: except xrpl.transaction.XRPLReliableSubmissionException as e:
tx_response = xrpl.transaction.send_reliable_submission(signed_tx,client)
response = tx_response
except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" response = f"Submit failed: {e}"
return response return response

View File

@@ -1,8 +1,6 @@
import xrpl import xrpl
import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
from xrpl.models.requests.account_info import AccountInfo
testnet_url = "https://s.altnet.rippletest.net:51234" testnet_url = "https://s.altnet.rippletest.net:51234"
@@ -14,28 +12,21 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
def create_trust_line(seed, issuer, currency, amount): def create_trust_line(seed, issuer, currency, amount):
"""create_trust_line""" """create_trust_line"""
# Get the client # Get the client
receiving_wallet = Wallet(seed, sequence = 16237283) receiving_wallet = Wallet.from_seed(seed)
client = JsonRpcClient(testnet_url) client = JsonRpcClient(testnet_url)
# Define the trust line transaction # Define the trust line transaction
trustline_tx=xrpl.models.transactions.TrustSet( trustline_tx=xrpl.models.transactions.TrustSet(
account=receiving_wallet.classic_address, account=receiving_wallet.address,
limit_amount=xrpl.models.amounts.IssuedCurrencyAmount( limit_amount=xrpl.models.amounts.IssuedCurrencyAmount(
currency=currency, currency=currency,
issuer=issuer, issuer=issuer,
value=int(amount) value=int(amount)
) )
) )
# Sign and fill the transaction
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction( response = xrpl.transaction.submit_and_wait(trustline_tx,
trustline_tx, receiving_wallet, client) client, receiving_wallet)
# Submit the transaction and get results return response.result
reply = ""
try:
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
return reply
################# #################
# send_currency # # send_currency #
@@ -44,29 +35,20 @@ def create_trust_line(seed, issuer, currency, amount):
def send_currency(seed, destination, currency, amount): def send_currency(seed, destination, currency, amount):
"""send_currency""" """send_currency"""
# Get the client # Get the client
sending_wallet=Wallet(seed, sequence=16237283) sending_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
# Define the payment transaction. # Define the payment transaction.
send_currency_tx=xrpl.models.transactions.Payment( send_currency_tx=xrpl.models.transactions.Payment(
account=sending_wallet.classic_address, account=sending_wallet.address,
amount=xrpl.models.amounts.IssuedCurrencyAmount( amount=xrpl.models.amounts.IssuedCurrencyAmount(
currency=currency, currency=currency,
value=int(amount), value=int(amount),
issuer=sending_wallet.classic_address issuer=sending_wallet.address
), ),
destination=destination destination=destination
) )
# Sign and fill the transaction response=xrpl.transaction.submit_and_wait(send_currency_tx, client, sending_wallet)
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction( return response.result
send_currency_tx, sending_wallet, client)
# Submit the transaction and get results
reply = ""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
return reply
############### ###############
# get_balance # # get_balance #
@@ -74,8 +56,7 @@ def send_currency(seed, destination, currency, amount):
def get_balance(sb_account_id, op_account_id): def get_balance(sb_account_id, op_account_id):
"""get_balance""" """get_balance"""
JSON_RPC_URL='wss://s.altnet.rippletest.net:51234' client=JsonRpcClient(testnet_url)
client=JsonRpcClient(JSON_RPC_URL)
balance=xrpl.models.requests.GatewayBalances( balance=xrpl.models.requests.GatewayBalances(
account=sb_account_id, account=sb_account_id,
ledger_index="validated", ledger_index="validated",
@@ -91,29 +72,18 @@ def get_balance(sb_account_id, op_account_id):
def configure_account(seed, default_setting): def configure_account(seed, default_setting):
"""configure_account""" """configure_account"""
# Get the client # Get the client
wallet=Wallet(seed, sequence = 16237283) wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
# Create transaction # Create transaction
if (default_setting): if (default_setting):
setting_tx=xrpl.models.transactions.AccountSet( setting_tx=xrpl.models.transactions.AccountSet(
account=wallet.classic_address, account=wallet.classic_address,
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
) )
else: else:
setting_tx=xrpl.models.transactions.AccountSet( setting_tx=xrpl.models.transactions.AccountSet(
account=wallet.classic_address, account=wallet.classic_address,
clear_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE clear_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
) )
response=xrpl.transaction.submit_and_wait(setting_tx,client,wallet)
# Sign and fill the transaction return response.result
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
setting_tx, wallet, client)
# Submit the transaction and get results
reply = ""
try:
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
return reply

View File

@@ -1,5 +1,4 @@
import xrpl import xrpl
import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
from xrpl.models.requests import AccountNFTs from xrpl.models.requests import AccountNFTs
@@ -9,23 +8,20 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
def mint_token(seed, uri, flags, transfer_fee, taxon): def mint_token(seed, uri, flags, transfer_fee, taxon):
"""mint_token""" """mint_token"""
# Get the client # Get the client
mint_wallet=Wallet(seed, sequence=16237283) minter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
# Define the mint transaction # Define the mint transaction
mint_tx=xrpl.models.transactions.NFTokenMint( mint_tx=xrpl.models.transactions.NFTokenMint(
account=mint_wallet.classic_address, account=minter_wallet.address,
uri=xrpl.utils.str_to_hex(uri), uri=xrpl.utils.str_to_hex(uri),
flags=int(flags), flags=int(flags),
transfer_fee=int(transfer_fee), transfer_fee=int(transfer_fee),
nftoken_taxon=int(taxon) nftoken_taxon=int(taxon)
) )
# Sign and fill the transaction
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
mint_tx, mint_wallet, client)
# Submit the transaction and get results # Submit the transaction and get results
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(mint_tx,client,minter_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -45,19 +41,16 @@ def get_tokens(account):
def burn_token(seed, nftoken_id): def burn_token(seed, nftoken_id):
"""burn_token""" """burn_token"""
# Get the client # Get the client
owner_wallet=Wallet(seed, sequence=16237283) owner_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
burn_tx=xrpl.models.transactions.NFTokenBurn( burn_tx=xrpl.models.transactions.NFTokenBurn(
account=owner_wallet.classic_address, account=owner_wallet.address,
nftoken_id=nftoken_id nftoken_id=nftoken_id
) )
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
burn_tx, owner_wallet, client)
# Submit the transaction and get results # Submit the transaction and get results
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(burn_tx,client,owner_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"

View File

@@ -12,7 +12,7 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
def create_sell_offer(seed, amount, nftoken_id, expiration, destination): def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
"""create_sell_offer""" """create_sell_offer"""
# Get the client # Get the client
owner_wallet = Wallet(seed, sequence=16237283) owner_wallet = Wallet.from_seed(seed)
client = JsonRpcClient(testnet_url) client = JsonRpcClient(testnet_url)
expiration_date = datetime.now() expiration_date = datetime.now()
if expiration != '': if expiration != '':
@@ -20,41 +20,34 @@ def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
expiration_date = expiration_date + int(expiration) expiration_date = expiration_date + int(expiration)
# Define the sell offer # Define the sell offer
sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer( sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account=owner_wallet.classic_address, account=owner_wallet.address,
nftoken_id=nftoken_id, nftoken_id=nftoken_id,
amount=amount, amount=amount,
destination=destination if destination != '' else None, destination=destination if destination != '' else None,
expiration=expiration_date if expiration != '' else None, expiration=expiration_date if expiration != '' else None,
flags=1 flags=1
) )
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
sell_offer_tx, owner_wallet, client)
# Submit the transaction and report the results # Submit the transaction and report the results
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(sell_offer_tx,client,owner_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
return reply return reply
def accept_sell_offer(seed, offer_index): def accept_sell_offer(seed, offer_index):
"""accept_sell_offer""" """accept_sell_offer"""
buyer_wallet=Wallet(seed, sequence=16237283) buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer( accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account=buyer_wallet.classic_address, account=buyer_wallet.classic_address,
nftoken_sell_offer=offer_index nftoken_sell_offer=offer_index
) )
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, buyer_wallet, client)
# Submit the transaction and report the results # Submit the transaction and report the results
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,buyer_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -64,7 +57,7 @@ def accept_sell_offer(seed, offer_index):
def create_buy_offer(seed, amount, nft_id, owner, expiration, destination): def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
"""create_buy_offer""" """create_buy_offer"""
# Get the client # Get the client
buyer_wallet=Wallet(seed, sequence=16237283) buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
expiration_date=datetime.now() expiration_date=datetime.now()
if (expiration!=''): if (expiration!=''):
@@ -72,7 +65,7 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
expiration_date=expiration_date + int(expiration) expiration_date=expiration_date + int(expiration)
# Define the buy offer transaction with an expiration date # Define the buy offer transaction with an expiration date
buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer( buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account=buyer_wallet.classic_address, account=buyer_wallet.address,
nftoken_id=nft_id, nftoken_id=nft_id,
amount=amount, amount=amount,
owner=owner, owner=owner,
@@ -80,13 +73,10 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
destination=destination if destination!='' else None, destination=destination if destination!='' else None,
flags=0 flags=0
) )
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
buy_offer_tx, buyer_wallet, client)
# Submit the transaction and report the results # Submit the transaction and report the results
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(buy_offer_tx,client,buyer_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -95,19 +85,16 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
def accept_buy_offer(seed, offer_index): def accept_buy_offer(seed, offer_index):
"""accept_buy_offer""" """accept_buy_offer"""
buyer_wallet=Wallet(seed, sequence=16237283) buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer( accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account=buyer_wallet.classic_address, account=buyer_wallet.address,
nftoken_buy_offer=offer_index nftoken_buy_offer=offer_index
) )
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, buyer_wallet, client)
# Submit the transaction and report the results # Submit the transaction and report the results
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,buyer_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -130,19 +117,17 @@ def get_offers(nft_id):
def cancel_offer(seed, nftoken_offer_ids): def cancel_offer(seed, nftoken_offer_ids):
"""cancel_offer""" """cancel_offer"""
owner_wallet=Wallet(seed, sequence=16237283) owner_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
tokenOfferIDs=[nftoken_offer_ids] tokenOfferIDs=[nftoken_offer_ids]
nftSellOffers="No sell offers" nftSellOffers="No sell offers"
cancel_offer_tx=xrpl.models.transactions.NFTokenCancelOffer( cancel_offer_tx=xrpl.models.transactions.NFTokenCancelOffer(
account=owner_wallet.classic_address, account=owner_wallet.classic_address,
nftoken_offers=tokenOfferIDs nftoken_offers=tokenOfferIDs
) )
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
cancel_offer_tx, owner_wallet, client)
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(cancel_offer_tx,client,owner_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"

View File

@@ -1,5 +1,4 @@
import xrpl import xrpl
import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
testnet_url = "https://s.altnet.rippletest.net:51234" testnet_url = "https://s.altnet.rippletest.net:51234"
@@ -7,7 +6,7 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
def broker_sale(seed, sell_offer_index, buy_offer_index, broker_fee): def broker_sale(seed, sell_offer_index, buy_offer_index, broker_fee):
"""broker_sale""" """broker_sale"""
broker_wallet=Wallet(seed, sequence=16237283) broker_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer( accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account=broker_wallet.classic_address, account=broker_wallet.classic_address,
@@ -15,13 +14,10 @@ def broker_sale(seed, sell_offer_index, buy_offer_index, broker_fee):
nftoken_buy_offer=buy_offer_index, nftoken_buy_offer=buy_offer_index,
nftoken_broker_fee=broker_fee nftoken_broker_fee=broker_fee
) )
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, broker_wallet, client)
# Submit the transaction and report the results # Submit the transaction and report the results
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,broker_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"

View File

@@ -1,47 +1,46 @@
import xrpl import xrpl
import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
testnet_url="https://s.altnet.rippletest.net:51234" testnet_url="https://s.altnet.rippletest.net:51234"
def set_minter(seed, minter): def set_minter(seed, minter):
"""set_minter""" """set_minter"""
granter_wallet=Wallet(seed, sequence = 16237283) granter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
set_minter_tx=xrpl.models.transactions.AccountSet( set_minter_tx=xrpl.models.transactions.AccountSet(
account=granter_wallet.classic_address, account=granter_wallet.address,
nftoken_minter=minter, nftoken_minter=minter,
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_AUTHORIZED_NFTOKEN_MINTER set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_AUTHORIZED_NFTOKEN_MINTER
) )
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
set_minter_tx, granter_wallet, client)
# Submit the transaction and report the results # Submit the transaction and report the results
reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(set_minter_tx,client,
granter_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
response=f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result return reply
def mint_other(seed, uri, flags, transfer_fee, taxon, issuer): def mint_other(seed, uri, flags, transfer_fee, taxon, issuer):
"""mint_other""" """mint_other"""
minter_wallet=Wallet(seed, sequence=16237283) minter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
mint_other_tx=xrpl.models.transactions.NFTokenMint( mint_other_tx=xrpl.models.transactions.NFTokenMint(
account=minter_wallet.classic_address, account=minter_wallet.address,
uri=xrpl.utils.str_to_hex(uri), uri=xrpl.utils.str_to_hex(uri),
flags=int(flags), flags=int(flags),
transfer_fee=int(transfer_fee), transfer_fee=int(transfer_fee),
nftoken_taxon=int(taxon), nftoken_taxon=int(taxon),
issuer=issuer 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 # Submit the transaction and report the results
reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(mint_other_tx,client,
minter_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
response=f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result return reply

View File

@@ -0,0 +1,80 @@
import xrpl
from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.requests import AccountNFTs
testnet_url = "https://s.altnet.rippletest.net:51234"
def batch_mint(seed, uri, flags, transfer_fee, taxon, count):
"""batch_mint"""
wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
acct_info = xrpl.models.requests.account_info.AccountInfo(
account=wallet.classic_address,
ledger_index='validated'
)
get_seq_request = client.request(acct_info)
current_sequence=get_seq_request.result['account_data']['Sequence']
ticket_tx=xrpl.models.transactions.TicketCreate(
account=wallet.address,
ticket_count=int(count),
sequence=current_sequence
)
response=xrpl.transaction.submit_and_wait(ticket_tx,client,wallet)
ticket_numbers_req=xrpl.models.requests.AccountObjects(
account=wallet.address,
type='ticket'
)
ticket_response=client.request(ticket_numbers_req)
tickets=[int(0)] * int(count)
acct_objs= ticket_response.result['account_objects']
for x in range(int(count)):
tickets[x] = acct_objs[x]['TicketSequence']
reply=""
create_count=0
# Define the mint transaction
for x in range(int(count)):
mint_tx=xrpl.models.transactions.NFTokenMint(
account=wallet.classic_address,
uri=xrpl.utils.str_to_hex(uri),
flags=int(flags),
transfer_fee=int(transfer_fee),
ticket_sequence=tickets[x],
sequence=0,
nftoken_taxon=int(taxon)
)
# Submit the transaction and get results
try:
response=xrpl.transaction.submit_and_wait(mint_tx,client,
wallet)
create_count+=1
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply+=f"Submit failed: {e}\n"
reply+=str(create_count)+' NFTs generated.'
return reply
def get_batch(seed, account):
"""get_batch"""
client=JsonRpcClient(testnet_url)
acct_nfts=AccountNFTs(
account=account,
limit=400
)
response=client.request(acct_nfts)
responses=response.result
while(acct_nfts.marker):
acct_nfts=AccountNFTs(
account=account,
limit=400,
marker=acct_nfts.marker
)
response=client.request(acct_nfts)
responses+=response.result
return responses

View File

@@ -90,7 +90,7 @@ The results show that the Issuer account has been credited 25 XRP. The Buyer acc
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to try each of the samples in your own browser.
## Set Minter ## Set Minter

View File

@@ -5,20 +5,20 @@ blurb: Broker a sale between a sell offer and a buy offer.
labels: labels:
- Accounts - Accounts
- Quickstart - Quickstart
- Broker - NFTs
- XRP - XRP
--- ---
# Batch Mint NFTs Using JavaScript # Batch Mint NFTs Using JavaScript
You can create an application that mints multiple NFTs at one time. You can use a `for` loop to send one transaction after another. You can create an application that mints multiple NFTs at one time. You can use a `for` loop to send one transaction after another.
A best practice is to use `Tickets` to reserve the transaction sequence numbers. If you create an application that creates NFTs without using tickets, if any transaction fails for any reason, the application stops with an error. If you use tickets, the application continues to send transactions, and you can look into the reason for the failure afterward. A best practice is to use `Tickets` to reserve the transaction sequence numbers. If you create an application that creates NFTs without using tickets, if any transaction fails for any reason, the application stops with an error. If you use tickets, the application continues to send transactions, and you can look into the reason for any individual failures afterward.
[![Batch Mint](img/quickstart33-batch-mint.png)](img/quickstart33-batch-mint.png) [![Batch Mint](img/quickstart33-batch-mint.png)](img/quickstart33-batch-mint.png)
## Usage ## Usage
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try the sample in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to try the sample in your own browser.
## Get an Account ## Get an Account
@@ -51,7 +51,7 @@ The difference between this function and the `getTokens()` function used earlier
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to try each of the samples in your own browser.
## Get Account From Seed ## Get Account From Seed
@@ -105,7 +105,7 @@ Disconnect from the XRP Ledger.
## Get Batch NFTs ## Get Batch NFTs
This version of `getTokens()` allows for a larger set of NFTs by watching for a `marker` at the end of each batch of NFTs. This version of `getTokens()` allows for a larger set of NFTs by watching for a `marker` at the end of each batch of NFTs. Subsequent requests get the next batch of NFTs starting at the previous marker, until all NFTs are retrieved.
```javascript ```javascript
// ******************************************************* // *******************************************************

View File

@@ -22,7 +22,7 @@ This example shows how to:
[![Quickstart form with Broker Account](img/quickstart21.png)](img/quickstart21.png) [![Quickstart form with Broker Account](img/quickstart21.png)](img/quickstart21.png)
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to try each of the samples in your own browser.
## Get Accounts ## Get Accounts
@@ -89,7 +89,7 @@ After accepting a buy offer, a best practice for the broker is to cancel all oth
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to examine the code samples. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to examine the code samples.
## ripplex5-broker-nfts.js ## ripplex5-broker-nfts.js
<!-- SPELLING_IGNORE: ripplex5 --> <!-- SPELLING_IGNORE: ripplex5 -->

View File

@@ -28,7 +28,7 @@ To get started, create a new folder on your local disk and install the JavaScrip
npm install xrpl npm install xrpl
``` ```
Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive. Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive.
**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow. **Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.
@@ -62,7 +62,7 @@ To transfer XRP from the Operational account to the Standby account:
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} in the source repository for this website. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} in the source repository for this website.
## ripplex-1-send-xrp.js ## ripplex-1-send-xrp.js

View File

@@ -23,7 +23,7 @@ This example shows how to:
## Prerequisites ## Prerequisites
Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive. Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive.
## Usage ## Usage
@@ -116,7 +116,7 @@ If you forget to save the sequence number, you can find it in the escrow transac
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} in the source repository for this website. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} in the source repository for this website.
## getConditionAndFulfillment.js ## getConditionAndFulfillment.js

View File

@@ -114,7 +114,7 @@ If you forget to save the sequence number, you can find it in the escrow transac
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} in the source repository for this website. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} in the source repository for this website.
## ripple8-escrow.js ## ripple8-escrow.js

View File

@@ -21,7 +21,7 @@ This example shows how to:
[![Test harness with currency transfer](img/quickstart5.png)](img/quickstart5.png) [![Test harness with currency transfer](img/quickstart5.png)](img/quickstart5.png)
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to try each of the samples in your own browser.
**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow. **Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.
@@ -62,7 +62,7 @@ To transfer an issued currency token, once you have created a trust line:
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to try each of the samples in your own browser.
## ripplex2-send-currency.js ## ripplex2-send-currency.js
<!-- SPELLING_IGNORE: ripplex2 --> <!-- SPELLING_IGNORE: ripplex2 -->

View File

@@ -19,7 +19,7 @@ This example shows how to:
# Usage # Usage
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try the sample in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to try the sample in your own browser.
## Get Accounts ## Get Accounts
@@ -65,7 +65,7 @@ To permanently destroy a NFT:
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to examine the code samples. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to examine the code samples.
## ripplex3-mint-nfts.js ## ripplex3-mint-nfts.js
<!-- SPELLING_IGNORE: ripplex3 --> <!-- SPELLING_IGNORE: ripplex3 -->

View File

@@ -1,6 +1,6 @@
--- ---
html: py-authorize-minter.html html: py-authorize-minter.html
parent: send-payments-using-python.html parent: nfts-using-python.html
blurb: Authorize another account to mint NFTs for you. blurb: Authorize another account to mint NFTs for you.
labels: labels:
- Accounts - Accounts
@@ -103,7 +103,7 @@ The Buyer account was debited the 100 XRP price plus 10 drops as the transaction
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to try each of the samples.
## mod6.py ## mod6.py
@@ -112,11 +112,10 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
Import dependencies and define the `testnet_url` global variable. Import dependencies and define the `testnet_url` global variable.
```python ```python
import xrpl import xrpl
import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
testnet_url = "https://s.altnet.rippletest.net:51234" testnet_url="https://s.altnet.rippletest.net:51234"
``` ```
### Set Minter ### Set Minter
@@ -128,7 +127,7 @@ Get the wallet of the account granting permission and instantiate a client.
```python ```python
def set_minter(seed, minter): def set_minter(seed, minter):
"""set_minter""" """set_minter"""
granter_wallet=Wallet(seed, sequence = 16237283) granter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -136,17 +135,10 @@ Define the AccountSet transaction that grants permission to another account to m
```python ```python
set_minter_tx=xrpl.models.transactions.AccountSet( set_minter_tx=xrpl.models.transactions.AccountSet(
account=granter_wallet.classic_address, account=granter_wallet.address,
nftoken_minter=minter, nftoken_minter=minter,
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_AUTHORIZED_NFTOKEN_MINTER set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_AUTHORIZED_NFTOKEN_MINTER
) )
```
Sign the transaction
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
set_minter_tx, granter_wallet, client)
``` ```
Submit the transaction and return the results. Submit the transaction and return the results.
@@ -154,7 +146,8 @@ Submit the transaction and return the results.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(set_minter_tx,client,
granter_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -168,7 +161,7 @@ Get the minter wallet and instantiate a client connection to the XRP ledger.
``` python ``` python
def mint_other(seed, uri, flags, transfer_fee, taxon, issuer): def mint_other(seed, uri, flags, transfer_fee, taxon, issuer):
"""mint_other""" """mint_other"""
minter_wallet=Wallet(seed, sequence=16237283) minter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -176,7 +169,7 @@ Define the `NFTokenMint` transaction. The new parameter in this method is the _i
```python ```python
mint_other_tx=xrpl.models.transactions.NFTokenMint( mint_other_tx=xrpl.models.transactions.NFTokenMint(
account=minter_wallet.classic_address, account=minter_wallet.address,
uri=xrpl.utils.str_to_hex(uri), uri=xrpl.utils.str_to_hex(uri),
flags=int(flags), flags=int(flags),
transfer_fee=int(transfer_fee), transfer_fee=int(transfer_fee),
@@ -185,21 +178,714 @@ Define the `NFTokenMint` transaction. The new parameter in this method is the _i
) )
``` ```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
mint_other_tx, minter_wallet, client)
```
Submit the transaction and report the results. Submit the transaction and report the results.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(mint_other_tx,client,
minter_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
return reply return reply
``` ```
## lesson6-auth-minter.py
This form is based on lesson4-transfer-tokens.py. Changes are highlighted below.
```python
import tkinter as tk
import xrpl
import json
from mod1 import get_account, get_account_info, send_xrp
from mod2 import (
create_trust_line,
send_currency,
get_balance,
configure_account,
)
from mod3 import (
mint_token,
get_tokens,
burn_token,
)
from mod4 import (
create_sell_offer,
create_buy_offer,
get_offers,
cancel_offer,
accept_sell_offer,
accept_buy_offer,
)
```
Import dependencies from `mod6.py`.
```python
from mod6 import set_minter, mint_other
```
Add handlers for new Module 6 methods.
```python
#############################################
## Handlers #################################
#############################################
# Module 6 Handlers
def standby_set_minter():
results = set_minter(ent_standby_seed.get(),ent_standby_auth_minter.get())
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_mint_other():
results = mint_other(
ent_standby_seed.get(),
ent_standby_uri.get(),
ent_standby_flags.get(),
ent_standby_transfer_fee.get(),
ent_standby_taxon.get(),
ent_standby_issuer.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def operational_set_minter():
results = set_minter(ent_operational_seed.get(),ent_operational_auth_minter.get())
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_mint_other():
results = mint_other(
ent_operational_seed.get(),
ent_operational_uri.get(),
ent_operational_flags.get(),
ent_operational_transfer_fee.get(),
ent_operational_taxon.get(),
ent_operational_issuer.get()
)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
# Module 4 Handlers
def standby_create_sell_offer():
results = create_sell_offer(
ent_standby_seed.get(),
ent_standby_amount.get(),
ent_standby_nft_id.get(),
ent_standby_expiration.get(),
ent_standby_destination.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_accept_sell_offer():
results = accept_sell_offer (
ent_standby_seed.get(),
ent_standby_nft_offer_index.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_create_buy_offer():
results = create_buy_offer(
ent_standby_seed.get(),
ent_standby_amount.get(),
ent_standby_nft_id.get(),
ent_standby_owner.get(),
ent_standby_expiration.get(),
ent_standby_destination.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_accept_buy_offer():
results = accept_buy_offer (
ent_standby_seed.get(),
ent_standby_nft_offer_index.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_get_offers():
results = get_offers(ent_standby_nft_id.get())
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", results)
def standby_cancel_offer():
results = cancel_offer(
ent_standby_seed.get(),
ent_standby_nft_offer_index.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def op_create_sell_offer():
results = create_sell_offer(
ent_operational_seed.get(),
ent_operational_amount.get(),
ent_operational_nft_id.get(),
ent_operational_expiration.get(),
ent_operational_destination.get()
)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def op_accept_sell_offer():
results = accept_sell_offer (
ent_operational_seed.get(),
ent_operational_nft_offer_index.get()
)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def op_create_buy_offer():
results = create_buy_offer(
ent_operational_seed.get(),
ent_operational_amount.get(),
ent_operational_nft_id.get(),
ent_operational_owner.get(),
ent_operational_expiration.get(),
ent_operational_destination.get()
)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def op_accept_buy_offer():
results = accept_buy_offer (
ent_operational_seed.get(),
ent_operational_nft_offer_index.get()
)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def op_get_offers():
results = get_offers(ent_operational_nft_id.get())
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", results)
def op_cancel_offer():
results = cancel_offer(
ent_operational_seed.get(),
ent_operational_nft_offer_index.get()
)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
# Module 3 Handlers
def standby_mint_token():
results = mint_token(
ent_standby_seed.get(),
ent_standby_uri.get(),
ent_standby_flags.get(),
ent_standby_transfer_fee.get(),
ent_standby_taxon.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_get_tokens():
results = get_tokens(ent_standby_account.get())
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_burn_token():
results = burn_token(
ent_standby_seed.get(),
ent_standby_nft_id.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def operational_mint_token():
results = mint_token(
ent_operational_seed.get(),
ent_operational_uri.get(),
ent_operational_flags.get(),
ent_operational_transfer_fee.get(),
ent_operational_taxon.get()
)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_get_tokens():
results = get_tokens(ent_operational_account.get())
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_burn_token():
results = burn_token(
ent_operational_seed.get(),
ent_operational_nft_id.get()
)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
# Module 2 Handlers
def standby_create_trust_line():
results = create_trust_line(ent_standby_seed.get(),
ent_standby_destination.get(),
ent_standby_currency.get(),
ent_standby_amount.get())
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_send_currency():
results = send_currency(ent_standby_seed.get(),
ent_standby_destination.get(),
ent_standby_currency.get(),
ent_standby_amount.get())
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_configure_account():
results = configure_account(
ent_standby_seed.get(),
standbyRippling)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def operational_create_trust_line():
results = create_trust_line(ent_operational_seed.get(),
ent_operational_destination.get(),
ent_operational_currency.get(),
ent_operational_amount.get())
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_send_currency():
results = send_currency(ent_operational_seed.get(),
ent_operational_destination.get(),
ent_operational_currency.get(),
ent_operational_amount.get())
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_configure_account():
results = configure_account(
ent_operational_seed.get(),
operationalRippling)
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
def get_balances():
results = get_balance(ent_operational_account.get(), ent_standby_account.get())
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
results = get_balance(ent_standby_account.get(), ent_operational_account.get())
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4))
# Module 1 Handlers
def get_standby_account():
new_wallet = get_account(ent_standby_seed.get())
ent_standby_account.delete(0, tk.END)
ent_standby_seed.delete(0, tk.END)
ent_standby_account.insert(0, new_wallet.classic_address)
ent_standby_seed.insert(0, new_wallet.seed)
def get_standby_account_info():
accountInfo = get_account_info(ent_standby_account.get())
ent_standby_balance.delete(0, tk.END)
ent_standby_balance.insert(0,accountInfo['Balance'])
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4))
def standby_send_xrp():
response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(),
ent_standby_destination.get())
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0",json.dumps(response.result, indent=4))
get_standby_account_info()
get_operational_account_info()
def get_operational_account():
new_wallet = get_account(ent_operational_seed.get())
ent_operational_account.delete(0, tk.END)
ent_operational_account.insert(0, new_wallet.classic_address)
ent_operational_seed.delete(0, tk.END)
ent_operational_seed.insert(0, new_wallet.seed)
def get_operational_account_info():
accountInfo = get_account_info(ent_operational_account.get())
ent_operational_balance.delete(0, tk.END)
ent_operational_balance.insert(0,accountInfo['Balance'])
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
def operational_send_xrp():
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(), ent_operational_destination.get())
text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0",json.dumps(response.result,indent=4))
get_standby_account_info()
get_operational_account_info()
```
Rename the window for the Authorized Minter examples.
```python
# Create a new window with the title "Quickstart - Authorized Minter"
window = tk.Tk()
window.title("Quickstart - Authorized Minter")
myscrollbar=tk.Scrollbar(window,orient="vertical")
myscrollbar.pack(side="right",fill="y")
standbyRippling = tk.BooleanVar()
operationalRippling = tk.BooleanVar()
# Form frame
frm_form = tk.Frame(relief=tk.SUNKEN, borderwidth=3)
frm_form.pack()
# Create the Label and Entry widgets for "Standby Account"
lbl_standy_seed = tk.Label(master=frm_form, text="Standby Seed")
ent_standby_seed = tk.Entry(master=frm_form, width=50)
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
ent_standby_account = tk.Entry(master=frm_form, width=50)
lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
ent_standby_amount = tk.Entry(master=frm_form, width=50)
lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
ent_standby_destination = tk.Entry(master=frm_form, width=50)
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
ent_standby_balance = tk.Entry(master=frm_form, width=50)
lbl_standby_currency = tk.Label(master=frm_form, text="Currency")
ent_standby_currency = tk.Entry(master=frm_form, width=50)
cb_standby_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=standbyRippling, onvalue=True, offvalue=False)
lbl_standby_uri = tk.Label(master=frm_form, text="NFT URI")
ent_standby_uri = tk.Entry(master=frm_form, width=50)
lbl_standby_flags = tk.Label(master=frm_form, text="Flags")
ent_standby_flags = tk.Entry(master=frm_form, width=50)
lbl_standby_transfer_fee = tk.Label(master=frm_form, text="Transfer Fee")
ent_standby_transfer_fee = tk.Entry(master=frm_form, width="50")
lbl_standby_taxon = tk.Label(master=frm_form, text="Taxon")
ent_standby_taxon = tk.Entry(master=frm_form, width="50")
lbl_standby_nft_id = tk.Label(master=frm_form, text="NFT ID")
ent_standby_nft_id = tk.Entry(master=frm_form, width="50")
lbl_standby_nft_offer_index = tk.Label(master=frm_form, text="NFT Offer Index")
ent_standby_nft_offer_index = tk.Entry(master=frm_form, width="50")
lbl_standby_owner = tk.Label(master=frm_form, text="Owner")
ent_standby_owner = tk.Entry(master=frm_form, width="50")
lbl_standby_expiration = tk.Label(master=frm_form, text="Expiration")
ent_standby_expiration = tk.Entry(master=frm_form, width="50")
```
Add fields for the **Authorized Minter** and **Issuer**.
```python
lbl_standby_auth_minter = tk.Label(master=frm_form, text="Authorized Minter")
ent_standby_auth_minter = tk.Entry(master=frm_form, width="50")
lbl_standby_issuer = tk.Label(master=frm_form, text="Issuer")
ent_standby_issuer = tk.Entry(master=frm_form, width="50")
lbl_standby_results = tk.Label(master=frm_form,text='Results')
text_standby_results = tk.Text(master=frm_form, height = 50, width = 65)
# Place field in a grid.
lbl_standy_seed.grid(row=0, column=0, sticky="w")
ent_standby_seed.grid(row=0, column=1)
lbl_standby_account.grid(row=2, column=0, sticky="e")
ent_standby_account.grid(row=2, column=1)
lbl_standy_amount.grid(row=3, column=0, sticky="e")
ent_standby_amount.grid(row=3, column=1)
lbl_standby_destination.grid(row=4, column=0, sticky="e")
ent_standby_destination.grid(row=4, column=1)
lbl_standby_balance.grid(row=5, column=0, sticky="e")
ent_standby_balance.grid(row=5, column=1)
lbl_standby_currency.grid(row=6, column=0, sticky="e")
ent_standby_currency.grid(row=6, column=1)
cb_standby_allow_rippling.grid(row=7,column=1, sticky="w")
lbl_standby_uri.grid(row=8, column=0, sticky="e")
ent_standby_uri.grid(row=8, column=1, sticky="w")
lbl_standby_flags.grid(row=9, column=0, sticky="e")
ent_standby_flags.grid(row=9, column=1, sticky="w")
lbl_standby_transfer_fee.grid(row=10, column=0, sticky="e")
ent_standby_transfer_fee.grid(row=10, column=1, sticky="w")
lbl_standby_taxon.grid(row=11, column=0, sticky="e")
ent_standby_taxon.grid(row=11, column=1, sticky="w")
lbl_standby_nft_id.grid(row=12, column=0, sticky="e")
ent_standby_nft_id.grid(row=12, column=1, sticky="w")
lbl_standby_nft_offer_index.grid(row=13, column=0, sticky="ne")
ent_standby_nft_offer_index.grid(row=13, column=1, sticky="w")
lbl_standby_owner.grid(row=14, column=0, sticky="ne")
ent_standby_owner.grid(row=14, column=1, sticky="w")
lbl_standby_expiration.grid(row=15, column=0, sticky="ne")
ent_standby_expiration.grid(row=15, column=1, sticky="w")
```
Add the new fields to the form grid.
```python
lbl_standby_auth_minter.grid(row=16,column=0, sticky="ne")
ent_standby_auth_minter.grid(row=16,column=1, sticky="w")
lbl_standby_issuer.grid(row=17,column=0, sticky="ne")
ent_standby_issuer.grid(row=17,column=1, sticky="w")
lbl_standby_results.grid(row=18, column=0, sticky="ne")
text_standby_results.grid(row=18, column=1, sticky="nw")
cb_standby_allow_rippling.select()
###############################################
## Operational Account ########################
###############################################
# Create the Label and Entry widgets for "Operational Account"
lbl_operational_seed = tk.Label(master=frm_form, text="Operational Seed")
ent_operational_seed = tk.Entry(master=frm_form, width=50)
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
ent_operational_account = tk.Entry(master=frm_form, width=50)
lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
ent_operational_amount = tk.Entry(master=frm_form, width=50)
lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
ent_operational_destination = tk.Entry(master=frm_form, width=50)
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
ent_operational_balance = tk.Entry(master=frm_form, width=50)
lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
ent_operational_currency = tk.Entry(master=frm_form, width=50)
cb_operational_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=operationalRippling, onvalue=True, offvalue=False)
lbl_operational_uri = tk.Label(master=frm_form, text="NFT URI")
ent_operational_uri = tk.Entry(master=frm_form, width=50)
lbl_operational_flags = tk.Label(master=frm_form, text="Flags")
ent_operational_flags = tk.Entry(master=frm_form, width=50)
lbl_operational_transfer_fee = tk.Label(master=frm_form, text="Transfer Fee")
ent_operational_transfer_fee = tk.Entry(master=frm_form, width="50")
lbl_operational_taxon = tk.Label(master=frm_form, text="Taxon")
ent_operational_taxon = tk.Entry(master=frm_form, width="50")
lbl_operational_nft_id = tk.Label(master=frm_form, text="NFT ID")
ent_operational_nft_id = tk.Entry(master=frm_form, width="50")
lbl_operational_nft_offer_index = tk.Label(master=frm_form, text="NFT Offer Index")
ent_operational_nft_offer_index = tk.Entry(master=frm_form, width="50")
lbl_operational_owner = tk.Label(master=frm_form, text="Owner")
ent_operational_owner = tk.Entry(master=frm_form, width="50")
lbl_operational_expiration = tk.Label(master=frm_form, text="Expiration")
ent_operational_expiration = tk.Entry(master=frm_form, width="50")
```
Add *Authorized Minter* and *Issuer* fields to the Operational side of the form.
```python
lbl_operational_auth_minter = tk.Label(master=frm_form, text="Authorized Minter")
ent_operational_auth_minter = tk.Entry(master=frm_form, width="50")
lbl_operational_issuer = tk.Label(master=frm_form, text="Issuer")
ent_operational_issuer = tk.Entry(master=frm_form, width="50")
lbl_operational_results = tk.Label(master=frm_form,text="Results")
text_operational_results = tk.Text(master=frm_form, height = 50, width = 65)
#Place the widgets in a grid
lbl_operational_seed.grid(row=0, column=4, sticky="e")
ent_operational_seed.grid(row=0, column=5, sticky="w")
lbl_operational_account.grid(row=2,column=4, sticky="e")
ent_operational_account.grid(row=2,column=5, sticky="w")
lbl_operational_amount.grid(row=3, column=4, sticky="e")
ent_operational_amount.grid(row=3, column=5, sticky="w")
lbl_operational_destination.grid(row=4, column=4, sticky="e")
ent_operational_destination.grid(row=4, column=5, sticky="w")
lbl_operational_balance.grid(row=5, column=4, sticky="e")
ent_operational_balance.grid(row=5, column=5, sticky="w")
lbl_operational_currency.grid(row=6, column=4, sticky="e")
ent_operational_currency.grid(row=6, column=5)
cb_operational_allow_rippling.grid(row=7,column=5, sticky="w")
lbl_operational_uri.grid(row=8, column=4, sticky="e")
ent_operational_uri.grid(row=8, column=5, sticky="w")
lbl_operational_flags.grid(row=9, column=4, sticky="e")
ent_operational_flags.grid(row=9, column=5, sticky="w")
lbl_operational_transfer_fee.grid(row=10, column=4, sticky="e")
ent_operational_transfer_fee.grid(row=10, column=5, sticky="w")
lbl_operational_taxon.grid(row=11, column=4, sticky="e")
ent_operational_taxon.grid(row=11, column=5, sticky="w")
lbl_operational_nft_id.grid(row=12, column=4, sticky="e")
ent_operational_nft_id.grid(row=12, column=5, sticky="w")
lbl_operational_nft_offer_index.grid(row=13, column=4, sticky="ne")
ent_operational_nft_offer_index.grid(row=13, column=5, sticky="w")
lbl_operational_owner.grid(row=14, column=4, sticky="ne")
ent_operational_owner.grid(row=14, column=5, sticky="w")
lbl_operational_expiration.grid(row=15, column=4, sticky="ne")
ent_operational_expiration.grid(row=15, column=5, sticky="w")
```
Add *Authorized Minter* and *Issuer* fields to the Operational grid.
```python
lbl_operational_auth_minter.grid(row=16, column=4, sticky="ne")
ent_operational_auth_minter.grid(row=16, column=5, sticky="w")
lbl_operational_issuer.grid(row=17, column=4, sticky="ne")
ent_operational_issuer.grid(row=17, column=5, sticky="w")
lbl_operational_results.grid(row=18, column=4, sticky="ne")
text_operational_results.grid(row=18, column=5, sticky="nw")
cb_operational_allow_rippling.select()
#############################################
## Buttons ##################################
#############################################
# Create the Standby Account Buttons
btn_get_standby_account = tk.Button(master=frm_form, text="Get Standby Account",
command = get_standby_account)
btn_get_standby_account.grid(row=0, column=2, sticky = "nsew")
btn_get_standby_account_info = tk.Button(master=frm_form,
text="Get Standby Account Info",
command = get_standby_account_info)
btn_get_standby_account_info.grid(row=1, column=2, sticky = "nsew")
btn_standby_send_xrp = tk.Button(master=frm_form, text="Send XRP >",
command = standby_send_xrp)
btn_standby_send_xrp.grid(row=2, column = 2, sticky = "nsew")
btn_standby_create_trust_line = tk.Button(master=frm_form,
text="Create Trust Line",
command = standby_create_trust_line)
btn_standby_create_trust_line.grid(row=4, column=2, sticky = "nsew")
btn_standby_send_currency = tk.Button(master=frm_form, text="Send Currency >",
command = standby_send_currency)
btn_standby_send_currency.grid(row=5, column=2, sticky = "nsew")
btn_standby_send_currency = tk.Button(master=frm_form, text="Get Balances",
command = get_balances)
btn_standby_send_currency.grid(row=6, column=2, sticky = "nsew")
btn_standby_configure_account = tk.Button(master=frm_form,
text="Configure Account",
command = standby_configure_account)
btn_standby_configure_account.grid(row=7,column=0, sticky = "nsew")
btn_standby_mint_token = tk.Button(master=frm_form, text="Mint NFT",
command = standby_mint_token)
btn_standby_mint_token.grid(row=8, column=2, sticky="nsew")
btn_standby_get_tokens = tk.Button(master=frm_form, text="Get NFTs",
command = standby_get_tokens)
btn_standby_get_tokens.grid(row=9, column=2, sticky="nsew")
btn_standby_burn_token = tk.Button(master=frm_form, text="Burn NFT",
command = standby_burn_token)
btn_standby_burn_token.grid(row=10, column=2, sticky="nsew")
btn_standby_create_sell_offer = tk.Button(master=frm_form, text="Create Sell Offer",
command = standby_create_sell_offer)
btn_standby_create_sell_offer.grid(row=11, column=2, sticky="nsew")
btn_standby_accept_sell_offer = tk.Button(master=frm_form, text="Accept Sell Offer",
command = standby_accept_sell_offer)
btn_standby_accept_sell_offer.grid(row=12, column=2, sticky="nsew")
btn_standby_create_buy_offer = tk.Button(master=frm_form, text="Create Buy Offer",
command = standby_create_buy_offer)
btn_standby_create_buy_offer.grid(row=13, column=2, sticky="nsew")
btn_standby_accept_buy_offer = tk.Button(master=frm_form, text="Accept Buy Offer",
command = standby_accept_buy_offer)
btn_standby_accept_buy_offer.grid(row=14, column=2, sticky="nsew")
btn_standby_get_offers = tk.Button(master=frm_form, text="Get Offers",
command = standby_get_offers)
btn_standby_get_offers.grid(row=15, column=2, sticky="nsew")
btn_standby_cancel_offer = tk.Button(master=frm_form, text="Cancel Offer",
command = standby_cancel_offer)
btn_standby_cancel_offer.grid(row=16, column=2, sticky="nsew")
```
Add buttons for *Set Minter* and *Mint Other* to the Standby side of the form.
```python
btn_standby_set_minter = tk.Button(master=frm_form, text="Set Minter",
command = standby_set_minter)
btn_standby_set_minter.grid(row=17, column=2, sticky="nsew")
btn_standby_mint_other = tk.Button(master=frm_form, text="Mint Other",
command = standby_mint_other)
btn_standby_mint_other.grid(row=18, column=2, sticky="new")
# Create the Operational Account Buttons
btn_get_operational_account = tk.Button(master=frm_form,
text="Get Operational Account",
command = get_operational_account)
btn_get_operational_account.grid(row=0, column=3, sticky = "nsew")
btn_get_op_account_info = tk.Button(master=frm_form, text="Get Op Account Info",
command = get_operational_account_info)
btn_get_op_account_info.grid(row=1, column=3, sticky = "nsew")
btn_op_send_xrp = tk.Button(master=frm_form, text="< Send XRP",
command = operational_send_xrp)
btn_op_send_xrp.grid(row=2, column = 3, sticky = "nsew")
btn_op_create_trust_line = tk.Button(master=frm_form, text="Create Trust Line",
command = operational_create_trust_line)
btn_op_create_trust_line.grid(row=4, column=3, sticky = "nsew")
btn_op_send_currency = tk.Button(master=frm_form, text="< Send Currency",
command = operational_send_currency)
btn_op_send_currency.grid(row=5, column=3, sticky = "nsew")
btn_op_get_balances = tk.Button(master=frm_form, text="Get Balances",
command = get_balances)
btn_op_get_balances.grid(row=6, column=3, sticky = "nsew")
btn_op_configure_account = tk.Button(master=frm_form, text="Configure Account",
command = operational_configure_account)
btn_op_configure_account.grid(row=7,column=4, sticky = "nsew")
btn_op_mint_token = tk.Button(master=frm_form, text="Mint NFT",
command = operational_mint_token)
btn_op_mint_token.grid(row=8, column=3, sticky="nsew")
btn_op_get_tokens = tk.Button(master=frm_form, text="Get NFTs",
command = operational_get_tokens)
btn_op_get_tokens.grid(row=9, column=3, sticky="nsew")
btn_op_burn_token = tk.Button(master=frm_form, text="Burn NFT",
command = operational_burn_token)
btn_op_burn_token.grid(row=10, column=3, sticky="nsew")
btn_op_create_sell_offer = tk.Button(master=frm_form, text="Create Sell Offer",
command = op_create_sell_offer)
btn_op_create_sell_offer.grid(row=11, column=3, sticky="nsew")
btn_op_accept_sell_offer = tk.Button(master=frm_form, text="Accept Sell Offer",
command = op_accept_sell_offer)
btn_op_accept_sell_offer.grid(row=12, column=3, sticky="nsew")
btn_op_create_buy_offer = tk.Button(master=frm_form, text="Create Buy Offer",
command = op_create_buy_offer)
btn_op_create_buy_offer.grid(row=13, column=3, sticky="nsew")
btn_op_accept_buy_offer = tk.Button(master=frm_form, text="Accept Buy Offer",
command = op_accept_buy_offer)
btn_op_accept_buy_offer.grid(row=14, column=3, sticky="nsew")
btn_op_get_offers = tk.Button(master=frm_form, text="Get Offers",
command = op_get_offers)
btn_op_get_offers.grid(row=15, column=3, sticky="nsew")
btn_op_cancel_offer = tk.Button(master=frm_form, text="Cancel Offer",
command = op_cancel_offer)
btn_op_cancel_offer.grid(row=16, column=3, sticky="nsew")
```
Add *Set Minter* and *Mint Other* buttons to the Operational side of the form.
```python
btn_op_set_minter = tk.Button(master=frm_form, text="Set Minter",
command = operational_set_minter)
btn_op_set_minter.grid(row=17, column=3, sticky="nsew")
btn_op_mint_other = tk.Button(master=frm_form, text="Mint Other",
command = operational_mint_other)
btn_op_mint_other.grid(row=18, column=3, sticky="new")
# Start the application
window.mainloop()
```

View File

@@ -0,0 +1,405 @@
---
html: py-batch-minting.html
parent: quickstart-python.html
blurb: Mint multiple NFTs with the press of a button.
labels:
- Accounts
- Quickstart
- NFTs
- XRP
---
# Batch Mint NFTs
You can create an application that mints multiple NFTs at one time, using a `for` loop to send one transaction after another.
A best practice is to use `Tickets` to reserve the transaction sequence numbers. If you create an application that creates NFTs without using tickets, if any transaction fails for any reason, the application stops with an error. If you use tickets, the application continues to send transactions, and you can look into the reason for any individual failures afterward.
[![Batch Mint](img/quickstart-py36.png)](img/quickstart-py36.png)
## Usage
You can download or clone the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} to try the sample in your own browser.
## Get an Account
1. Open and run `lesson7-batch-minting.py`.
2. Get a test account.
1. If you want to use an existing account seed:
1. Paste the account seed in the **Standby Seed** field.
2. Click **Get Standby Account**.
2. If you do not want to use an existing account seed, click **Get Standby Account**.
## Batch Mint NFTs
This example lets you mint multiple NFTs for a single unique item. The NFT might represent "prints" of an original artwork, tickets to an event, or another limited set of unique items.
To batch mint non-fungible token objects:
1. 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. See [NFTokenMint](nftokenmint.html) for available NFT minting flags.
2. Enter the **NFT URI**. 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.
3. Enter an **NFT Count** of up to 200 NFTs to create in one batch.
4. 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 fees 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.
5. Click **Batch Mint NFTs**.
## Get Batch NFTs
Click **Get Batch NFTs** to get the current list of NFTs for your account.
The difference between this function and the `getTokens()` function used earlier is that it allows for larger lists of tokens, sending multiple requests if the tokens exceed the number of objects allowed in a single request.
# Code Walkthrough
You can download or clone the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} to try each of the samples locally.
Import dependencies and define the testnet_url variable.
```python
import xrpl
from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.requests import AccountNFTs
testnet_url = "https://s.altnet.rippletest.net:51234"
```
## Batch Mint
Pass the values `seed`, `uri`, `flags`, `transfer_fee`, `taxon`, and `count`.
```python
def batch_mint(seed, uri, flags, transfer_fee, taxon, count):
"""batch_mint"""
```
Get the account wallet and a client instance.
```python
wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
```
Request the full account info.
```python
acct_info = xrpl.models.requests.account_info.AccountInfo(
account=wallet.classic_address,
ledger_index='validated'
)
get_seq_request = client.request(acct_info)
```
Parse the current sequence value.
```python
current_sequence=get_seq_request.result['account_data']['Sequence']
```
Create a transaction to create tickets, starting at the current sequence number.
```python
ticket_tx=xrpl.models.transactions.TicketCreate(
account=wallet.address,
ticket_count=int(count),
sequence=current_sequence
)
```
Submit the ticket transaction and wait for the result.
```python
response=xrpl.transaction.submit_and_wait(ticket_tx,client,wallet)
```
Create a request to obtain the next ticket number.
```python
ticket_numbers_req=xrpl.models.requests.AccountObjects(
account=wallet.address,
type='ticket'
)
ticket_response=client.request(ticket_numbers_req)
```
Create the `tickets` variable to store an array of tickets.
```python
tickets=[int(0)] * int(count)
acct_objs= ticket_response.result['account_objects']
```
Create an array of ticket numbers.
```python
for x in range(int(count)):
tickets[x] = acct_objs[x]['TicketSequence']
```
Initialize variables to be used in the mint loop.
```python
reply=""
create_count=0
```
Use a `for` loop to send repeated mint requests, using the `ticket_sequence` field to uniquely identify the mint transactions.
```python
for x in range(int(count)):
mint_tx=xrpl.models.transactions.NFTokenMint(
account=wallet.classic_address,
uri=xrpl.utils.str_to_hex(uri),
flags=int(flags),
transfer_fee=int(transfer_fee),
ticket_sequence=tickets[x],
sequence=0,
nftoken_taxon=int(taxon)
)
```
Submit each transaction and report the results.
```python
try:
response=xrpl.transaction.submit_and_wait(mint_tx,client,
wallet)
create_count+=1
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply+=f"Submit failed: {e}\n"
reply+=str(create_count)+' NFTs generated.'
return reply
```
### Get Batch
This version of `getTokens()` allows for a larger set of NFTs by watching for a `marker` at the end of each batch of NFTs. Subsequent requests get the next batch of NFTs starting at the previous marker, until all NFTs are retrieved.
```python
def get_batch(seed, account):
"""get_batch"""
```
Get a client instance. Since this is a request for publicly available information, no wallet is required.
```python
client=JsonRpcClient(testnet_url)
```
Define the request for account NFTs. Set a return limit of 400 objects.
```python
acct_nfts=AccountNFTs(
account=account,
limit=400
)
```
Send the request.
```python
response=client.request(acct_nfts)
```
Capture the result in the _responses_ variable.
```python
responses=response.result
```
While there is a _marker_ value in the response, continue to define and send requests for 400 account NFTs at a time. Capture the _result_ from each request in the _responses_ variable.
```python
while(acct_nfts.marker):
acct_nfts=AccountNFTs(
account=account,
limit=400,
marker=acct_nfts.marker
)
response=client.request(acct_nfts)
responses+=response.result
```
Return the _responses_ variable.
```python
return responses
```
## lesson7-batch-minting.py
This form is based on earlier examples, with unused fields, handlers, and buttons removed. Additions are highlighted below.
```python
import tkinter as tk
import xrpl
import json
from mod1 import get_account, get_account_info, send_xrp
from mod2 import (
get_balance,
configure_account,
)
```
Import dependencies from `mod7.py`.
```python
from mod7 import batch_mint, get_batch
```
Add Module 7 handlers.
```python
def batch_mint_nfts():
results = batch_mint(
ent_standby_seed.get(),
ent_standby_uri.get(),
ent_standby_flags.get(),
ent_standby_transfer_fee.get(),
ent_standby_taxon.get(),
ent_standby_nft_count.get()
)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
def get_batch_nfts():
results = get_batch(ent_standby_seed.get(), ent_standby_account.get())
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0",json.dumps(results, indent=4))
# Module 2 Handlers
def standby_configure_account():
results = configure_account(
ent_standby_seed.get(),
standbyRippling)
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4))
# Module 1 Handlers
def get_standby_account():
new_wallet = get_account(ent_standby_seed.get())
ent_standby_account.delete(0, tk.END)
ent_standby_seed.delete(0, tk.END)
ent_standby_account.insert(0, new_wallet.classic_address)
ent_standby_seed.insert(0, new_wallet.seed)
def get_standby_account_info():
accountInfo = get_account_info(ent_standby_account.get())
ent_standby_balance.delete(0, tk.END)
ent_standby_balance.insert(0,accountInfo['Balance'])
text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4))
```
Rename the window for Module 7.
```python
# Create a new window with the title "Quickstart Module 7"
window = tk.Tk()
window.title("Quickstart Module 7")
standbyRippling = tk.BooleanVar()
operationalRippling = tk.BooleanVar()
# Form frame
frm_form = tk.Frame(relief=tk.SUNKEN, borderwidth=3)
frm_form.pack()
# Create the Label and Entry widgets for "Standby Account"
lbl_standy_seed = tk.Label(master=frm_form, text="Standby Seed")
ent_standby_seed = tk.Entry(master=frm_form, width=50)
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
ent_standby_account = tk.Entry(master=frm_form, width=50)
lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
ent_standby_amount = tk.Entry(master=frm_form, width=50)
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
ent_standby_balance = tk.Entry(master=frm_form, width=50)
cb_standby_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=standbyRippling, onvalue=True, offvalue=False)
lbl_standby_uri = tk.Label(master=frm_form, text="NFT URI")
ent_standby_uri = tk.Entry(master=frm_form, width=50)
lbl_standby_flags = tk.Label(master=frm_form, text="Flags")
ent_standby_flags = tk.Entry(master=frm_form, width=50)
lbl_standby_transfer_fee = tk.Label(master=frm_form, text="Transfer Fee")
ent_standby_transfer_fee = tk.Entry(master=frm_form, width="50")
lbl_standby_taxon = tk.Label(master=frm_form, text="Taxon")
ent_standby_taxon = tk.Entry(master=frm_form, width="50")
lbl_standby_nft_id = tk.Label(master=frm_form, text="NFT ID")
ent_standby_nft_id = tk.Entry(master=frm_form, width="50")
```
Add the **NFT Count** field for batch minting.
```python
lbl_standby_nft_count=tk.Label(master=frm_form, text="NFT Count")
ent_standby_nft_count=tk.Entry(master=frm_form, width="50")
lbl_standby_results = tk.Label(master=frm_form,text="Results")
text_standby_results = tk.Text(master=frm_form, height = 20, width = 65)
# Place field in a grid.
lbl_standy_seed.grid(row=0, column=0, sticky="w")
ent_standby_seed.grid(row=0, column=1)
lbl_standby_account.grid(row=2, column=0, sticky="e")
ent_standby_account.grid(row=2, column=1)
lbl_standy_amount.grid(row=3, column=0, sticky="e")
ent_standby_amount.grid(row=3, column=1)
lbl_standby_balance.grid(row=5, column=0, sticky="e")
ent_standby_balance.grid(row=5, column=1)
cb_standby_allow_rippling.grid(row=7,column=1, sticky="w")
lbl_standby_uri.grid(row=8, column=0, sticky="e")
ent_standby_uri.grid(row=8, column=1, sticky="w")
lbl_standby_flags.grid(row=9, column=0, sticky="e")
ent_standby_flags.grid(row=9, column=1, sticky="w")
lbl_standby_transfer_fee.grid(row=10, column=0, sticky="e")
ent_standby_transfer_fee.grid(row=10, column=1, sticky="w")
lbl_standby_taxon.grid(row=11, column=0, sticky="e")
ent_standby_taxon.grid(row=11, column=1, sticky="w")
lbl_standby_nft_id.grid(row=12, column=0, sticky="e")
ent_standby_nft_id.grid(row=12, column=1, sticky="w")
```
Place the **NFT Count** field in the grid.
```python
lbl_standby_nft_count.grid(row=13, column=0, sticky="e")
ent_standby_nft_count.grid(row=13, column=1, sticky="w")
lbl_standby_results.grid(row=14, column=0, sticky="ne")
text_standby_results.grid(row=14, column=1, sticky="nw")
cb_standby_allow_rippling.select()
#############################################
## Buttons ##################################
#############################################
# Create the Standby Account Buttons
btn_get_standby_account = tk.Button(master=frm_form, text="Get Standby Account",
command = get_standby_account)
btn_get_standby_account.grid(row=0, column=2, sticky = "nsew")
btn_get_standby_account_info = tk.Button(master=frm_form,
text="Get Standby Account Info",
command = get_standby_account_info)
btn_get_standby_account_info.grid(row=1, column=2, sticky = "nsew")
btn_standby_configure_account = tk.Button(master=frm_form,
text="Configure Account",
command = standby_configure_account)
btn_standby_configure_account.grid(row=7,column=0, sticky = "nsew")
```
Add the **Batch Mint NFTs** and **Get Batch NFTs** buttons.
```python
btn_standby_mint_token = tk.Button(master=frm_form, text="Batch Mint NFTs",
command = batch_mint_nfts)
btn_standby_mint_token.grid(row=8, column=2, sticky="nsew")
btn_standby_get_tokens = tk.Button(master=frm_form, text="Get Batch NFTs",
command = get_batch_nfts)
btn_standby_get_tokens.grid(row=9, column=2, sticky="nsew")
# Start the application
window.mainloop()
```

View File

@@ -1,6 +1,6 @@
--- ---
html: py-broker-sale.html html: py-broker-sale.html
parent: send-payments-using-python.html parent: nfts-using-python.html
blurb: Broker a sale between a sell offer and a buy offer. blurb: Broker a sale between a sell offer and a buy offer.
labels: labels:
- Accounts - Accounts
@@ -23,7 +23,7 @@ This example shows how to:
[![Quickstart form with Broker Account](img/quickstart-py23.png)](img/quickstart-py23.png) [![Quickstart form with Broker Account](img/quickstart-py23.png)](img/quickstart-py23.png)
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to try each of the samples in your own browser.
## Get Accounts ## Get Accounts
@@ -96,7 +96,7 @@ After accepting a buy offer, a best practice for the broker is to cancel all oth
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to examine the code samples. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to examine the code samples.
## ripplex5-broker-nfts.js ## ripplex5-broker-nfts.js
<!-- SPELLING_IGNORE: ripplex5 --> <!-- SPELLING_IGNORE: ripplex5 -->
@@ -107,7 +107,6 @@ Import dependencies and create a global variable for `testnet_url`.
```python ```python
import xrpl import xrpl
import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
testnet_url = "https://s.altnet.rippletest.net:51234" testnet_url = "https://s.altnet.rippletest.net:51234"
@@ -125,7 +124,7 @@ def broker_sale(seed, sell_offer_index, buy_offer_index, broker_fee):
Get the broker wallet and establish a client connection. Get the broker wallet and establish a client connection.
```python ```python
broker_wallet=Wallet(seed, sequence=16237283) broker_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -140,22 +139,16 @@ Define the accept offer transaction, matching a sell offer with the selected buy
) )
``` ```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, broker_wallet, client)
```
Submit the transaction and report the results. Submit the transaction and report the results.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,broker_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
return reply
``` ```
## lesson5-broker-nfts.py ## lesson5-broker-nfts.py
@@ -882,4 +875,4 @@ btn_op_cancel_offer.grid(row=16, column=3, sticky="nsew")
# Start the application # Start the application
window.mainloop() window.mainloop()
``` ```x

View File

@@ -63,20 +63,24 @@ To transfer XRP from the Operational account to the Standby account:
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} in the source repository for this website. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} in the source repository for this website.
## mod1.py ## mod1.py
The mod1.py module contains the business logic for interacting with the XRP Ledger. The mod1.py module contains the business logic for interacting with the XRP Ledger.
Import the XRPL and JSON libraries, and the module 1 methods. Import the XRPL library.
```python ```python
import xrpl import xrpl
import json
import xrpl.clients
import xrpl.wallet
```
Create a variable for the server URI. This example uses the _Testnet_ ledger. You can update the URI to choose a different XRP Ledger instance.
```python
testnet_url = "https://s.altnet.rippletest.net:51234/"
``` ```
### get_account ### get_account
@@ -90,16 +94,10 @@ def get_account(seed):
"""get_account""" """get_account"""
``` ```
This example uses the _Testnet_ ledger. You can update the URI to choose a different XRP Ledger instance.
```python
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
```
Request a new client from the XRP Ledger. Request a new client from the XRP Ledger.
```python ```python
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL) client = xrpl.clients.JsonRpcClient(testnet_url)
``` ```
If you do not enter a seed, generate and return a new wallet. If you provide a seed value, return the wallet for that seed. If you do not enter a seed, generate and return a new wallet. If you provide a seed value, return the wallet for that seed.
@@ -108,8 +106,8 @@ If you do not enter a seed, generate and return a new wallet. If you provide a s
if (seed == ''): if (seed == ''):
new_wallet = xrpl.wallet.generate_faucet_wallet(client) new_wallet = xrpl.wallet.generate_faucet_wallet(client)
else: else:
new_wallet = xrpl.wallet.Wallet(seed, sequence = 79396029) new_wallet = xrpl.wallet.Wallet.from_seed(seed)
return(new_wallet) return new_wallet
``` ```
### get_account_info ### get_account_info
@@ -124,8 +122,7 @@ def get_account_info(accountId):
Get a client instance from Testnet. Get a client instance from Testnet.
```python ```python
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234' client = xrpl.clients.JsonRpcClient(testnet_url)
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
``` ```
Create the account info request, passing the account ID and the ledger index (in this case, the latest validated ledger). Create the account info request, passing the account ID and the ledger index (in this case, the latest validated ledger).
@@ -160,35 +157,26 @@ def send_xrp(seed, amount, destination):
Get the sending wallet. Get the sending wallet.
```python ```python
sending_wallet = xrpl.wallet.Wallet(seed, sequence = 16237283) sending_wallet = xrpl.wallet.Wallet.from_seed(seed)
testnet_url = "https://s.altnet.rippletest.net:51234"
client = xrpl.clients.JsonRpcClient(testnet_url) client = xrpl.clients.JsonRpcClient(testnet_url)
``` ```
Create a transaction request, passing the sending account, amount, and destination account. Create a transaction request, passing the sending account, amount, and destination account.
```python ```python
payment=xrpl.models.transactions.Payment( payment = xrpl.models.transactions.Payment(
account=sending_wallet.classic_address, account=sending_wallet.address,
amount=xrpl.utils.xrp_to_drops(int(amount)), amount=xrpl.utils.xrp_to_drops(int(amount)),
destination=destination, destination=destination,
) )
``` ```
Sign the transaction.
```python
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
payment, sending_wallet, client)
```
Submit the transaction and return the response. If the transaction fails, return the error message. Submit the transaction and return the response. If the transaction fails, return the error message.
```python ```python
try: try:
tx_response = xrpl.transaction.send_reliable_submission(signed_tx,client) response = xrpl.transaction.submit_and_wait(payment, client, sending_wallet)
response = tx_response except xrpl.transaction.XRPLReliableSubmissionException as e:
except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" response = f"Submit failed: {e}"
return response return response
``` ```
@@ -429,4 +417,3 @@ Start the application.
```python ```python
window.mainloop() window.mainloop()
``` ```

View File

@@ -20,7 +20,7 @@ This example shows how to:
[![Test harness with currency transfer](img/quickstart-py5.png)](img/quickstart-py5.png) [![Test harness with currency transfer](img/quickstart-py5.png)](img/quickstart-py5.png)
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to try each of the samples in your own browser.
**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow. **Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.
@@ -83,7 +83,7 @@ Verify the setting by looking for the _Clear Flag_ value in the response, which
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to try each of the samples.
## mod2.py ## mod2.py
@@ -93,10 +93,8 @@ Import dependencies and set the `testnet_url`.
```python ```python
import xrpl import xrpl
import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
from xrpl.models.requests.account_info import AccountInfo
testnet_url = "https://s.altnet.rippletest.net:51234" testnet_url = "https://s.altnet.rippletest.net:51234"
``` ```
@@ -113,7 +111,7 @@ def create_trust_line(seed, issuer, currency, amount):
Get the wallet and a new client instance. Get the wallet and a new client instance.
```python ```python
receiving_wallet = Wallet(seed, sequence = 16237283) receiving_wallet = Wallet.from_seed(seed)
client = JsonRpcClient(testnet_url) client = JsonRpcClient(testnet_url)
``` ```
@@ -121,7 +119,7 @@ Define the `TrustSet` transaction.
```python ```python
trustline_tx=xrpl.models.transactions.TrustSet( trustline_tx=xrpl.models.transactions.TrustSet(
account=receiving_wallet.classic_address, account=receiving_wallet.address,
limit_amount=xrpl.models.amounts.IssuedCurrencyAmount( limit_amount=xrpl.models.amounts.IssuedCurrencyAmount(
currency=currency, currency=currency,
issuer=issuer, issuer=issuer,
@@ -130,28 +128,17 @@ Define the `TrustSet` transaction.
) )
``` ```
Sign the transaction.
```python
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
trustline_tx, receiving_wallet, client)
```
Submit the transaction to the XRP Ledger. Submit the transaction to the XRP Ledger.
```python ```python
reply = "" response = xrpl.transaction.submit_and_wait(trustline_tx,
try: client, receiving_wallet)
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
``` ```
Return the results. Return the results.
```python ```python
return reply return response.result
``` ```
## send_currency ## send_currency
@@ -165,7 +152,7 @@ def send_currency(seed, destination, currency, amount):
Get the sending wallet and a client instance on Testnet. Get the sending wallet and a client instance on Testnet.
```python ```python
sending_wallet=Wallet(seed, sequence=16237283) sending_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -173,38 +160,25 @@ Define the payment transaction. The amount requires further description to ident
```python ```python
send_currency_tx=xrpl.models.transactions.Payment( send_currency_tx=xrpl.models.transactions.Payment(
account=sending_wallet.classic_address, account=sending_wallet.address,
amount=xrpl.models.amounts.IssuedCurrencyAmount( amount=xrpl.models.amounts.IssuedCurrencyAmount(
currency=currency, currency=currency,
value=int(amount), value=int(amount),
issuer=sending_wallet.classic_address issuer=sending_wallet.address
), ),
destination=destination destination=destination
) )
``` ```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
send_currency_tx, sending_wallet, client)
```
Submit the transaction and get the response. Submit the transaction and get the response.
```python ```python
reply = "" response=xrpl.transaction.submit_and_wait(send_currency_tx, client, sending_wallet)```
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
```
Return the JSON response, or an error message if the transaction fails. Return the results.
```python ```python
return reply return response.result
``` ```
### get_balance ### get_balance
@@ -219,8 +193,7 @@ def get_balance(sb_account_id, op_account_id):
Connect to the XRP Ledger and instantiate a client. Connect to the XRP Ledger and instantiate a client.
```python ```python
JSON_RPC_URL='wss://s.altnet.rippletest.net:51234' client=JsonRpcClient(testnet_url)
client=JsonRpcClient(JSON_RPC_URL)
``` ```
Create the `GatewayBalances` request. Create the `GatewayBalances` request.
@@ -253,7 +226,7 @@ def configure_account(seed, default_setting):
Get the account wallet and instantiate a client. Get the account wallet and instantiate a client.
```python ```python
wallet=Wallet(seed, sequence = 16237283) wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -263,37 +236,20 @@ If `default_setting` is true, create a `set_flag` transaction to enable ripplin
if (default_setting): if (default_setting):
setting_tx=xrpl.models.transactions.AccountSet( setting_tx=xrpl.models.transactions.AccountSet(
account=wallet.classic_address, account=wallet.classic_address,
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
) )
else: else:
setting_tx=xrpl.models.transactions.AccountSet( setting_tx=xrpl.models.transactions.AccountSet(
account=wallet.classic_address, account=wallet.classic_address,
clear_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
) )
``` ```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
setting_tx, wallet, client)
```
Submit the transaction and get results. Submit the transaction and get results.
```python ```python
reply = "" response=xrpl.transaction.submit_and_wait(setting_tx,client,wallet)
try: return response.result
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
```
Return the results.
```python
return reply
``` ```
## lesson2-send-currency.py ## lesson2-send-currency.py
@@ -615,4 +571,4 @@ btn_op_configure_account.grid(row=7,column=4, sticky = "nsew")
```python ```python
window.mainloop() window.mainloop()
``` ```

View File

@@ -1,6 +1,6 @@
--- ---
html: py-mint-and-burn-nfts.html html: py-mint-and-burn-nfts.html
parent: send-payments-using-python.html parent: nfts-using-python.html
blurb: Mint and burn NFTs. blurb: Mint and burn NFTs.
labels: labels:
- Quickstart - Quickstart
@@ -20,7 +20,7 @@ This example shows how to:
# Usage # Usage
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try the sample in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to try the sample in your own browser.
## Get Accounts ## Get Accounts
@@ -71,7 +71,7 @@ To permanently destroy an NFT:
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to examine the code samples. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to examine the code samples.
## mod3.py ## mod3.py
@@ -81,12 +81,10 @@ Import dependencies and set global variable.
```python ```python
import xrpl import xrpl
import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
from xrpl.models.requests import AccountNFTs from xrpl.models.requests import AccountNFTs
testnet_url = "https://s.altnet.rippletest.net:51234" testnet_url = "https://s.altnet.rippletest.net:51234"
``` ```
@@ -96,12 +94,13 @@ Pass the arguments account seed, NFT URI, transaction flags, the transfer fee, a
```python ```python
def mint_token(seed, uri, flags, transfer_fee, taxon): def mint_token(seed, uri, flags, transfer_fee, taxon):
"""mint_token"""
``` ```
Get the account wallet and a client instance. Get the account wallet and a client instance.
```python ```python
mint_wallet=Wallet(seed, sequence=16237283) minter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -109,7 +108,7 @@ Define the mint transaction. Note that the NFT URI must be converted to a hex st
```python ```python
mint_tx=xrpl.models.transactions.NFTokenMint( mint_tx=xrpl.models.transactions.NFTokenMint(
account=mint_wallet.classic_address, account=minter_wallet.address,
uri=xrpl.utils.str_to_hex(uri), uri=xrpl.utils.str_to_hex(uri),
flags=int(flags), flags=int(flags),
transfer_fee=int(transfer_fee), transfer_fee=int(transfer_fee),
@@ -117,19 +116,12 @@ Define the mint transaction. Note that the NFT URI must be converted to a hex st
) )
``` ```
Sign and fill the transaction.
```python
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
mint_tx, mint_wallet, client)
```
Submit the transaction and return results. Submit the transaction and return results.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(mint_tx,client,minter_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -176,7 +168,7 @@ def burn_token(seed, nftoken_id):
Get the owner wallet and client instance. Get the owner wallet and client instance.
```python ```python
owner_wallet=Wallet(seed, sequence=16237283) owner_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -184,31 +176,23 @@ Define the NFTokenBurn transaction.
```python ```python
burn_tx=xrpl.models.transactions.NFTokenBurn( burn_tx=xrpl.models.transactions.NFTokenBurn(
account=owner_wallet.classic_address, account=owner_wallet.address,
nftoken_id=nftoken_id nftoken_id=nftoken_id
) )
``` ```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
burn_tx, owner_wallet, client)
```
Submit the transaction and return results. Submit the transaction and return results.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(burn_tx,client,owner_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
return reply return reply
``` ```
## lesson3-mint-token.py ## lesson3-mint-token.py
<!-- SPELLING_IGNORE: lesson3 --> <!-- SPELLING_IGNORE: lesson3 -->
@@ -646,4 +630,3 @@ btn_op_burn_token.grid(row=10, column=3, sticky="nsew")
# Start the application # Start the application
window.mainloop() window.mainloop()
``` ```

View File

@@ -0,0 +1,57 @@
quickstart---
html: py-quickstart-intro.html
parent: quickstart-python.html
blurb: Use a Python test harness to send XRP, trade currencies, and mint and trade NFTs.
labels:
- Accounts
- Cross-Currency
- Non-fungible Tokens, NFTs
- Payments
- Quickstart
- Tokens
- XRP
---
# Quickstart Introduction (Python)
The XRP Ledger (XRPL) is a robust, secure, customizable service. You can create your own interface to try out the capabilities and support your specific business needs.
This quickstart describes a test harness interface you can build to try out the XRP Ledger. The test harness displays multiple accounts, so that you can transfer tokens from one account to the other and see the results in real time. The image below shows the Token Test Harness at the completion of step 4.
[![Quickstart Tutorial Window](img/quickstart-py15.png)](img/quickstart-py15.png)
That is a lot of fields and buttons, all working together to perform some significant practical tasks. But getting _started_ with the XRP Ledger is not that complicated. When you eat the elephant a bite at a time, none of the tasks are difficult to consume.
Typically, the example functions for interacting with the XRP Ledger involve four steps.
1. Connect to the XRP Ledger and instantiate your wallet.
2. Make changes to the XRP Ledger using transactions.
3. Get the state of accounts and tokens on the XRP Ledger using requests.
4. Disconnect from the XRP Ledger.
Each lesson shows you how to build the Token Test Harness one section at a time. Each module lets you try out meaningful interactions with the test ledger, with complete Python code samples and a code walkthrough. There is also a link to the complete source code for each section that can be modified with a text editor and run in a Python environment. You can try out the examples in any order.
This quickstart tutorial introduces you to the API used to implement features and explore the capabilities of XRP Ledger. It does not represent _all_ of the capabilities of the API and this example is not intended for production or secure payment use.
Much of this is “brute force” code that sacrifices conciseness for readability. Each example builds on the previous step, adding a new Python UI file and a module to support the new behavior in the lesson. We expect the applications you build to greatly improve upon these examples. Your feedback and contributions are most welcome.
In this quickstart, you can:
1. [Create Accounts and Send XRP](py-create-accounts-send-xrp.html)
2. [Create Trust Line and Send Currency](py-create-trustline-send-currency.html).
3. [Mint and Burn NFTs](py-mint-and-burn-nfts.html).
4. [Transfer NFTs](py-transfer-nfts.html).
There are also expanded lessons demonstrating how to [Broker an NFT Sale](py-broker-sale.html) and [Assign an Authorized Minter](py-authorize-minter.html).
## Prerequisites
To get started, create a new folder on your local disk and install the Python library (xrpl-py) using `pip`.
```
pip3 install xrpl-py
```
Download the python [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download}.
**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.

View File

@@ -1,6 +1,6 @@
--- ---
html: py-transfer-nfts.html html: py-transfer-nfts.html
parent: send-payments-using-python.html parent: nfts-using-python.html
blurb: Use a Python test harness to create and accept NFT buy and sell offers. blurb: Use a Python test harness to create and accept NFT buy and sell offers.
labels: labels:
- Quickstart - Quickstart
@@ -21,7 +21,7 @@ This example shows how to:
[![Quickstart form with NFT transfer fields](img/quickstart-py15.png)](img/quickstart-py15.png) [![Quickstart form with NFT transfer fields](img/quickstart-py15.png)](img/quickstart-py15.png)
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to try each of the samples in your own browser.
# Usage # Usage
@@ -120,7 +120,7 @@ To cancel a buy or sell offer that you have created:
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to try each of the samples in your own browser.
## mod4.py ## mod4.py
This module contains the new methods `create_sell_offer`, `create_buy_offer`, `accept_sell_offer`, `accept_buy_offer`, `get_offers`, and `cancel_offer`. This module contains the new methods `create_sell_offer`, `create_buy_offer`, `accept_sell_offer`, `accept_buy_offer`, `get_offers`, and `cancel_offer`.
@@ -152,7 +152,7 @@ def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
Get the owner wallet and create a client connection. Get the owner wallet and create a client connection.
```python ```python
owner_wallet = Wallet(seed, sequence=16237283) owner_wallet = Wallet.from_seed(seed)
client = JsonRpcClient(testnet_url) client = JsonRpcClient(testnet_url)
``` ```
@@ -169,7 +169,7 @@ Define the sell offer transaction.
```python ```python
sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer( sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account=owner_wallet.classic_address, account=owner_wallet.address,
nftoken_id=nftoken_id, nftoken_id=nftoken_id,
amount=amount, amount=amount,
``` ```
@@ -192,19 +192,12 @@ Set the `flags` value to _1_, indicating that this is a sell offer.
) )
``` ```
Sign the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
sell_offer_tx, owner_wallet, client)
```
Submit the transaction. Submit the transaction.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(sell_offer_tx,client,owner_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -228,7 +221,7 @@ def accept_sell_offer(seed, offer_index):
Get the wallet and a client instance. Get the wallet and a client instance.
```python ```python
buyer_wallet=Wallet(seed, sequence=16237283) buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -253,7 +246,7 @@ Submit the transaction and report the results.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,buyer_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -272,7 +265,7 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
Get the buyer wallet and a client instance. Get the buyer wallet and a client instance.
```python ```python
buyer_wallet=Wallet(seed, sequence=16237283) buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -289,7 +282,7 @@ Define the buy offer transaction.
```python ```python
buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer( buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account=buyer_wallet.classic_address, account=buyer_wallet.address,
nftoken_id=nft_id, nftoken_id=nft_id,
amount=amount, amount=amount,
owner=owner, owner=owner,
@@ -314,19 +307,12 @@ Set the _flags_ value to _0_, indicating that this is a "buy" offer.
) )
``` ```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
buy_offer_tx, buyer_wallet, client)
```
Submit the transaction and report the results. Submit the transaction and report the results.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(buy_offer_tx,client,buyer_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -345,7 +331,7 @@ def accept_buy_offer(seed, offer_index):
Get the buyer wallet and a client instance. Get the buyer wallet and a client instance.
```python ```python
buyer_wallet=Wallet(seed, sequence=16237283) buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
@@ -353,24 +339,17 @@ Define the accept offer transaction.
```python ```python
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer( accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account=buyer_wallet.classic_address, account=buyer_wallet.address,
nftoken_buy_offer=offer_index nftoken_buy_offer=offer_index
) )
``` ```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, buyer_wallet, client)
```
Submit the transaction and report the results Submit the transaction and report the results
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,buyer_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -469,19 +448,12 @@ Define the cancel offer transaction.
) )
``` ```
Sign the transaction.
```python
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
cancel_offer_tx, owner_wallet, client)
```
Submit the transaction and return the result. Submit the transaction and return the result.
```python ```python
reply="" reply=""
try: try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client) response=xrpl.transaction.submit_and_wait(cancel_offer_tx,client,owner_wallet)
reply=response.result reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e: except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}" reply=f"Submit failed: {e}"
@@ -1044,4 +1016,4 @@ btn_op_cancel_offer.grid(row=16, column=3, sticky="nsew")
# Start the application # Start the application
window.mainloop() window.mainloop()
``` ```

View File

@@ -1,7 +1,7 @@
--- ---
html: send-payments-using-python.html html: send-payments-using-python.html
parent: modular-tutorials-in-python.html parent: modular-tutorials-in-python.html
blurb: Use a Python test harness to send XRP, trade currencies, and mint and trade NFTs. blurb: Use a Python test harness to send XRP,trade currencies, and more.
labels: labels:
- Accounts - Accounts
- Cross-Currency - Cross-Currency

View File

@@ -105,7 +105,7 @@ To cancel a buy or sell offer that you have created:
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} archive to try each of the samples in your own browser.
## Create Sell Offer ## Create Sell Offer

View File

@@ -55,7 +55,7 @@ To create your first NFTs, follow the instructions in the tutorial _Mint and Bur
The NFToken URL is a link to the location where the content of the NFT is stored. One option is create an IPFS account and store the NFToken content at a persistent URL. See [Best Practices for Storing NFT Data](https://docs.ipfs.io/how-to/best-practices-for-nft-data). The NFToken URL is a link to the location where the content of the NFT is stored. One option is create an IPFS account and store the NFToken content at a persistent URL. See [Best Practices for Storing NFT Data](https://docs.ipfs.io/how-to/best-practices-for-nft-data).
If you, as the issuer, want to be able to burn the token in the future, set the `Flags` field to _1._ To make the NFT transferable, set the `Flags` field to _8_. Set the `Flags` field to _9_ to make the NFT both burnable and transferable. See [Burnable flag](nftoken.html#nftoken-flags) and [Transferable flag](nftoken.html#nftoken-flags). If you, as the issuer, want to be able to burn the token in the future, set the `Flags` field to _1._ To make the NFT transferable, set the `Flags` field to _8_. Set the `Flags` field to _9_ to make the NFT both burnable and transferable. See [Burnable flag](nftoken.html) and [Transferable flag](nftoken.html).
You can collect royalties from future sales by setting a <code>transfer fee<em>. </em></code>This is a value from 0-50000 representing 0-50% of the sale price. See [Transfer Fee](nftoken.html#transferfee). You can collect royalties from future sales by setting a <code>transfer fee<em>. </em></code>This is a value from 0-50000 representing 0-50% of the sale price. See [Transfer Fee](nftoken.html#transferfee).

View File

@@ -1580,6 +1580,16 @@ pages:
- en - en
- ja - ja
- name: NFTs Using Python
html: nfts-using-python.html
parent: modular-tutorials-in-python.html
top_nav_grouping: Article Types
template: pagetype-category.html.jinja
blurb: Mint and sell NFTs on the XRP Ledger using Python.
targets:
- en
- ja
# TODO: translate # TODO: translate
- md: tutorials/quickstart/py-mint-and-burn-nfts.md - md: tutorials/quickstart/py-mint-and-burn-nfts.md
targets: targets:
@@ -1715,7 +1725,7 @@ pages:
parent: modular-tutorials-in-javascript.html parent: modular-tutorials-in-javascript.html
top_nav_grouping: Article Types top_nav_grouping: Article Types
template: pagetype-category.html.jinja template: pagetype-category.html.jinja
blurb: Mint and sell NFTs on the XRP Ledger. blurb: Mint and sell NFTs on the XRP Ledger using JavaScript.
targets: targets:
- en - en

BIN
img/quickstart-py36.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 KiB