diff --git a/.gitignore b/.gitignore
index 45407bd62b..d2aecc68a1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@ online_walletdb
/pingdb
/pongdb
backup
+example-walletdb
# JSON files
address.json
diff --git a/bindings/nodejs/examples/wallet/14-burn-nft.ts b/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts
similarity index 67%
rename from bindings/nodejs/examples/wallet/14-burn-nft.ts
rename to bindings/nodejs/examples/how_tos/nfts/burn_nft.ts
index c5663d09a7..0c6b0660e8 100644
--- a/bindings/nodejs/examples/wallet/14-burn-nft.ts
+++ b/bindings/nodejs/examples/how_tos/nfts/burn_nft.ts
@@ -1,7 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
-import { getUnlockedWallet } from './common';
+import { Wallet } from '@iota/sdk';
// In this example we will burn an existing nft output.
//
@@ -9,27 +9,39 @@ import { getUnlockedWallet } from './common';
// running the `how_tos/accounts-and-addresses/create-wallet` example!
//
// Rename `.env.example` to `.env` first, then run
-// yarn run-example ./wallet/14-burn-nft.ts
+// yarn run-example ./how_tos/nfts/burn_nft.ts
async function run() {
try {
+ if (!process.env.STRONGHOLD_PASSWORD) {
+ throw new Error(
+ '.env STRONGHOLD_PASSWORD is undefined, see .env.example',
+ );
+ }
+
// Create the wallet
- const wallet = await getUnlockedWallet();
+ const wallet = new Wallet({
+ storagePath: process.env.WALLET_DB_PATH,
+ });
// Get the account we generated with `01-create-wallet`
- const account = await wallet.getAccount('Alice');
+ const account = await wallet.getAccount(
+ `${process.env.ACCOUNT_ALIAS_1}`,
+ );
// May want to ensure the account is synced before sending a transaction.
let balance = await account.sync();
if (balance.nfts.length == 0) {
- throw new Error(`No NFT available in account 'Alice'`);
+ throw new Error(
+ `No NFT available in account '${process.env.ACCOUNT_ALIAS_1}'`,
+ );
}
// Get the first nft
const nftId = balance.nfts[0];
console.log(`Balance BEFORE burning:\n`, balance);
- // Burn a native token
+ // Burn an NFT
const transaction = await account
.prepareBurnNft(nftId)
.then((prepared) => prepared.send());
@@ -41,7 +53,7 @@ async function run() {
transaction.transactionId,
);
console.log(
- `Transaction included: ${process.env.EXPLORER_URL}/block/${blockId}`,
+ `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
console.log(`Burned NFT ${nftId}`);
diff --git a/bindings/nodejs/examples/wallet/10-mint-ntf.ts b/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts
similarity index 69%
rename from bindings/nodejs/examples/wallet/10-mint-ntf.ts
rename to bindings/nodejs/examples/how_tos/nfts/mint_nft.ts
index b1e0e9bf06..50e681da0f 100644
--- a/bindings/nodejs/examples/wallet/10-mint-ntf.ts
+++ b/bindings/nodejs/examples/how_tos/nfts/mint_nft.ts
@@ -9,10 +9,9 @@ import {
SenderFeature,
utf8ToHex,
Utils,
+ Wallet,
} from '@iota/sdk';
-import { getUnlockedWallet } from './common';
-
// The owner address of the first NFT we'll mint
const NFT1_OWNER_ADDRESS =
'rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu';
@@ -25,30 +24,32 @@ const NFT1_TAG = utf8ToHex('some NFT tag');
// The base coin amount we sent with the second NFT
const NFT2_AMOUNT = '1000000';
-// In this example we will mint an NFT in two different ways.
+// In this example we will mint a new nft.
//
// Make sure that `example.stronghold` and `example.walletdb` already exist by
// running the `how_tos/accounts-and-addresses/create-wallet` example!
//
// Rename `.env.example` to `.env` first, then run
-// yarn run-example ./wallet/10-mint-nft.ts
+// yarn run-example ./how_tos/nfts/mint_nft.ts
async function run() {
try {
- // Create the wallet
- const wallet = await getUnlockedWallet();
+ if (!process.env.STRONGHOLD_PASSWORD) {
+ throw new Error(
+ '.env STRONGHOLD_PASSWORD is undefined, see .env.example',
+ );
+ }
- // Get the account we generated with `01-create-wallet`
- const account = await wallet.getAccount('Alice');
+ const wallet = new Wallet({
+ storagePath: process.env.WALLET_DB_PATH,
+ });
- // May want to ensure the account is synced before sending a transaction.
- let balance = await account.sync();
- const nftsBefore = balance.nfts;
+ const account = await wallet.getAccount(
+ `${process.env.ACCOUNT_ALIAS_1}`,
+ );
// We send from the first address in the account.
const senderAddress = (await account.addresses())[0].address;
- console.log('Sending the minting transaction for NFT 1...');
-
const params: MintNftParams = {
address: NFT1_OWNER_ADDRESS, // Remove or change to senderAddress to send to self
sender: senderAddress,
@@ -68,7 +69,7 @@ async function run() {
);
console.log(
- `Transaction included: ${process.env.EXPLORER_URL}/block/${blockId}`,
+ `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
console.log('Minted NFT 1');
@@ -80,7 +81,9 @@ async function run() {
amount: NFT2_AMOUNT,
nftId: '0x0000000000000000000000000000000000000000000000000000000000000000',
unlockConditions: [
- new AddressUnlockCondition(new Ed25519Address(hexAddress)),
+ new AddressUnlockCondition(
+ new Ed25519Address(Utils.bech32ToHex(NFT1_OWNER_ADDRESS)),
+ ),
],
immutableFeatures: [
new IssuerFeature(new Ed25519Address(hexAddress)),
@@ -88,8 +91,6 @@ async function run() {
features: [new SenderFeature(new Ed25519Address(hexAddress))],
});
- console.log('Sending minting transaction for NFT 2...');
-
transaction = await account.sendOutputs([output]);
console.log(`Transaction sent: ${transaction.transactionId}`);
@@ -99,25 +100,16 @@ async function run() {
);
console.log(
- `Transaction included: ${process.env.EXPLORER_URL}/block/${blockId}`,
+ `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
console.log('Minted NFT 2');
// Ensure the account is synced after minting.
- balance = await account.sync();
- const nftsAfter = balance.nfts;
-
- console.log('New owned NFTs:', nftsBefore.length, nftsAfter.length);
- for (const nftId of nftsAfter) {
- if (!nftsBefore.includes(nftId)) {
- console.log(`- ${nftId}`);
- }
- }
+ await account.sync();
} catch (error) {
- console.log('Error: ', error);
+ console.error('Error: ', error);
}
- process.exit(0);
}
-run();
+run().then(() => process.exit());
diff --git a/bindings/nodejs/examples/wallet/08-send-nft.ts b/bindings/nodejs/examples/how_tos/nfts/send_nft.ts
similarity index 78%
rename from bindings/nodejs/examples/wallet/08-send-nft.ts
rename to bindings/nodejs/examples/how_tos/nfts/send_nft.ts
index 7adb72cc4d..2c8060f97b 100644
--- a/bindings/nodejs/examples/wallet/08-send-nft.ts
+++ b/bindings/nodejs/examples/how_tos/nfts/send_nft.ts
@@ -1,11 +1,9 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
-import { SendNftParams } from '@iota/sdk';
+import { SendNftParams, Wallet } from '@iota/sdk';
-import { getUnlockedWallet } from './common';
-
-// The address to send the tokens to
+// The address to send the NFT to
const RECV_ADDRESS =
'rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu';
@@ -15,14 +13,23 @@ const RECV_ADDRESS =
// running the `how_tos/accounts-and-addresses/create-wallet` example!
//
// Rename `.env.example` to `.env` first, then run
-// yarn run-example ./wallet/08-send-nft.ts
+// yarn run-example ./how_tos/nfts/send_nft.ts
async function run() {
try {
- // Create the wallet
- const wallet = await getUnlockedWallet();
+ if (!process.env.STRONGHOLD_PASSWORD) {
+ throw new Error(
+ '.env STRONGHOLD_PASSWORD is undefined, see .env.example',
+ );
+ }
+
+ const wallet = new Wallet({
+ storagePath: process.env.WALLET_DB_PATH,
+ });
// Get the account we generated with `01-create-wallet`
- const account = await wallet.getAccount('Alice');
+ const account = await wallet.getAccount(
+ `${process.env.ACCOUNT_ALIAS_1}`,
+ );
// May want to ensure the account is synced before sending a transaction.
const balance = await account.sync();
@@ -40,8 +47,6 @@ async function run() {
},
];
- console.log(`Sending NFT '${nftId}' to '${RECV_ADDRESS}'...`);
-
// Send the full NFT output to the specified address
const transaction = await account
.prepareSendNft(outputs)
@@ -55,7 +60,7 @@ async function run() {
);
console.log(
- `Transaction included: ${process.env.EXPLORER_URL}/block/${blockId}`,
+ `Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
// To send an NFT with expiration unlock condition prepareOutput() can be used like this:
diff --git a/bindings/python/examples/wallet/burn_nft.py b/bindings/python/examples/how_tos/nfts/burn_nft.py
similarity index 100%
rename from bindings/python/examples/wallet/burn_nft.py
rename to bindings/python/examples/how_tos/nfts/burn_nft.py
index 7a1aad57a2..cbf679ec43 100644
--- a/bindings/python/examples/wallet/burn_nft.py
+++ b/bindings/python/examples/how_tos/nfts/burn_nft.py
@@ -7,16 +7,16 @@
# In this example we will burn an NFT
wallet = Wallet('./alice-database')
-account = wallet.get_account('Alice')
-
-# Sync account with the node
-response = account.sync()
-
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
+response = account.sync()
+
# TODO: replace with your own values.
nftId = "0xf95f4d5344217a2ba19a6c19a47f97d267edf8c4d76a7b8c08072ad35acbebbe"
diff --git a/bindings/python/examples/wallet/8-mint-nft.py b/bindings/python/examples/how_tos/nfts/mint_nft.py
similarity index 99%
rename from bindings/python/examples/wallet/8-mint-nft.py
rename to bindings/python/examples/how_tos/nfts/mint_nft.py
index 5f733871b8..23bd819ff4 100644
--- a/bindings/python/examples/wallet/8-mint-nft.py
+++ b/bindings/python/examples/how_tos/nfts/mint_nft.py
@@ -8,20 +8,19 @@
wallet = Wallet('./alice-database')
-account = wallet.get_account('Alice')
-
-# Sync account with the node
-response = account.sync()
-
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
+response = account.sync()
+
outputs = [{
"immutableMetadata": utf8_to_hex("some immutable nft metadata"),
}]
transaction = account.prepare_mint_nfts(outputs).send()
-
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction["blockId"]}')
diff --git a/bindings/python/examples/wallet/6-send-nft.py b/bindings/python/examples/how_tos/nfts/send_nft.py
similarity index 99%
rename from bindings/python/examples/wallet/6-send-nft.py
rename to bindings/python/examples/how_tos/nfts/send_nft.py
index 32b4069d91..0d948900e3 100644
--- a/bindings/python/examples/wallet/6-send-nft.py
+++ b/bindings/python/examples/how_tos/nfts/send_nft.py
@@ -8,21 +8,20 @@
wallet = Wallet('./alice-database')
-account = wallet.get_account('Alice')
-
-# Sync account with the node
-response = account.sync()
-
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
+response = account.sync()
+
outputs = [{
"address": "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
"nftId": "0x17f97185f80fa56eab974de6b7bbb80fa812d4e8e37090d166a0a41da129cebc",
}]
transaction = account.prepare_send_nft(outputs).send()
-
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction["blockId"]}')
diff --git a/documentation/sdk/docs/how_tos/nfts/burn_nft.mdx b/documentation/sdk/docs/how_tos/nfts/burn_nft.mdx
new file mode 100644
index 0000000000..312efc1bd8
--- /dev/null
+++ b/documentation/sdk/docs/how_tos/nfts/burn_nft.mdx
@@ -0,0 +1,50 @@
+---
+title: Burn NFT
+description: 'How to burn NFT'
+image: /img/logo/iota_mark_light.png
+keywords:
+- how to
+- burn
+- nft
+- nodejs
+- python
+- rust
+---
+
+import CodeBlock from '@theme/CodeBlock';
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import RustCode from "!!raw-loader!../../../../../sdk/examples/how_tos/nfts/burn_nft.rs";
+import NodejsCode from "!!raw-loader!../../../../../bindings/nodejs/examples/how_tos/nfts/burn_nft.ts";
+import PythonCode from "!!raw-loader!../../../../../bindings/python/examples/how_tos/nfts/burn_nft.py";
+
+This How-To will show you how to burn an NFT.
+
+
+## Code Example
+
+
+
+
+ {RustCode}
+
+
+
+
+ {NodejsCode}
+
+
+
+
+ {PythonCode}
+
+
+
+
+## Expected Output
+
+```bash
+Transaction sent: 0xed7955f0c2d1a1e267b61b0a1859b58a9b5112385c18feae1a198f3a9992d19e
+Block included: https://explorer.shimmer.network/testnet/block/0x1c4fe528677089eeffaa01eefe34eda4a75f7c6f2020d83af61221571979f616
+Burned NFT 0xd2356323fad25efa3ec772a341d122eaf5ea3bf1cba48b70a1038b7d00bc385d
+```
diff --git a/documentation/sdk/docs/how_tos/nfts/mint_nft.mdx b/documentation/sdk/docs/how_tos/nfts/mint_nft.mdx
new file mode 100644
index 0000000000..163a3b1ae1
--- /dev/null
+++ b/documentation/sdk/docs/how_tos/nfts/mint_nft.mdx
@@ -0,0 +1,53 @@
+---
+title: Mint NFT
+description: 'How to mint NFT'
+image: /img/logo/iota_mark_light.png
+keywords:
+- how to
+- mint
+- nft
+- nodejs
+- python
+- rust
+---
+
+import CodeBlock from '@theme/CodeBlock';
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import RustCode from "!!raw-loader!../../../../../sdk/examples/how_tos/nfts/mint_nft.rs";
+import NodejsCode from "!!raw-loader!../../../../../bindings/nodejs/examples/how_tos/nfts/mint_nft.ts";
+import PythonCode from "!!raw-loader!../../../../../bindings/python/examples/how_tos/nfts/mint_nft.py";
+
+This How-To will show you how to mint nft.
+
+
+## Code Example
+
+
+
+
+ {RustCode}
+
+
+
+
+ {NodejsCode}
+
+
+
+
+ {PythonCode}
+
+
+
+
+## Expected Output
+
+```bash
+Transaction sent: 0x4890a22c8c06a55d0e28b00d7a684c2a25479ae02b644824a5930ff059418280
+Block included: https://explorer.shimmer.network/testnet/block/0xa7e1459879b7a4114b505ad2c5c67bf62b98b13a5ba530018c928530af873c3b
+Minted NFT 1
+Transaction sent: 0x308078cfd811fb99621e51791a431c6a306a077aceb99df6409188c61a27f372
+Block included: https://explorer.shimmer.network/testnet/block/0xa020b148abdeeb94256e4f78dd4e3d623420fd233e0bbf7c20f64fd53d4f4b8d
+Minted NFT 2
+```
diff --git a/documentation/sdk/docs/how_tos/nfts/send_nft.mdx b/documentation/sdk/docs/how_tos/nfts/send_nft.mdx
new file mode 100644
index 0000000000..781a9562ae
--- /dev/null
+++ b/documentation/sdk/docs/how_tos/nfts/send_nft.mdx
@@ -0,0 +1,49 @@
+---
+title: Send NFT
+description: 'How to send NFT to another address'
+image: /img/logo/iota_mark_light.png
+keywords:
+- how to
+- send
+- nft
+- nodejs
+- python
+- rust
+---
+
+import CodeBlock from '@theme/CodeBlock';
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+import RustCode from "!!raw-loader!../../../../../sdk/examples/how_tos/nfts/send_nft.rs";
+import NodejsCode from "!!raw-loader!../../../../../bindings/nodejs/examples/how_tos/nfts/send_nft.ts";
+import PythonCode from "!!raw-loader!../../../../../bindings/python/examples/how_tos/nfts/send_nft.py";
+
+This How-To will show you how to mint nft.
+
+
+## Code Example
+
+
+
+
+ {RustCode}
+
+
+
+
+ {NodejsCode}
+
+
+
+
+ {PythonCode}
+
+
+
+
+## Expected Output
+
+```bash
+Transaction sent: 0x58716bf9c7d3b36276a3ce9b57b43693c03bd6816198a7fe8ee1b814c424dae6
+Block included: https://explorer.shimmer.network/testnet/block/0xd7ccfb7922a719dcee7e4bf15eaf3a6983c378b7a4c16adf34a3eb001cfc5773
+```
diff --git a/documentation/sdk/sidebars.js b/documentation/sdk/sidebars.js
index d4a7f8153c..21225be8fb 100644
--- a/documentation/sdk/sidebars.js
+++ b/documentation/sdk/sidebars.js
@@ -135,6 +135,16 @@ module.exports = {
dirName: 'how-tos/outputs'
}
]
+ },
+ {
+ type: "category",
+ label: 'NFTs',
+ items: [
+ {
+ type: 'autogenerated',
+ dirName: 'how_tos/nfts'
+ }
+ ]
}
]
},
diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml
index d940e73ae2..83b539668f 100644
--- a/sdk/Cargo.toml
+++ b/sdk/Cargo.toml
@@ -594,18 +594,18 @@ path = "examples/wallet/offline_signing/3_send_transaction.rs"
required-features = [ "wallet", "storage" ]
[[example]]
-name = "send_nft"
-path = "examples/wallet/08_send_nft.rs"
+name = "mint_nft"
+path = "examples/how_tos/nfts/mint_nft.rs"
required-features = [ "wallet", "stronghold" ]
[[example]]
-name = "mint_nft"
-path = "examples/wallet/10_mint_nft.rs"
+name = "send_nft"
+path = "examples/how_tos/nfts/send_nft.rs"
required-features = [ "wallet", "stronghold" ]
[[example]]
name = "burn_nft"
-path = "examples/wallet/14_burn_nft.rs"
+path = "examples/how_tos/nfts/burn_nft.rs"
required-features = [ "wallet", "stronghold" ]
[[example]]
diff --git a/sdk/examples/wallet/14_burn_nft.rs b/sdk/examples/how_tos/nfts/burn_nft.rs
similarity index 70%
rename from sdk/examples/wallet/14_burn_nft.rs
rename to sdk/examples/how_tos/nfts/burn_nft.rs
index 4a38e6bb99..c6024acf91 100644
--- a/sdk/examples/wallet/14_burn_nft.rs
+++ b/sdk/examples/how_tos/nfts/burn_nft.rs
@@ -1,15 +1,10 @@
-// Copyright 2022 IOTA Stiftung
+// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! In this example we will burn an existing nft output.
+//! Rename `.env.example` to `.env` first.
//!
-//! Make sure that `example.stronghold` and `example.walletdb` already exist by
-//! running the `create_account` example!
-//!
-//! Rename `.env.example` to `.env` first, then run the command:
-//! ```sh
-//! cargo run --release --all-features --example burn_nft
-//! ```
+//! `cargo run --release --example burn_nft`
use std::env::var;
@@ -20,6 +15,7 @@ async fn main() -> Result<()> {
// This example uses secrets in environment variables for simplicity which should not be done in production.
dotenvy::dotenv().ok();
+ // Create the wallet
let wallet = Wallet::builder()
.with_storage_path(&var("WALLET_DB_PATH").unwrap())
.finish()
@@ -33,15 +29,13 @@ async fn main() -> Result<()> {
// Get the first nft
if let Some(nft_id) = balance.nfts().first() {
let nfts_before = balance.nfts();
- println!("NFTs BEFORE destroying:\n{nfts_before:#?}",);
+ println!("Balance before burning:\n{nfts_before:#?}",);
// Set the stronghold password
wallet
.set_stronghold_password(var("STRONGHOLD_PASSWORD").unwrap())
.await?;
- println!("Sending NFT burn transaction...");
-
let transaction = account.burn(*nft_id, None).await?;
println!("Transaction sent: {}", transaction.transaction_id);
@@ -49,17 +43,13 @@ async fn main() -> Result<()> {
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;
- println!(
- "Transaction included: {}/block/{}",
- var("EXPLORER_URL").unwrap(),
- block_id
- );
+ println!("Block included: {}/block/{}", var("EXPLORER_URL").unwrap(), block_id);
println!("Burned NFT '{}'", nft_id);
let balance = account.sync(None).await?;
let nfts_after = balance.nfts();
- println!("NFTs AFTER destroying:\n{nfts_after:#?}",);
+ println!("Balance after burning:\n{nfts_after:#?}",);
} else {
println!("No NFT available in account '{alias}'");
}
diff --git a/sdk/examples/wallet/10_mint_nft.rs b/sdk/examples/how_tos/nfts/mint_nft.rs
similarity index 73%
rename from sdk/examples/wallet/10_mint_nft.rs
rename to sdk/examples/how_tos/nfts/mint_nft.rs
index 4e5f5b04d5..72fda4d19b 100644
--- a/sdk/examples/wallet/10_mint_nft.rs
+++ b/sdk/examples/how_tos/nfts/mint_nft.rs
@@ -1,15 +1,10 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
-//! In this example we will mint an NFT in two different ways.
+//! In this example we will mint an NFT.
+//! Rename `.env.example` to `.env` first.
//!
-//! Make sure that `example.stronghold` and `example.walletdb` already exist by
-//! running the `create_account` example!
-//!
-//! Rename `.env.example` to `.env` first, then run the command:
-//! ```sh
-//! cargo run --release --all-features --example mint_nft
-//! ```
+//! `cargo run --release --example mint_nft`
use std::env::var;
@@ -39,15 +34,17 @@ async fn main() -> Result<()> {
// This example uses secrets in environment variables for simplicity which should not be done in production.
dotenvy::dotenv().ok();
+ // Create the wallet
let wallet = Wallet::builder()
.with_storage_path(&var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
+
+ // Get the account we generated with `01_create_wallet`
let account = wallet.get_account("Alice").await?;
- // May want to ensure the account is synced before sending a transaction.
- let balance = account.sync(None).await?;
- let nfts_before = balance.nfts();
+ // Ensure the account is synced after minting.
+ account.sync(None).await?;
// We send from the first address in the account.
let sender_address = *account.addresses().await?[0].address();
@@ -65,8 +62,6 @@ async fn main() -> Result<()> {
.try_with_issuer(sender_address)?
.with_immutable_metadata(NFT1_IMMUTABLE_METADATA.as_bytes().to_vec())];
- println!("Sending minting transaction for NFT 1...");
-
let transaction = account.mint_nfts(nft_params, None).await?;
println!("Transaction sent: {}", transaction.transaction_id);
@@ -74,11 +69,7 @@ async fn main() -> Result<()> {
let block_id = account
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;
- println!(
- "Transaction included: {}/block/{}",
- var("EXPLORER_URL").unwrap(),
- block_id
- );
+ println!("Block included: {}/block/{}", var("EXPLORER_URL").unwrap(), block_id);
println!("Minted NFT 1");
// Build an NFT manually by using the `NftOutputBuilder`
@@ -92,8 +83,6 @@ async fn main() -> Result<()> {
.finish_output(token_supply)?,
];
- println!("Sending minting transaction for NFT 2...");
-
let transaction = account.send(outputs, None).await?;
println!("Transaction sent: {}", transaction.transaction_id);
@@ -101,22 +90,11 @@ async fn main() -> Result<()> {
let block_id = account
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;
- println!(
- "Transaction included: {}/block/{}",
- var("EXPLORER_URL").unwrap(),
- block_id
- );
+ println!("Block included: {}/block/{}", var("EXPLORER_URL").unwrap(), block_id);
println!("Minted NFT 2");
// Ensure the account is synced after minting.
- let balance = account.sync(None).await?;
- let nfts_after = balance.nfts();
- println!("New owned NFTs:");
- nfts_after.iter().for_each(|nft_id| {
- if !nfts_before.contains(nft_id) {
- println!("- {nft_id}");
- }
- });
+ account.sync(None).await?;
Ok(())
}
diff --git a/sdk/examples/wallet/08_send_nft.rs b/sdk/examples/how_tos/nfts/send_nft.rs
similarity index 76%
rename from sdk/examples/wallet/08_send_nft.rs
rename to sdk/examples/how_tos/nfts/send_nft.rs
index da988a089d..5cd5f09ef8 100644
--- a/sdk/examples/wallet/08_send_nft.rs
+++ b/sdk/examples/how_tos/nfts/send_nft.rs
@@ -1,15 +1,10 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
-//! In this example we will send an NFT (Non-fungible token).
+//! In this example we will send an nft.
+//! Rename `.env.example` to `.env` first.
//!
-//! Make sure that `example.stronghold` and `example.walletdb` already exist by
-//! running the `create_account` example!
-//!
-//! Rename `.env.example` to `.env` first, then run the command:
-//! ```sh
-//! cargo run --release --all-features --example send_nft
-//! ```
+//! `cargo run --release --example send_nft`
use std::env::var;
@@ -26,6 +21,7 @@ async fn main() -> Result<()> {
// This example uses secrets in environment variables for simplicity which should not be done in production.
dotenvy::dotenv().ok();
+ // Create the wallet
let wallet = Wallet::builder()
.with_storage_path(&var("WALLET_DB_PATH").unwrap())
.finish()
@@ -54,11 +50,7 @@ async fn main() -> Result<()> {
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;
- println!(
- "Transaction included: {}/block/{}",
- var("EXPLORER_URL").unwrap(),
- block_id
- );
+ println!("Block included: {}/block/{}", var("EXPLORER_URL").unwrap(), block_id);
} else {
println!("No available NFTs");
}