Use own TokenID in contract instead of Counters

Hello, maybe someone can help me.

I create my own js-file with following code:

const nftId1 = await mintNft(nftFileMetadataFilePath1, ownID);
	console.log(nftId1);

and here is my mintNFT-function in the same file, which i call.

/*** minten */
mintNft = async (metadataUrl, ownTokenID) => {

	const receipt = await tokenContract.methods.createItem(metadataUrl, ownTokenID).send({from: ethereum.selectedAddress});
	return receipt.events.Transfer.returnValues.tokenId;
}

from here i call the contract: tokenContract.methods.createItem(metadataUrl, ownTokenID)

Here the code:

    //create item function
    function createItem(string memory uri, uint256 ownID) public returns (uint256) {
        _safeMint(msg.sender, ownID);
        Items[ownID] = Item(ownID, msg.sender, uri);
        return ownID;
    }

this does not work, because the parent “createItem”- I do not know, where it is in all the files!

And it has only one parameter (two are not allowed) and this function is not virtual, so that with “override” it is not posible to change it by myself.

I only need to set my own ID from my js-file to the .contract- like you can see above.

Thanks for help and maybe for a nice solution…

what if you name that function createMyItem?

I try it, but then it say - function is not define, then i change it.

Only with one parameter work the createItem(string memory uri)

But this is not what i need. I need two parameters… like above.

CreateItem has a motherfile! And here i make a cild of the motherfile, but i search the motherfile in all files, like ERC721.sol, and so on, but I do not find this function… but somewhere it has to be their…

I change it in the api.js, but this is also not right…

I only need a solution, where i can set my ownID in the contract…

what is the error that you get?

The function has to wear the name “createItem” - nothing else works!

Here the error_Message, the moralis_server says “No”.
1.) the function has only one Parameter, and let me not change it.
2.) the function has the name “createItem”

see attachment…

This is the error, when i change the name of this function in the contract.

And the second picture, show the error, when i want to change it into TWO PARAMETERS

here the source-code:

  //create item function in the contract
    function createItem(string memory uri, uint256 ownTokenID) public returns (uint256) {
       
        _safeMint(msg.sender, ownTokenID);

        Items[ownTokenID] = Item(ownTokenID, msg.sender, uri);

        return ownTokenID;
    }
    
    
    
    /*** minten in my own js-file*/
mintNft = async (metadataUrl, ownTokenID) => {

	const receipt = await tokenContract.methods.createItem(metadataUrl, ownTokenID).send({from: ethereum.selectedAddress});
	console.log(receipt);
	return receipt.events.Transfer.returnValues.tokenId;

}


I mean, did you deploy a new smart contract with a new modified function?

In javascript you will get an error if you don’t update the abi and keep using the abi when the function had 1 parameter

That make sense, but i try and something i do not see:

 {
    "inputs": [
      {
        "internalType": "string",
        "name": "uri",
        "type": "string"
      }
    ],
    "inputs": [
      {
        "internalType": "uint256",
        "name": "ownID",
        "type": "uint256"
      }
    ],
    "name": "createItem",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },

This is my ABI.js - I have add the second parameter, (like you see [ownID]) but still i get the error: "invalid number of parameters for function “createItem”, Got two, expected 1!

I have change it - like you write - before with two parameters, I registered the tokencontractaddress, and maketplaceaddress, load it to my server, but something is wrong…

In the moment: “I can’t see the forest for the trees…”

Maybe someone else…

thanks

I have make a mistake in the ABI.js, but this was not the solution!
Still i get the error: "invalid number of parameters for function “createItem”, Got two, expected 1!

Hello cryptokid,

thanks for your reply. This was the solution!

But, when i forget to load the abi.js to my server, then I shouldn’t be surprised, when it not works.

Really, i think i need a break for today, till i go on…

Thanks.

Perfect…

1 Like