1

How to create nft in statemint in javascript.and how to set the nft images. can any one provide the example. my test code go wrong.

 const wsProvider = new polkadot.WsProvider("wss://westmint-rpc.polkadot.io");
 const api = await polkadot.ApiPromise.create({provider:wsProvider});

let tx = api.tx.utility.batchAll([
  api.tx.uniques.create(classId, ADDR_1);
  api.tx.uniques.setAttribute(classId, null,"Link","https://cloudflare-ipfs.com/ipfs/QmRdpVRCLxN51vNnYCRr2is1w6UVpT3mR8YDov9ktPmKub"), // this tx will crash
    ]);
tx.signAndSend(pair);
  
3
  • 1
    It is crashing because you are hitting the ValueLimit.
    – Bruno
    May 13, 2022 at 0:22
  • Next time please provide the associated error message. Thanks!
    – Bruno
    May 13, 2022 at 0:23
  • well. api.tx.uniques.setAttribute(classId, null,"Link","https://cloudflare-ipfs.com/ipfs/QmRdpVRCLxN51vNnYCRr2is1w6UVpT3mR8YDov9ktPmKub"), // this tx will crash this line will crash in rust
    – polaris
    May 13, 2022 at 4:03

1 Answer 1

2

Here is an example of using the uniques pallet to create non-fungible assets:

export const createNonFungibleAssets = async () => {
    let tx = api.tx.utility.batchAll([
        api.tx.uniques.create(classId, admin),
        api.tx.uniques.setAttribute(classId, 1, "cid", "FgsChd2hVdrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68k"),
        api.tx.uniques.setAttribute(classId, 2, "cid", "JrqChd2hKbrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68d"),
        api.tx.uniques.setAttribute(classId, 3, "cid", "LxmChd2hSsrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68a"),
        api.tx.uniques.mint(classId, 1, owner),
        api.tx.uniques.mint(classId, 2, owner),
        api.tx.uniques.mint(classId, 3, owner)
    ])
    tx.signAndSend(pair, ({ status }) => {
        if (status.isInBlock) {
          console.log(`included in ${status.asInBlock}`);
        }
      });
}

Typically you will not store the image on-chain. You would use a third-party service to store the images and store the hash on-chain.

1
  • !!the answer you give is so bad
    – polaris
    May 13, 2022 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.