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/[email protected]/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