Invalid Token Id for Moralis.transfer

Hi,
Iā€™m trying to do a simple transfer with Moralis but Iā€™m getting ā€œInvalid Token Idā€ error.

Iā€™m importing the latest web3 library

	<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
	<script src="https://unpkg.com/moralis/dist/moralis.js"></script>

Hereā€™s the code adapted from your example

    const web3 = await Moralis.enableWeb3();
    const options = { type: "native", receiver: "0x7336BfdA526724B7900c4f5A84B7065295b50E2b", amount: Moralis.Units.ETH("0.5")};
    const tx = await Moralis.transfer(options);

and the error:

I tested both rinkeby and mainnet but Iā€™ve got the same result

I might be doing something wrong, many thanks for your help!

Very weird,
I added the tokenId parameter and itā€™s now working.

    const options = { tokenId: 1, type: "native", receiver: "0x7336BfdA526724B7900c4f5A84B7065295b50E2b", amount: Moralis.Units.ETH("0.5")};
    const tx = await Moralis.transfer(options);

Is tokenId parameter required when sending ETH to another address?

I think that it is a bug that we have to fix with that tokenId parameter.

Ok thanks for confirming

1 Like

Iā€™m having a similar issue but it is when tokenId = 0 as in Filipā€™s ā€œnft contract complete guideā€ tutorial.

It seems that Moralis.transfer cannot read a tokenId of 0 as it believes this is a non-value or lack of value, as if I put amount = 0.

How can this be fixed? Simply not using ā€œsomeNFT_id = 0ā€ and starting with 1?

You can send it as a string as ā€œ0ā€

1 Like