Skip to content

Blob of mintNFT'argument is not match front-side's input #17

@hokosugi

Description

@hokosugi

I converted the string input value of front-size to Blob and used it as an argument to the mintNFTfunction to mint erc721-like nft, but got an error below.
I think metadeta value doesn't match blob variant, so need to match Blob type in motoko and blob in javascript.But I don't know what I do. What is needed? Thank you in advance.

error (chrome validation)

myNFT
index.js:17781 Blob {size: 5, type: 'text/html'}
index.js:17791 name::::myNFT
index.js:17793 miner::::rrkah-fqaaa-aaaaa-aaaaq-cai
index.js:4524 Uncaught (in promise) Error: Invalid record {to:variant {principal:principal; address:text}; metadata:opt vec nat8} argument: {"to":{"principal":{"_arr":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":1,"8":1,"9":1},"_isPrincipal":true},"address":""},"metadeta":{}}
    at index.js:4524:19
    at index.js:3435:29
    at Array.map (<anonymous>)
    at zipWith (index.js:3435:15)
    at Module.encode (index.js:4522:75)
    at caller (index.js:199:74)
    at CanisterActor.handler [as mintNFT] (index.js:221:34)
    at HTMLButtonElement.<anonymous> (index.js:17798:99)
(匿名) @ index.js:4524
(匿名) @ index.js:3435
zipWith @ index.js:3435
encode @ index.js:4522
caller @ index.js:199
handler @ index.js:221
(匿名) @ index.js:17798

index.js (src/myNFT_assets)

document.getElementById("mintNftBtn").addEventListener("click", async () => {
  const nft = document.getElementById("nft").value.toString();
  console.log(nft);
  const blob = new Blob([nft], {type: 'text/html'});
  console.log(blob);
  function readAsText(b) {
    return new Promise((resolve, reject) => {
      let reader = new FileReader();
      reader.onload = () => { resolve(reader.result); };
      reader.onerror = () => { reject(reader.error); };
      reader.readAsText(b);
    });
  };
  const name = await readAsText(blob);
  console.log("name::::"+name);
  const minter = await dfinity_nft_ext.getMinter();
  console.log("miner::::"+minter);
  const mintReq = {
    to: { principal: minter, address: "" },
    metadeta: blob  // as execute, empty: "metadeta":{}
  };
  const minted = await dfinity_nft_ext.mintNFT(mintReq);  // mint
  console.log("minted::::"+minted);  //Maybe return minted number

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions