diff --git a/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts b/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts index ade5231015..da3808d5b7 100644 --- a/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts +++ b/bindings/nodejs/examples/how_tos/nft_collection/01_mint_collection_nft.ts @@ -67,7 +67,11 @@ async function run() { i + NUM_NFTS_MINTED_PER_TRANSACTION, ); - console.log(`Minting ${chunk.length} NFTs...`); + console.log( + `Minting ${chunk.length} NFTs... (${ + i + chunk.length + }/${NFT_COLLECTION_SIZE})`, + ); const prepared = await account.prepareMintNfts(chunk); const transaction = await prepared.send(); diff --git a/bindings/python/examples/how_tos/advanced_transactions/advanced_transaction.py b/bindings/python/examples/how_tos/advanced_transactions/advanced_transaction.py index 70af82fa86..3f94860477 100644 --- a/bindings/python/examples/how_tos/advanced_transactions/advanced_transaction.py +++ b/bindings/python/examples/how_tos/advanced_transactions/advanced_transaction.py @@ -33,9 +33,9 @@ ) transaction = account.send_outputs([basic_output]) -print(f'Transaction sent: {transaction["transactionId"]}') +print(f'Transaction sent: {transaction.transactionId}') -block_id = account.retry_transaction_until_included(transaction["transactionId"]) +block_id = account.retry_transaction_until_included(transaction.transactionId) print( f'Block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') diff --git a/bindings/python/examples/how_tos/advanced_transactions/send_micro_transaction.py b/bindings/python/examples/how_tos/advanced_transactions/send_micro_transaction.py index 1595071bee..5a10b60890 100644 --- a/bindings/python/examples/how_tos/advanced_transactions/send_micro_transaction.py +++ b/bindings/python/examples/how_tos/advanced_transactions/send_micro_transaction.py @@ -24,9 +24,9 @@ }] transaction = account.send(params, {"allowMicroAmount": True}) -print(f'Transaction sent: {transaction["transactionId"]}') +print(f'Transaction sent: {transaction.transactionId}') -block_id = account.retry_transaction_until_included(transaction["transactionId"]) +block_id = account.retry_transaction_until_included(transaction.transactionId) print( f'Block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') diff --git a/bindings/python/examples/how_tos/native_tokens/burn.py b/bindings/python/examples/how_tos/native_tokens/burn.py index 686947c952..2480d72206 100644 --- a/bindings/python/examples/how_tos/native_tokens/burn.py +++ b/bindings/python/examples/how_tos/native_tokens/burn.py @@ -26,7 +26,7 @@ # Send transaction. transaction = account.prepare_burn_native_token(token["tokenId"], burn_amount).send() -print(f'Transaction sent: {transaction["transactionId"]}') +print(f'Transaction sent: {transaction.transactionId}') # Wait for transaction to get included blockId = account.retry_transaction_until_included(transaction['transactionId']) diff --git a/bindings/python/examples/how_tos/native_tokens/create.py b/bindings/python/examples/how_tos/native_tokens/create.py index 17126f7f83..960f708888 100644 --- a/bindings/python/examples/how_tos/native_tokens/create.py +++ b/bindings/python/examples/how_tos/native_tokens/create.py @@ -22,7 +22,7 @@ if not balance["aliases"]: # If we don't have an alias, we need to create one transaction = account.prepare_create_alias_output(None, None).send() - print(f'Transaction sent: {transaction["transactionId"]}') + print(f'Transaction sent: {transaction.transactionId}') # Wait for transaction to get included blockId = account.retry_transaction_until_included(transaction.transactionId) diff --git a/bindings/python/examples/how_tos/native_tokens/destroy_foundry.py b/bindings/python/examples/how_tos/native_tokens/destroy_foundry.py index 5ddfb0a645..bcd3450692 100644 --- a/bindings/python/examples/how_tos/native_tokens/destroy_foundry.py +++ b/bindings/python/examples/how_tos/native_tokens/destroy_foundry.py @@ -24,7 +24,7 @@ # Send transaction. transaction = account.prepare_destroy_foundry(foundry_id).send() -print(f'Transaction sent: {transaction["transactionId"]}') +print(f'Transaction sent: {transaction.transactionId}') # Wait for transaction to get included blockId = account.retry_transaction_until_included(transaction.transactionId) diff --git a/bindings/python/examples/how_tos/native_tokens/melt.py b/bindings/python/examples/how_tos/native_tokens/melt.py index 3092089b8f..fccde3120d 100644 --- a/bindings/python/examples/how_tos/native_tokens/melt.py +++ b/bindings/python/examples/how_tos/native_tokens/melt.py @@ -28,7 +28,7 @@ # Send transaction. transaction = account.prepare_melt_native_token(token_id, melt_amount).send() -print(f'Transaction sent: {transaction["transactionId"]}') +print(f'Transaction sent: {transaction.transactionId}') # Wait for transaction to get included blockId = account.retry_transaction_until_included(transaction['transactionId']) diff --git a/bindings/python/examples/how_tos/native_tokens/mint.py b/bindings/python/examples/how_tos/native_tokens/mint.py index a0521b47d6..9f5e6e225b 100644 --- a/bindings/python/examples/how_tos/native_tokens/mint.py +++ b/bindings/python/examples/how_tos/native_tokens/mint.py @@ -28,7 +28,7 @@ # Prepare and send transaction. transaction = account.prepare_mint_native_token(token_id, mint_amount).send() -print(f'Transaction sent: {transaction["transactionId"]}') +print(f'Transaction sent: {transaction.transactionId}') # Wait for transaction to get included blockId = account.retry_transaction_until_included(transaction['transactionId']) diff --git a/bindings/python/examples/how_tos/native_tokens/send.py b/bindings/python/examples/how_tos/native_tokens/send.py index 0e9ba38069..d355d1dc19 100644 --- a/bindings/python/examples/how_tos/native_tokens/send.py +++ b/bindings/python/examples/how_tos/native_tokens/send.py @@ -30,7 +30,7 @@ }] transaction = account.prepare_send_native_tokens(outputs, None).send() -print(f'Transaction sent: {transaction["transactionId"]}') +print(f'Transaction sent: {transaction.transactionId}') # Wait for transaction to get included blockId = account.retry_transaction_until_included(transaction['transactionId']) diff --git a/bindings/python/examples/how_tos/nft_collection/00_mint_issuer_nft.py b/bindings/python/examples/how_tos/nft_collection/00_mint_issuer_nft.py new file mode 100644 index 0000000000..20b8612a98 --- /dev/null +++ b/bindings/python/examples/how_tos/nft_collection/00_mint_issuer_nft.py @@ -0,0 +1,43 @@ +from iota_sdk import Wallet, Utils, utf8_to_hex +from dotenv import load_dotenv +import os + +load_dotenv() + +# In this example we will mint the issuer NFT for the NFT collection. + +wallet = Wallet(os.environ['WALLET_DB_PATH']) + +if 'STRONGHOLD_PASSWORD' not in os.environ: + raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") + +wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) + +account = wallet.get_account('Alice') + +# Sync account with the node +account.sync() + +# Issue the minting transaction and wait for its inclusion +print('Sending NFT minting transaction...') +params = { + "immutableMetadata": utf8_to_hex("This NFT will be the issuer from the awesome NFT collection"), +} + +prepared = account.prepare_mint_nfts([params]) +transaction = prepared.send() + +# Wait for transaction to get included +block_id = account.retry_transaction_until_included(transaction.transactionId) + +print( + f'Block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') + +essence = transaction.payload["essence"] + +for outputIndex, output in enumerate(essence["outputs"]): + # New minted NFT id is empty in the output + if output["type"] == 6 and output["nftId"] == '0x0000000000000000000000000000000000000000000000000000000000000000': + outputId = Utils.compute_output_id(transaction.transactionId, outputIndex) + nftId = Utils.compute_nft_id(outputId) + print(f'New minted NFT id: {nftId}') diff --git a/bindings/python/examples/how_tos/nft_collection/01_mint_collection_nft.py b/bindings/python/examples/how_tos/nft_collection/01_mint_collection_nft.py new file mode 100644 index 0000000000..3e46bb9269 --- /dev/null +++ b/bindings/python/examples/how_tos/nft_collection/01_mint_collection_nft.py @@ -0,0 +1,69 @@ +from iota_sdk import Wallet, Utils, utf8_to_hex +from dotenv import load_dotenv +import os +import sys +import json + +load_dotenv() + +# The NFT collection size +NFT_COLLECTION_SIZE = 150 +# Mint NFTs in chunks since the transaction size is limited +NUM_NFTS_MINTED_PER_TRANSACTION = 50 + +# In this example we will mint some collection NFTs with issuer feature. + +if len(sys.argv) < 2: + raise Exception("missing example argument: ISSUER_NFT_ID") + +issuer_nft_id = sys.argv[1] + +wallet = Wallet(os.environ['WALLET_DB_PATH']) + +if 'STRONGHOLD_PASSWORD' not in os.environ: + raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example") + +wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"]) + +account = wallet.get_account('Alice') + +# Sync account with the node +account.sync() + +bech32_hrp = wallet.get_client().get_bech32_hrp() +issuer = Utils.nft_id_to_bech32(issuer_nft_id, bech32_hrp) + +def get_immutable_metadata(index: int, issuer_nft_id: str) -> str: + data = { + "standard": "IRC27", + "version": "v1.0", + "type": "video/mp4", + "uri": "ipfs://wrongcVm9fx47YXNTkhpMEYSxCD3Bqh7PJYr7eo5Ywrong", + "name": "Shimmer OG NFT #" + str(index), + "description": "The Shimmer OG NFT was handed out 1337 times by the IOTA Foundation to celebrate the official launch of the Shimmer Network.", + "issuerName": "IOTA Foundation", + "collectionId": issuer_nft_id, + "collectionName": "Shimmer OG" + } + return json.dumps(data, separators=(',', ':')) + +# Create the metadata with another index for each +nft_mint_params = list(map(lambda index: { + "immutableMetadata": utf8_to_hex(get_immutable_metadata(index, issuer_nft_id)), + "issuer": issuer +}, range(NFT_COLLECTION_SIZE))) + +while nft_mint_params: + chunk, nft_mint_params = nft_mint_params[:NUM_NFTS_MINTED_PER_TRANSACTION], nft_mint_params[NUM_NFTS_MINTED_PER_TRANSACTION:] + print(f'Minting {len(chunk)} NFTs... ({NFT_COLLECTION_SIZE-len(nft_mint_params)}/{NFT_COLLECTION_SIZE})') + prepared = account.prepare_mint_nfts(chunk) + transaction = prepared.send() + + # Wait for transaction to get included + block_id = account.retry_transaction_until_included(transaction.transactionId) + + print( + f'Block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') + + # Sync so the new outputs are available again for new transactions + account.sync() \ No newline at end of file diff --git a/bindings/python/examples/how_tos/simple_transaction/simple_transaction.py b/bindings/python/examples/how_tos/simple_transaction/simple_transaction.py index dc5891dcdc..997e5eae81 100644 --- a/bindings/python/examples/how_tos/simple_transaction/simple_transaction.py +++ b/bindings/python/examples/how_tos/simple_transaction/simple_transaction.py @@ -23,5 +23,5 @@ "amount": "1000000", }] -transaction = account.send(outputs) +transaction = account.send(params) print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}') diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index 4847b612e3..08377de024 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -120,7 +120,8 @@ def compute_storage_deposit(output, rent) -> HexStr: """Computes the required storage deposit of an output. """ return _call_method('computeStorageDeposit', { - 'inputs': inputs + 'output': output, + 'rent': rent }) @staticmethod @@ -128,7 +129,7 @@ def compute_nft_id(output_id: OutputId) -> HexStr: """Computes the NFT id for the given NFT output id. """ return _call_method('computeNftId', { - 'outputId': output_id + 'outputId': repr(output_id) }) @staticmethod @@ -136,7 +137,7 @@ def compute_output_id(transaction_id: HexStr, index: int) -> OutputId: """Computes the output id from transaction id and output index. """ return OutputId.from_string(_call_method('computeOutputId', { - 'transactionId': transaction_id, + 'id': transaction_id, 'index': index, })) diff --git a/sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs b/sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs index dbcda7295d..42c291a804 100644 --- a/sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs +++ b/sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs @@ -66,8 +66,13 @@ async fn main() -> Result<()> { }) .collect::>(); - for nft_mint_params in nft_mint_params.chunks(NUM_NFTS_MINTED_PER_TRANSACTION) { - println!("Minting {} NFTs...", nft_mint_params.len()); + for (index, nft_mint_params) in nft_mint_params.chunks(NUM_NFTS_MINTED_PER_TRANSACTION).enumerate() { + println!( + "Minting {} NFTs... ({}/{})", + nft_mint_params.len(), + index * NUM_NFTS_MINTED_PER_TRANSACTION + nft_mint_params.len(), + NFT_COLLECTION_SIZE + ); let transaction = account.mint_nfts(nft_mint_params.to_vec(), None).await?; wait_for_inclusion(&transaction.transaction_id, &account).await?;