nifty_cli/commands/
create.rs

1use super::*;
2
3pub struct CreateArgs {
4    pub keypair_path: Option<PathBuf>,
5    pub rpc_url: Option<String>,
6    pub name: String,
7    pub asset_keypair_path: Option<PathBuf>,
8    pub immutable: bool,
9    pub owner: Option<Pubkey>,
10}
11
12pub fn handle_create(args: CreateArgs) -> Result<()> {
13    let config = CliConfig::new(args.keypair_path, args.rpc_url)?;
14
15    let asset_sk = if let Some(path) = args.asset_keypair_path {
16        read_keypair_file(path).expect("failed to read keypair file")
17    } else {
18        Keypair::new()
19    };
20    let authority_sk = config.keypair;
21
22    let asset = asset_sk.pubkey();
23    let authority = authority_sk.pubkey();
24    let owner = args.owner.unwrap_or(authority);
25
26    let ix_args = CreateInstructionArgs {
27        name: args.name,
28        standard: Standard::NonFungible,
29        mutable: !args.immutable,
30        extensions: None,
31    };
32
33    let ix = Create {
34        asset,
35        authority: (authority, false),
36        owner,
37        payer: Some(authority),
38        group: None,
39        group_authority: None,
40        system_program: Some(system_program::id()),
41    }
42    .instruction(ix_args);
43
44    let sig = send_and_confirm_tx(&config.client, &[&authority_sk, &asset_sk], &[ix])?;
45
46    println!("Asset {asset} created in tx: {sig}");
47
48    Ok(())
49}