Transferring NFTs

Can you put some lines with console log to see if that code executes?

Uncaught SyntaxError: Unexpected token ‘const’
transfer.html:10 Uncaught ReferenceError: runcode is not defined
at HTMLButtonElement.onclick (transfer.html:10)

It looks like the code doesn’t run because it tries to call a function before was defined.

So am I missing something in the

<head>

then maybe?

Do you know how to call that function from the browser console?

Sorry but no I do not.

Ok, can you try to search on google how to do it? I guess that you also started a local http server.

You enter the function name in the browser console

now it looks like that is not a complete function, it looks like it is missing { }

Yeh I deleted the object then put it back missing them by accident, they are back now. This is frustrating, is this article correct or what? My code is verbatim is it not? This is supposedly a simple task but is seemingly not and I can’t figure out if it is me, the code or the article all I know is nothing happens.

what I wanted to say that instead of:

function runcode()
	const options = {type: "erc721",  
                 receiver: "0xaE46BA4588b0e60a85a6831b799782238EFa4c45",
                 contractAddress: "0xb38eb14171A5913B9E61c76829F14Cf5899E4073",
                 tokenId: 10102}
	let result = await Moralis.transfer(options)

it should be:

function runcode(){
	const options = {type: "erc721",  
                 receiver: "0xaE46BA4588b0e60a85a6831b799782238EFa4c45",
                 contractAddress: "0xb38eb14171A5913B9E61c76829F14Cf5899E4073",
                 tokenId: 10102}
	let result = await Moralis.transfer(options)
}

also I think that here <button onclick="runcode()">Run Code</button> it should be <button onclick="runcode">Run Code</button>, but this one is from the article

and you can also write directly in the browser console runcode and press enter

Thank you for your help here cryptokid.

I had put the {} back already and I just tried changing <button onclick="runcode()"> to <button onclick="runcode"> but still to no avail.

I am now thinking that I need to add some code to connect Metamask to the page first maybe?

I will put the () back for now.

I copied this and run directly in browser console and it worked for me:

await Moralis.enableWeb3();
const options = {type: "erc721",  
                 receiver: "0xaE46BA4588b0e60a85a6831b799782238EFa4c45",
                 contractAddress: "0xb38eb14171A5913B9E61c76829F14Cf5899E4073",
                 tokenId: 10102}
	let result = await Moralis.transfer(options)

it looks like you also have to call Moralis.enableWeb3()

Maybe it is my set up? I adjusted the code in the page, can you please go see if it works live on the page I have up? It isn’t working at my end and I have called Moralis.enableWeb3()

What error you get now?

Same as ever - Uncaught ReferenceError: runcode is not defined (line 10)

and

Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules (line 12)

After you open the page, can you paste the above code that I pasted in your browser console? It should work

Just did and yes, it fires up Metamask just fine…

So is it my contract address then?

No, I think that it is how the JavaScript code is written in that html, I copied that code from your code and added one more line with enableWeb3