forked from iotaledger/wallet.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_mint_nft.rs
81 lines (66 loc) · 2.79 KB
/
10_mint_nft.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example mint_nft --release
// In this example we will mint a native token
// Rename `.env.example` to `.env` first
use std::env;
use dotenv::dotenv;
use iota_wallet::{
account_manager::AccountManager,
iota_client::block::output::{
feature::{IssuerFeature, SenderFeature},
unlock_condition::AddressUnlockCondition,
Feature, NftId, NftOutputBuilder, UnlockCondition,
},
NftOptions, Result,
};
#[tokio::main]
async fn main() -> Result<()> {
// This example uses dotenv, which is not safe for use in production
dotenv().ok();
// Create the account manager
let manager = AccountManager::builder().finish().await?;
// Get the account we generated with `01_create_wallet`
let account = manager.get_account("Alice").await?;
account.sync(None).await?;
// Set the stronghold password
manager
.set_stronghold_password(&env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;
let nft_options = vec![NftOptions {
address: Some("rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string()),
sender: Some("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string()),
metadata: Some(b"some NFT metadata".to_vec()),
tag: Some(b"some NFT tag".to_vec()),
issuer: Some("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy".to_string()),
immutable_metadata: Some(b"some NFT immutable metadata".to_vec()),
}];
let transaction = account.mint_nfts(nft_options, None).await?;
println!("Transaction: {}.", transaction.transaction_id,);
println!(
"Block sent: {}/api/core/v2/blocks/{}.",
&env::var("NODE_URL").unwrap(),
transaction.block_id.expect("no block created yet")
);
// Build nft output manually
let sender_address = account.addresses().await?[0].address().clone();
let token_supply = account.client().get_token_supply()?;
let outputs = vec![
// address of the owner of the NFT
NftOutputBuilder::new_with_amount(1_000_000, NftId::null())?
.add_unlock_condition(UnlockCondition::Address(AddressUnlockCondition::new(
*sender_address.as_ref(),
)))
.add_feature(Feature::Sender(SenderFeature::new(*sender_address.as_ref())))
.add_immutable_feature(Feature::Issuer(IssuerFeature::new(*sender_address.as_ref())))
.finish_output(token_supply)?,
];
let transaction = account.send(outputs, None).await?;
println!(
"Transaction: {} Block sent: {}/api/core/v2/blocks/{}",
transaction.transaction_id,
&env::var("NODE_URL").unwrap(),
transaction.block_id.expect("No block created yet")
);
Ok(())
}