mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 11:45:50 +00:00
Resubmit Python2 updates
This commit is contained in:
@@ -1,22 +1,19 @@
|
||||
import xrpl
|
||||
import json
|
||||
import xrpl.clients
|
||||
import xrpl.wallet
|
||||
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234/"
|
||||
|
||||
def get_account(seed):
|
||||
"""get_account"""
|
||||
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
|
||||
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
|
||||
client = xrpl.clients.JsonRpcClient(testnet_url)
|
||||
if (seed == ''):
|
||||
new_wallet = xrpl.wallet.generate_faucet_wallet(client)
|
||||
else:
|
||||
new_wallet = xrpl.wallet.Wallet(seed, sequence = 79396029)
|
||||
return(new_wallet)
|
||||
new_wallet = xrpl.wallet.Wallet.from_seed(seed)
|
||||
return new_wallet
|
||||
|
||||
def get_account_info(accountId):
|
||||
"""get_account_info"""
|
||||
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234'
|
||||
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
|
||||
client = xrpl.clients.JsonRpcClient(testnet_url)
|
||||
acct_info = xrpl.models.requests.account_info.AccountInfo(
|
||||
account=accountId,
|
||||
ledger_index="validated"
|
||||
@@ -25,20 +22,15 @@ def get_account_info(accountId):
|
||||
return response.result['account_data']
|
||||
|
||||
def send_xrp(seed, amount, destination):
|
||||
sending_wallet = xrpl.wallet.Wallet(seed, sequence = 16237283)
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
sending_wallet = xrpl.wallet.Wallet.from_seed(seed)
|
||||
client = xrpl.clients.JsonRpcClient(testnet_url)
|
||||
payment = xrpl.models.transactions.Payment(
|
||||
account=sending_wallet.classic_address,
|
||||
account=sending_wallet.address,
|
||||
amount=xrpl.utils.xrp_to_drops(int(amount)),
|
||||
destination=destination,
|
||||
)
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
payment, sending_wallet, client)
|
||||
try:
|
||||
tx_response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response = tx_response
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
try:
|
||||
response = xrpl.transaction.submit_and_wait(payment, client, sending_wallet)
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
return response
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
from xrpl.models.requests.account_info import AccountInfo
|
||||
|
||||
|
||||
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):
|
||||
"""create_trust_line"""
|
||||
# Get the client
|
||||
receiving_wallet = Wallet(seed, sequence = 16237283)
|
||||
receiving_wallet = Wallet.from_seed(seed)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
# Define the trust line transaction
|
||||
trustline_tx=xrpl.models.transactions.TrustSet(
|
||||
account=receiving_wallet.classic_address,
|
||||
account=receiving_wallet.address,
|
||||
limit_amount=xrpl.models.amounts.IssuedCurrencyAmount(
|
||||
currency=currency,
|
||||
issuer=issuer,
|
||||
value=int(amount)
|
||||
)
|
||||
)
|
||||
# Sign and fill the transaction
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
trustline_tx, receiving_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
|
||||
|
||||
response = xrpl.transaction.submit_and_wait(trustline_tx,
|
||||
client, receiving_wallet)
|
||||
return response.result
|
||||
|
||||
#################
|
||||
# send_currency #
|
||||
@@ -44,29 +35,20 @@ def create_trust_line(seed, issuer, currency, amount):
|
||||
def send_currency(seed, destination, currency, amount):
|
||||
"""send_currency"""
|
||||
# Get the client
|
||||
sending_wallet=Wallet(seed, sequence=16237283)
|
||||
sending_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
# Define the payment transaction.
|
||||
send_currency_tx=xrpl.models.transactions.Payment(
|
||||
account=sending_wallet.classic_address,
|
||||
account=sending_wallet.address,
|
||||
amount=xrpl.models.amounts.IssuedCurrencyAmount(
|
||||
currency=currency,
|
||||
value=int(amount),
|
||||
issuer=sending_wallet.classic_address
|
||||
issuer=sending_wallet.address
|
||||
),
|
||||
destination=destination
|
||||
)
|
||||
# Sign and fill the transaction
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
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
|
||||
response=xrpl.transaction.submit_and_wait(send_currency_tx, client, sending_wallet)
|
||||
return response.result
|
||||
|
||||
###############
|
||||
# get_balance #
|
||||
@@ -74,8 +56,7 @@ def send_currency(seed, destination, currency, amount):
|
||||
|
||||
def get_balance(sb_account_id, op_account_id):
|
||||
"""get_balance"""
|
||||
JSON_RPC_URL='wss://s.altnet.rippletest.net:51234'
|
||||
client=JsonRpcClient(JSON_RPC_URL)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
balance=xrpl.models.requests.GatewayBalances(
|
||||
account=sb_account_id,
|
||||
ledger_index="validated",
|
||||
@@ -91,29 +72,18 @@ def get_balance(sb_account_id, op_account_id):
|
||||
def configure_account(seed, default_setting):
|
||||
"""configure_account"""
|
||||
# Get the client
|
||||
wallet=Wallet(seed, sequence = 16237283)
|
||||
wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
# Create transaction
|
||||
if (default_setting):
|
||||
setting_tx=xrpl.models.transactions.AccountSet(
|
||||
account=wallet.classic_address,
|
||||
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
|
||||
set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
|
||||
)
|
||||
else:
|
||||
setting_tx=xrpl.models.transactions.AccountSet(
|
||||
account=wallet.classic_address,
|
||||
clear_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
|
||||
clear_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
|
||||
)
|
||||
|
||||
# Sign and fill the transaction
|
||||
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
|
||||
|
||||
response=xrpl.transaction.submit_and_wait(setting_tx,client,wallet)
|
||||
return response.result
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
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):
|
||||
"""mint_token"""
|
||||
# Get the client
|
||||
mint_wallet=Wallet(seed, sequence=16237283)
|
||||
minter_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
# Define the mint transaction
|
||||
mint_tx=xrpl.models.transactions.NFTokenMint(
|
||||
account=mint_wallet.classic_address,
|
||||
account=minter_wallet.address,
|
||||
uri=xrpl.utils.str_to_hex(uri),
|
||||
flags=int(flags),
|
||||
transfer_fee=int(transfer_fee),
|
||||
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
|
||||
reply=""
|
||||
try:
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response=xrpl.transaction.submit_and_wait(mint_tx,client,minter_wallet)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
@@ -45,19 +41,16 @@ def get_tokens(account):
|
||||
def burn_token(seed, nftoken_id):
|
||||
"""burn_token"""
|
||||
# Get the client
|
||||
owner_wallet=Wallet(seed, sequence=16237283)
|
||||
owner_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
burn_tx=xrpl.models.transactions.NFTokenBurn(
|
||||
account=owner_wallet.classic_address,
|
||||
account=owner_wallet.address,
|
||||
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
|
||||
reply=""
|
||||
try:
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response=xrpl.transaction.submit_and_wait(burn_tx,client,owner_wallet)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
|
||||
@@ -12,7 +12,7 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
|
||||
"""create_sell_offer"""
|
||||
# Get the client
|
||||
owner_wallet = Wallet(seed, sequence=16237283)
|
||||
owner_wallet = Wallet.from_seed(seed)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
expiration_date = datetime.now()
|
||||
if expiration != '':
|
||||
@@ -20,41 +20,34 @@ def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
|
||||
expiration_date = expiration_date + int(expiration)
|
||||
# Define the sell offer
|
||||
sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account=owner_wallet.classic_address,
|
||||
account=owner_wallet.address,
|
||||
nftoken_id=nftoken_id,
|
||||
amount=amount,
|
||||
destination=destination if destination != '' else None,
|
||||
expiration=expiration_date if expiration != '' else None,
|
||||
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
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
|
||||
def accept_sell_offer(seed, offer_index):
|
||||
"""accept_sell_offer"""
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
buyer_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
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
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as 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):
|
||||
"""create_buy_offer"""
|
||||
# Get the client
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
buyer_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
expiration_date=datetime.now()
|
||||
if (expiration!=''):
|
||||
@@ -72,7 +65,7 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
|
||||
expiration_date=expiration_date + int(expiration)
|
||||
# Define the buy offer transaction with an expiration date
|
||||
buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
account=buyer_wallet.address,
|
||||
nftoken_id=nft_id,
|
||||
amount=amount,
|
||||
owner=owner,
|
||||
@@ -80,13 +73,10 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
|
||||
destination=destination if destination!='' else None,
|
||||
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
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as 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):
|
||||
"""accept_buy_offer"""
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
buyer_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
account=buyer_wallet.address,
|
||||
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
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
@@ -130,19 +117,17 @@ def get_offers(nft_id):
|
||||
|
||||
def cancel_offer(seed, nftoken_offer_ids):
|
||||
"""cancel_offer"""
|
||||
owner_wallet=Wallet(seed, sequence=16237283)
|
||||
owner_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
tokenOfferIDs=[nftoken_offer_ids]
|
||||
nftSellOffers="No sell offers"
|
||||
cancel_offer_tx=xrpl.models.transactions.NFTokenCancelOffer(
|
||||
account=owner_wallet.classic_address,
|
||||
nftoken_offers=tokenOfferIDs
|
||||
)
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
cancel_offer_tx, owner_wallet, client)
|
||||
)
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
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):
|
||||
"""broker_sale"""
|
||||
broker_wallet=Wallet(seed, sequence=16237283)
|
||||
broker_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
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_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
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
|
||||
@@ -1,47 +1,46 @@
|
||||
import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
testnet_url="https://s.altnet.rippletest.net:51234"
|
||||
|
||||
def set_minter(seed, minter):
|
||||
"""set_minter"""
|
||||
granter_wallet=Wallet(seed, sequence = 16237283)
|
||||
granter_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
|
||||
set_minter_tx=xrpl.models.transactions.AccountSet(
|
||||
account=granter_wallet.classic_address,
|
||||
account=granter_wallet.address,
|
||||
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
|
||||
reply=""
|
||||
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:
|
||||
response=f"Submit failed: {e}"
|
||||
return response.result
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
def mint_other(seed, uri, flags, transfer_fee, taxon, issuer):
|
||||
"""mint_other"""
|
||||
minter_wallet=Wallet(seed, sequence=16237283)
|
||||
minter_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
mint_other_tx=xrpl.models.transactions.NFTokenMint(
|
||||
account=minter_wallet.classic_address,
|
||||
account=minter_wallet.address,
|
||||
uri=xrpl.utils.str_to_hex(uri),
|
||||
flags=int(flags),
|
||||
transfer_fee=int(transfer_fee),
|
||||
nftoken_taxon=int(taxon),
|
||||
issuer=issuer
|
||||
)
|
||||
# Sign and fill the transaction
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
mint_other_tx, minter_wallet, client)
|
||||
# Submit the transaction and report the results
|
||||
reply=""
|
||||
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:
|
||||
response=f"Submit failed: {e}"
|
||||
return response.result
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
80
content/_code-samples/quickstart/py/mod7.py
Normal file
80
content/_code-samples/quickstart/py/mod7.py
Normal 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
|
||||
@@ -5,14 +5,14 @@ blurb: Broker a sale between a sell offer and a buy offer.
|
||||
labels:
|
||||
- Accounts
|
||||
- Quickstart
|
||||
- Broker
|
||||
- NFTs
|
||||
- XRP
|
||||
---
|
||||
# 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.
|
||||
|
||||
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.
|
||||
|
||||
[](img/quickstart33-batch-mint.png)
|
||||
|
||||
@@ -105,7 +105,7 @@ Disconnect from the XRP Ledger.
|
||||
|
||||
## 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
|
||||
// *******************************************************
|
||||
|
||||
@@ -103,7 +103,7 @@ The Buyer account was debited the 100 XRP price plus 10 drops as the transaction
|
||||
|
||||
# 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
|
||||
|
||||
@@ -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.
|
||||
|
||||
```python
|
||||
import xrpl
|
||||
import json
|
||||
import xrpl
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
testnet_url="https://s.altnet.rippletest.net:51234"
|
||||
```
|
||||
|
||||
### Set Minter
|
||||
@@ -128,7 +127,7 @@ Get the wallet of the account granting permission and instantiate a client.
|
||||
```python
|
||||
def set_minter(seed, minter):
|
||||
"""set_minter"""
|
||||
granter_wallet=Wallet(seed, sequence = 16237283)
|
||||
granter_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -136,17 +135,10 @@ Define the AccountSet transaction that grants permission to another account to m
|
||||
|
||||
```python
|
||||
set_minter_tx=xrpl.models.transactions.AccountSet(
|
||||
account=granter_wallet.classic_address,
|
||||
account=granter_wallet.address,
|
||||
nftoken_minter=minter,
|
||||
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_AUTHORIZED_NFTOKEN_MINTER
|
||||
)
|
||||
```
|
||||
|
||||
Sign the transaction
|
||||
|
||||
```python
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
set_minter_tx, granter_wallet, client)
|
||||
set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_AUTHORIZED_NFTOKEN_MINTER
|
||||
)
|
||||
```
|
||||
|
||||
Submit the transaction and return the results.
|
||||
@@ -154,7 +146,8 @@ Submit the transaction and return the results.
|
||||
```python
|
||||
reply=""
|
||||
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:
|
||||
reply=f"Submit failed: {e}"
|
||||
@@ -168,7 +161,7 @@ Get the minter wallet and instantiate a client connection to the XRP ledger.
|
||||
``` python
|
||||
def mint_other(seed, uri, flags, transfer_fee, taxon, issuer):
|
||||
"""mint_other"""
|
||||
minter_wallet=Wallet(seed, sequence=16237283)
|
||||
minter_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -176,7 +169,7 @@ Define the `NFTokenMint` transaction. The new parameter in this method is the _i
|
||||
|
||||
```python
|
||||
mint_other_tx=xrpl.models.transactions.NFTokenMint(
|
||||
account=minter_wallet.classic_address,
|
||||
account=minter_wallet.address,
|
||||
uri=xrpl.utils.str_to_hex(uri),
|
||||
flags=int(flags),
|
||||
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.
|
||||
|
||||
```python
|
||||
reply=""
|
||||
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:
|
||||
reply=f"Submit failed: {e}"
|
||||
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()
|
||||
```
|
||||
|
||||
405
content/tutorials/quickstart/py-batch-minting.md
Normal file
405
content/tutorials/quickstart/py-batch-minting.md
Normal 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.
|
||||
|
||||
[](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()
|
||||
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
html: py-broker-sale.html
|
||||
parent: send-payments-using-python.html
|
||||
parent: quickstart-python.html
|
||||
blurb: Broker a sale between a sell offer and a buy offer.
|
||||
labels:
|
||||
- Accounts
|
||||
@@ -9,7 +9,7 @@ labels:
|
||||
- XRP
|
||||
---
|
||||
|
||||
# Broker an NFT Sale Using Python
|
||||
# Broker an NFT Sale (Python)
|
||||
|
||||
Earlier examples showed how to make buy and sell offers directly between two accounts. Another option is to use a third account as a broker for the sale. The broker acts on behalf of the NFT owner. The seller creates an offer with the broker account as its destination. The broker gathers and evaluates buy offers and chooses which one to accept, adding an agreed-upon fee for arranging the sale. When the broker account accepts a sell offer with a buy offer, the funds and ownership of the NFT are transferred simultaneously, completing the deal. This allows an account to act as a marketplace or personal agent for NFT creators and traders.
|
||||
|
||||
@@ -23,7 +23,7 @@ This example shows how to:
|
||||
|
||||
[](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
|
||||
|
||||
@@ -96,7 +96,7 @@ After accepting a buy offer, a best practice for the broker is to cancel all oth
|
||||
|
||||
# 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
|
||||
<!-- SPELLING_IGNORE: ripplex5 -->
|
||||
@@ -107,7 +107,6 @@ Import dependencies and create a global variable for `testnet_url`.
|
||||
|
||||
```python
|
||||
import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
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.
|
||||
|
||||
```python
|
||||
broker_wallet=Wallet(seed, sequence=16237283)
|
||||
broker_wallet=Wallet.from_seed(seed)
|
||||
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.
|
||||
|
||||
```python
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
```
|
||||
|
||||
## lesson5-broker-nfts.py
|
||||
@@ -882,4 +875,4 @@ btn_op_cancel_offer.grid(row=16, column=3, sticky="nsew")
|
||||
|
||||
# Start the application
|
||||
window.mainloop()
|
||||
```
|
||||
```x
|
||||
@@ -1,14 +1,14 @@
|
||||
---
|
||||
html: py-create-accounts-send-xrp.html
|
||||
parent: send-payments-using-python.html
|
||||
blurb: Create two accounts and transfer XRP between them using Python.
|
||||
parent: quickstart-python.html
|
||||
blurb: Quickstart 1, create two accounts and transfer XRP between them.
|
||||
labels:
|
||||
- Accounts
|
||||
- Quickstart
|
||||
- Transaction Sending
|
||||
- XRP
|
||||
---
|
||||
# Create Accounts and Send XRP Using Python
|
||||
# 1. Create Accounts and Send XRP (Python)
|
||||
|
||||
This example shows how to:
|
||||
|
||||
@@ -63,20 +63,24 @@ To transfer XRP from the Operational account to the Standby account:
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
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
|
||||
@@ -90,16 +94,10 @@ def get_account(seed):
|
||||
"""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.
|
||||
|
||||
```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.
|
||||
@@ -108,8 +106,8 @@ If you do not enter a seed, generate and return a new wallet. If you provide a s
|
||||
if (seed == ''):
|
||||
new_wallet = xrpl.wallet.generate_faucet_wallet(client)
|
||||
else:
|
||||
new_wallet = xrpl.wallet.Wallet(seed, sequence = 79396029)
|
||||
return(new_wallet)
|
||||
new_wallet = xrpl.wallet.Wallet.from_seed(seed)
|
||||
return new_wallet
|
||||
```
|
||||
|
||||
### get_account_info
|
||||
@@ -124,8 +122,7 @@ def get_account_info(accountId):
|
||||
Get a client instance from Testnet.
|
||||
|
||||
```python
|
||||
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234'
|
||||
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
|
||||
client = xrpl.clients.JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```python
|
||||
sending_wallet = xrpl.wallet.Wallet(seed, sequence = 16237283)
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
sending_wallet = xrpl.wallet.Wallet.from_seed(seed)
|
||||
client = xrpl.clients.JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Create a transaction request, passing the sending account, amount, and destination account.
|
||||
|
||||
```python
|
||||
payment=xrpl.models.transactions.Payment(
|
||||
account=sending_wallet.classic_address,
|
||||
payment = xrpl.models.transactions.Payment(
|
||||
account=sending_wallet.address,
|
||||
amount=xrpl.utils.xrp_to_drops(int(amount)),
|
||||
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.
|
||||
|
||||
```python
|
||||
try:
|
||||
tx_response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response = tx_response
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
try:
|
||||
response = xrpl.transaction.submit_and_wait(payment, client, sending_wallet)
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
return response
|
||||
```
|
||||
@@ -429,4 +417,3 @@ Start the application.
|
||||
```python
|
||||
window.mainloop()
|
||||
```
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
---
|
||||
html: py-create-trustline-send-currency.html
|
||||
parent: send-payments-using-python.html
|
||||
blurb: Create trust lines and send currency.
|
||||
parent: quickstart-python.html
|
||||
blurb: Quickstart step 2, create trust lines and send currency.
|
||||
labels:
|
||||
- Cross-Currency
|
||||
- Payments
|
||||
- Quickstart
|
||||
- Tokens
|
||||
---
|
||||
# Create Trust Line and Send Currency Using Python
|
||||
# 2. Create Trust Line and Send Currency (Python)
|
||||
|
||||
This example shows how to:
|
||||
|
||||
@@ -20,7 +20,7 @@ This example shows how to:
|
||||
|
||||
[](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.
|
||||
|
||||
@@ -83,7 +83,7 @@ Verify the setting by looking for the _Clear Flag_ value in the response, which
|
||||
|
||||
# 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
|
||||
|
||||
@@ -93,10 +93,8 @@ Import dependencies and set the `testnet_url`.
|
||||
|
||||
```python
|
||||
import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
from xrpl.models.requests.account_info import AccountInfo
|
||||
|
||||
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.
|
||||
|
||||
```python
|
||||
receiving_wallet = Wallet(seed, sequence = 16237283)
|
||||
receiving_wallet = Wallet.from_seed(seed)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -121,7 +119,7 @@ Define the `TrustSet` transaction.
|
||||
|
||||
```python
|
||||
trustline_tx=xrpl.models.transactions.TrustSet(
|
||||
account=receiving_wallet.classic_address,
|
||||
account=receiving_wallet.address,
|
||||
limit_amount=xrpl.models.amounts.IssuedCurrencyAmount(
|
||||
currency=currency,
|
||||
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.
|
||||
|
||||
```python
|
||||
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}"
|
||||
response = xrpl.transaction.submit_and_wait(trustline_tx,
|
||||
client, receiving_wallet)
|
||||
```
|
||||
|
||||
Return the results.
|
||||
|
||||
```python
|
||||
return reply
|
||||
return response.result
|
||||
```
|
||||
## send_currency
|
||||
|
||||
@@ -165,7 +152,7 @@ def send_currency(seed, destination, currency, amount):
|
||||
Get the sending wallet and a client instance on Testnet.
|
||||
|
||||
```python
|
||||
sending_wallet=Wallet(seed, sequence=16237283)
|
||||
sending_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -173,38 +160,25 @@ Define the payment transaction. The amount requires further description to ident
|
||||
|
||||
```python
|
||||
send_currency_tx=xrpl.models.transactions.Payment(
|
||||
account=sending_wallet.classic_address,
|
||||
account=sending_wallet.address,
|
||||
amount=xrpl.models.amounts.IssuedCurrencyAmount(
|
||||
currency=currency,
|
||||
value=int(amount),
|
||||
issuer=sending_wallet.classic_address
|
||||
issuer=sending_wallet.address
|
||||
),
|
||||
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.
|
||||
|
||||
```python
|
||||
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}"
|
||||
```
|
||||
response=xrpl.transaction.submit_and_wait(send_currency_tx, client, sending_wallet)```
|
||||
|
||||
Return the JSON response, or an error message if the transaction fails.
|
||||
Return the results.
|
||||
|
||||
```python
|
||||
return reply
|
||||
return response.result
|
||||
```
|
||||
|
||||
### get_balance
|
||||
@@ -219,8 +193,7 @@ def get_balance(sb_account_id, op_account_id):
|
||||
Connect to the XRP Ledger and instantiate a client.
|
||||
|
||||
```python
|
||||
JSON_RPC_URL='wss://s.altnet.rippletest.net:51234'
|
||||
client=JsonRpcClient(JSON_RPC_URL)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Create the `GatewayBalances` request.
|
||||
@@ -253,7 +226,7 @@ def configure_account(seed, default_setting):
|
||||
Get the account wallet and instantiate a client.
|
||||
|
||||
```python
|
||||
wallet=Wallet(seed, sequence = 16237283)
|
||||
wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -263,37 +236,20 @@ If `default_setting` is true, create a `set_flag` transaction to enable ripplin
|
||||
if (default_setting):
|
||||
setting_tx=xrpl.models.transactions.AccountSet(
|
||||
account=wallet.classic_address,
|
||||
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
|
||||
set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
|
||||
)
|
||||
else:
|
||||
setting_tx=xrpl.models.transactions.AccountSet(
|
||||
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.
|
||||
|
||||
```python
|
||||
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 the results.
|
||||
|
||||
```python
|
||||
return reply
|
||||
response=xrpl.transaction.submit_and_wait(setting_tx,client,wallet)
|
||||
return response.result
|
||||
```
|
||||
|
||||
## lesson2-send-currency.py
|
||||
@@ -615,4 +571,4 @@ btn_op_configure_account.grid(row=7,column=4, sticky = "nsew")
|
||||
|
||||
```python
|
||||
window.mainloop()
|
||||
```
|
||||
```
|
||||
@@ -1,14 +1,14 @@
|
||||
---
|
||||
html: py-mint-and-burn-nfts.html
|
||||
parent: send-payments-using-python.html
|
||||
blurb: Mint and burn NFTs.
|
||||
parent: quickstart-python.html
|
||||
blurb: Quickstart step 3, mint and burn NFTs.
|
||||
labels:
|
||||
- Quickstart
|
||||
- Tokens
|
||||
- Non-fungible tokens, NFTs
|
||||
---
|
||||
|
||||
# Mint and Burn NFTs Using Python
|
||||
# 3. Mint and Burn NFTs (Python)
|
||||
|
||||
This example shows how to:
|
||||
|
||||
@@ -20,7 +20,7 @@ This example shows how to:
|
||||
|
||||
# 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
|
||||
|
||||
@@ -71,7 +71,7 @@ To permanently destroy an NFT:
|
||||
|
||||
# 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
|
||||
|
||||
@@ -81,12 +81,10 @@ Import dependencies and set global variable.
|
||||
|
||||
```python
|
||||
import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
from xrpl.models.requests import AccountNFTs
|
||||
|
||||
|
||||
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
|
||||
def mint_token(seed, uri, flags, transfer_fee, taxon):
|
||||
"""mint_token"""
|
||||
```
|
||||
|
||||
Get the account wallet and a client instance.
|
||||
|
||||
```python
|
||||
mint_wallet=Wallet(seed, sequence=16237283)
|
||||
minter_wallet=Wallet.from_seed(seed)
|
||||
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
|
||||
mint_tx=xrpl.models.transactions.NFTokenMint(
|
||||
account=mint_wallet.classic_address,
|
||||
account=minter_wallet.address,
|
||||
uri=xrpl.utils.str_to_hex(uri),
|
||||
flags=int(flags),
|
||||
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.
|
||||
|
||||
```python
|
||||
reply=""
|
||||
try:
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response=xrpl.transaction.submit_and_wait(mint_tx,client,minter_wallet)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
@@ -176,7 +168,7 @@ def burn_token(seed, nftoken_id):
|
||||
Get the owner wallet and client instance.
|
||||
|
||||
```python
|
||||
owner_wallet=Wallet(seed, sequence=16237283)
|
||||
owner_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -184,31 +176,23 @@ Define the NFTokenBurn transaction.
|
||||
|
||||
```python
|
||||
burn_tx=xrpl.models.transactions.NFTokenBurn(
|
||||
account=owner_wallet.classic_address,
|
||||
account=owner_wallet.address,
|
||||
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.
|
||||
|
||||
```python
|
||||
reply=""
|
||||
try:
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response=xrpl.transaction.submit_and_wait(burn_tx,client,owner_wallet)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
```
|
||||
|
||||
|
||||
## lesson3-mint-token.py
|
||||
<!-- SPELLING_IGNORE: lesson3 -->
|
||||
|
||||
@@ -646,4 +630,3 @@ btn_op_burn_token.grid(row=10, column=3, sticky="nsew")
|
||||
# Start the application
|
||||
window.mainloop()
|
||||
```
|
||||
|
||||
|
||||
57
content/tutorials/quickstart/py-quickstart-intro.md
Normal file
57
content/tutorials/quickstart/py-quickstart-intro.md
Normal 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.
|
||||
|
||||
[](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.
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
html: py-transfer-nfts.html
|
||||
parent: send-payments-using-python.html
|
||||
parent: quickstart-python.html
|
||||
blurb: Use a Python test harness to create and accept NFT buy and sell offers.
|
||||
labels:
|
||||
- Quickstart
|
||||
@@ -8,7 +8,7 @@ labels:
|
||||
- Non-fungible Tokens, NFTs
|
||||
---
|
||||
|
||||
# Transfer NFTs Using Python
|
||||
# 4. Transfer NFTs (Python)
|
||||
|
||||
This example shows how to:
|
||||
|
||||
@@ -21,7 +21,7 @@ This example shows how to:
|
||||
|
||||
[](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
|
||||
|
||||
@@ -120,7 +120,7 @@ To cancel a buy or sell offer that you have created:
|
||||
|
||||
# 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/python/){.github-code-download} archive to try each of the samples in your own browser.
|
||||
|
||||
## 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`.
|
||||
@@ -152,7 +152,7 @@ def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
|
||||
Get the owner wallet and create a client connection.
|
||||
|
||||
```python
|
||||
owner_wallet = Wallet(seed, sequence=16237283)
|
||||
owner_wallet = Wallet.from_seed(seed)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -169,7 +169,7 @@ Define the sell offer transaction.
|
||||
|
||||
```python
|
||||
sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account=owner_wallet.classic_address,
|
||||
account=owner_wallet.address,
|
||||
nftoken_id=nftoken_id,
|
||||
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.
|
||||
|
||||
```python
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
@@ -228,7 +221,7 @@ def accept_sell_offer(seed, offer_index):
|
||||
Get the wallet and a client instance.
|
||||
|
||||
```python
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
buyer_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -253,7 +246,7 @@ Submit the transaction and report the results.
|
||||
```python
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as 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.
|
||||
|
||||
```python
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
buyer_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -289,7 +282,7 @@ Define the buy offer transaction.
|
||||
|
||||
```python
|
||||
buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
account=buyer_wallet.address,
|
||||
nftoken_id=nft_id,
|
||||
amount=amount,
|
||||
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.
|
||||
|
||||
```python
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as 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.
|
||||
|
||||
```python
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
buyer_wallet=Wallet.from_seed(seed)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -353,24 +339,17 @@ Define the accept offer transaction.
|
||||
|
||||
```python
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
account=buyer_wallet.address,
|
||||
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
|
||||
|
||||
```python
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as 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.
|
||||
|
||||
```python
|
||||
reply=""
|
||||
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
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
@@ -1044,4 +1016,4 @@ btn_op_cancel_offer.grid(row=16, column=3, sticky="nsew")
|
||||
|
||||
# Start the application
|
||||
window.mainloop()
|
||||
```
|
||||
```
|
||||
Reference in New Issue
Block a user