ICRC7 Minting function help (Motoko)

Hi devs, Is anyone playing with ICRC7? I need help trying to code my mint function. Im following this guide: 5.4 NFT Turorial

Repo

Blockquote

However, the default icrcx_mint Function, allows you to hardset the NFT Metadata yourself whilst calling the Function.

What Im trying to do is to code it automatically on the function itself!, so anyone can call the function, and it will automatically create NFT with its respective token_id metadata, which is basically a URL pointing to a ,json file.

This sounds simple but with the integration of ICRC37 and ICRC3 I find it extreamly hard to comprehend, as Im new to coding.

I’m playing around with that repo, so I’ll share my approach, which might be helpful. First I removed icrc37 and unnecessary initialization logic because it’s a bit excessive imo.

Then I do all update interactions (mint/burn) through another (rust) canister. No need to look past the first mint function if that’s all you’re doing but something like this might be helpful.

I also know very little about motoko, so not messing with the logic inside ‘icrc_nft’ was more approachable for me. Now to mint, all you need is a string and other metadata is pre-populated as you like.

1 Like

I’ll be happy to help.

icrcx_mint is not part of the standard, so you are free to implement it however you would like. You’re going to need to learn some motoko, but you should be able to get where you want to go pretty easily.

The example hardcodes the items and passes them in via DFX. If you want logic in the cainster to create any number of NFT or use randomness, you just need to program it.

You are basically just trying to build the following structure:

public type SetNFTItemRequest = {
    token_id: Nat;
    metadata: NFTInput;
    owner: ?Account;
    override: Bool;
    memo: ?Blob;
    created_at_time : ?Nat64;
  };

The core NFT stuff is in the metadata. You want it to looks something like this:

public shared(msg) mintanything(url: Text,mime:Text,description: Text,name: text) : async (){
     icrc7().set_nfts<system>(msg.caller, [{
       token_id = 2;
      owner = ?{ owner =msg.caller; subaccount = null;};
      metadata = #Map([
           ("icrc97:metadata", #Map([
                 ("name", #Text(name),
                 ("description", #Text(description)),
                 ("assets", #Array([
                      #Map([
                        ("url", #Text(url)),
                        ("mime", #Text(mime)), 
                        ("purpose", #Text("icrc97:image")
                      ])
                 ])
             ]),
      memo = null;
      override = true;
      created_at_time = null;
}], true)
}
1 Like

Thanks Evan, the code you shared is very clean and it is exacty what Im looking to implement, but on Motoko, as IDK Rust! :frowning_face:

I will try to accomodate that onto motoko code, and I will follow your advise of removing ICRC37 at least until I get the mint function going. Thanks!

1 Like

Thanks Skilesare, I will try testing with that code, but you answered my question on how the structure will most likely go! Cheers! :grinning: :pray:

You may want to check out @sea-snake 's ICRC-97 that aims to be compatible with OpenSea like NFT metadata: ICRC/ICRCs/ICRC-97/ICRC-97.md at icrc-97-nft-metadata · sea-snake/ICRC · GitHub (which is what I tried to use in the example above).

1 Like

Nice, thanks for the information, I will check it out!