Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IRC metadata in examples #1180

Merged
merged 9 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ required-features = ["wallet", "storage", "stronghold"]
[[example]]
name = "mint_collection_nft"
path = "examples/how_tos/nft_collection/01_mint_collection_nft.rs"
required-features = ["wallet", "stronghold"]
required-features = ["wallet", "stronghold", "irc_27"]

# Native Tokens Examples

Expand Down Expand Up @@ -781,7 +781,7 @@ required-features = ["wallet", "storage"]
[[example]]
name = "mint_nft"
path = "examples/how_tos/nfts/mint_nft.rs"
required-features = ["wallet", "stronghold"]
required-features = ["wallet", "stronghold", "irc_30"]

[[example]]
name = "send_nft"
Expand Down
31 changes: 14 additions & 17 deletions sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use iota_sdk::{
types::block::{
address::{Bech32Address, NftAddress},
output::NftId,
output::{feature::Irc27Metadata, NftId},
payload::transaction::TransactionId,
},
wallet::{Account, MintNftParams, Result},
Expand Down Expand Up @@ -60,7 +60,7 @@ async fn main() -> Result<()> {
let nft_mint_params = (0..NFT_COLLECTION_SIZE)
.map(|index| {
MintNftParams::new()
.with_immutable_metadata(get_immutable_metadata(index, issuer_nft_id).as_bytes().to_vec())
.with_immutable_metadata(get_immutable_metadata(index).to_bytes())
// The NFT address from the NFT we minted in mint_issuer_nft example
.with_issuer(issuer)
})
Expand Down Expand Up @@ -89,21 +89,18 @@ async fn main() -> Result<()> {
Ok(())
}

fn get_immutable_metadata(index: usize, issuer_nft_id: NftId) -> String {
// Note: we use `serde_json::from_str` to remove all unnecessary whitespace
serde_json::from_str::<serde_json::Value>(&format!(
r#"{{
"standard":"IRC27",
"version":"v1.0",
"type":"video/mp4",
"uri":"ipfs://wrongcVm9fx47YXNTkhpMEYSxCD3Bqh7PJYr7eo5Ywrong",
"name":"Shimmer OG NFT #{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"
}}"#
)).unwrap().to_string()
fn get_immutable_metadata(index: usize) -> Irc27Metadata {
Irc27Metadata::new(
"video/mp4",
"ipfs://wrongcVm9fx47YXNTkhpMEYSxCD3Bqh7PJYr7eo5Ywrong".parse().unwrap(),
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
format!("Shimmer OG NFT #{index}"),
)
.with_description(
"The Shimmer OG NFT was handed out 1337 times by the IOTA Foundation \
to celebrate the official launch of the Shimmer Network.",
)
.with_issuer_name("IOTA Foundation")
.with_collection_name("Shimmer OG")
}

async fn wait_for_inclusion(transaction_id: &TransactionId, account: &Account) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions sdk/examples/how_tos/nfts/mint_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use iota_sdk::{
types::block::output::{
feature::{IssuerFeature, SenderFeature},
feature::{Irc30Metadata, IssuerFeature, SenderFeature},
unlock_condition::AddressUnlockCondition,
NftId, NftOutputBuilder,
},
Expand All @@ -25,8 +25,6 @@ use iota_sdk::{
const NFT1_OWNER_ADDRESS: &str = "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu";
// The metadata of the first minted NFT
const NFT1_METADATA: &str = "some NFT metadata";
// The immutable metadata of the first minted NFT
const NFT1_IMMUTABLE_METADATA: &str = "some NFT immutable metadata";
// The tag of the first minted NFT
const NFT1_TAG: &str = "some NFT tag";
// The base coin amount we sent with the second NFT
Expand Down Expand Up @@ -57,13 +55,15 @@ async fn main() -> Result<()> {
.set_stronghold_password(std::env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;

let metadata = Irc30Metadata::new("My NFT", "MYNFT", 10).with_description("My super cool NFT.");
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved

let nft_params = [MintNftParams::new()
.try_with_address(NFT1_OWNER_ADDRESS)?
.try_with_sender(sender_address)?
.with_metadata(NFT1_METADATA.as_bytes().to_vec())
.with_tag(NFT1_TAG.as_bytes().to_vec())
.try_with_issuer(sender_address)?
.with_immutable_metadata(NFT1_IMMUTABLE_METADATA.as_bytes().to_vec())];
.with_immutable_metadata(metadata.to_bytes())];

let transaction = account.mint_nfts(nft_params, None).await?;
println!("Transaction sent: {}", transaction.transaction_id);
Expand Down
Loading