[SOLVED] "TokenId missing" error in Moralis.transfer()

So I am building a new contract and trying to test the transfer function, but I continually get an error in my console log in:

let result = await Moralis.transfer(options);

This is the console in the browser at the moment:

options in transfer()
1. {type: 'erc1155', receiver: '<receiver_address>', contractAddress: '<contract_address>', tokenId: 0, amount: 2}

  1. amount: 2
  2. contractAddress: '<contract_address'
  3. receiver:  '<receiver_address>'
  4. tokenId: 0
  5. type: "erc1155"
  6. [[Prototype]]: Object

Uncaught (in promise) ['tokenId is required'] transfer @ transfer.js:33

The tokenId is typed as in the docs and tutorial on YT, and it’s being logged correctly from the IDE in the frontend. What is the issue here? Does 0 not function as a tokenId? Filip used tokenId = 1 in the tutorial so he didn’t hit this wall.

You can use “0” instead of 0 and it should work

Well the ID should be a number so they can be incremented, not a string. I don’t want to go make a new contract, new test servers, burn all my tokens, reconnect everything, make new tokens, etc… That’s an hour wasted because the system cant take a number 0 but would take a string “0”? Why did Filip use 0 as one of the NFT token id’s in the tutorial if it doesnt actually work to transfer them later? It certainly is functioning to SHOW them and burn them after, but not transferring.

I’m just curious as to whether or not the issue truly is that the Moralis code sees this 0 as an ‘unidentified’ value of some sort (I say that for lack of knowing the correct term here). I also don’t believe that not solving this problem and saying to use a string where a number should go is a good solution. This seems hacky and isnt what I want.

dangit i wanted to edit my post and it deleted…
I wanted to say that I need a number and I don’t want to remake all my contract and NFTs and servers blah blah blah… just because the transfer function cannot (but should) handle an id=0 as a number and not a string. I would like to increment numbers and not be sending strings ( which could lead to errors later if strings are accepted ). This isnt a solution

I think that you only need to send that parameter as a sting, only for 0 and it would work fine without any change in your smart contract. I think that it is a problem in that function for parameters that are null or 0. Are you also using latest version of Moralis SDK?

But the tokenId is a number, so won’t sending a string 0 to the Moralis API cause an error if it’s expecting a number?
SDK: I have no idea about what version I’m using, I just followed Filip’s YT tutorial video…

It doesn’t matter at all, there is no difference between you provide number or string, in the end, they both will become a string type

Okay :slight_smile: I will try it

1 Like

I guess we have a fix for this already, but it’s not merged to the production :sweat_smile:

Sure, let me know how does it work for you

Setting the incoming tokenId as such:

if (tokenId === 0) {
tokenId = tokenId.toString();

Works. I think having that built into the codebase OR telling the codebase that in this specific parameter, 0 is a value not a lack of value, that would be great. Idk which route you guys took :slight_smile:

Thank you!