Send ETH, ERC20 and NFTs [ONE LINE OF CODE] Help

Hey
I follow the instruction on the video and it not works
I used the text from the video tutorial and from the documentation and still nothing happens

<html>
    <head>
        <title>Vanilla Boilerplate</title>

            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
            <script src="https://npmcdn.com/moralis/dist/moralis.js"></script>

    </head>

    <body>

        <buttom onclick="runcode()">Run Code</buttom>
        <br><br>

        <script>
        function runcode(){
           // sending 0.5 ETH
            Moralis.transfer({type:"native",receiver:"0x1471054eF555b52C35e7B94f2302e2273c14Ad50",
                                amount:Moralis.Units.ETH("0.5")});
        }    


        </script>
    </body>

</html>

and also

<html>

    <head>

        <title>Vanilla Boilerplate</title>

            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>

            <script src="https://npmcdn.com/moralis/dist/moralis.js"></script>

    </head>

    <body>

        <buttom onclick="runcode()">Run Code</buttom>

        <br><br>

        <script>

        function runcode(){

           // sending 0.5 ETH

        const options = {type: "native", amount: Moralis.Units.ETH("0.5"), receiver: "0x1471054eF555b52C35e7B94f2302e2273c14Ad50"}

        let result = await Moralis.transfer(options)

        }    

        </script>

    </body>

did you connect to metamask? I don’t see any button to connect first

Also try to check the console for any error, that’ll be helpful to debug :raised_hands:

How do I connect metamask? didn’t saw any reference to it via the video

Checking the page with dev tools gave me that errors

4moralis.js:7317 Uncaught (in promise) Error: Missing web3 instance, make sure to call Moralis.enableWeb3() or Moralis.authenticate()
at Function.value (moralis.js:7317:48)
at Function. (moralis.js:7101:46)
at tryCatch (moralis.js:73356:40)
at Generator.invoke [as _invoke] (moralis.js:73587:22)
at Generator.next (moralis.js:73412:21)
at asyncGeneratorStep (moralis.js:30002:24)
at _next (moralis.js:30024:9)
at moralis.js:30031:7
at new Promise ()
at new Wrapper (moralis.js:56579:24)
value @ moralis.js:7317
(anonymous) @ moralis.js:7101
tryCatch @ moralis.js:73356
invoke @ moralis.js:73587
(anonymous) @ moralis.js:73412
asyncGeneratorStep @ moralis.js:30002
_next @ moralis.js:30024
(anonymous) @ moralis.js:30031
Wrapper @ moralis.js:56579
(anonymous) @ moralis.js:30020
(anonymous) @ moralis.js:7166
runcode @ Untitled-1.html:18
onclick @ Untitled-1.html:12

also do I need to install something to use the SDK? maybe that might be the problem?

No you don’t need to, you already import it with CDN in the script tag. And yeah you need to connect with wallet first, as the error mentioned, you need to call Moralis.authenticate. I’m not very sure which video are you referring to so can’t tell

I saw this video
https://www.youtube.com/watch?v=suZYvqrc_Hg&t=212s

How do I connect Metamask and call to

Moralis.authenticate.

just make a button and call it from button’s onclick

That not work that why I opened the topic :sweat_smile:

I mean for Moralis.authenticate :sweat_smile: so that you can connect to metamask first then transfer

could you please express it via a code? and which on of the codes the first or the last?

Hey man,
For 90% of Moralis functionality, you need to authenticate to do so. On click of a button the function below should be called

async Login{
   await Moralis.authenticate();
}
1 Like

When I adding

async Login{
   await Moralis.authenticate();
}

I getting the following error

I think you need the function identifier

async function Login() {
   await Moralis.authenticate();
}

I updated the code to this

<html>
    <head>
        <title>Vanilla Boilerplate</title>

            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
            <script>Moralis.authenticate</script>
            <script src="https://npmcdn.com/moralis/dist/moralis.js"></script>

    </head>

    <body>

        <buttom onclick="runcode()">Run Code</buttom>
        
        
        <br><br>

        <script>
        function runcode(){
           // sending 0.5 ETH
            Moralis.transfer({type:"native",receiver:"0x1471054eF555b52C35e7B94f2302e2273c14Ad50",
                                amount:Moralis.Units.ETH("0.5")});
                                
        }
            


        </script>
    </body>



</html>

But getting the following error

Untitled-1.html:6 Uncaught ReferenceError: Moralis is not defined
at Untitled-1.html:6

when I try this code

<html>
    <head>
        <title>Vanilla Boilerplate</title>

            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
            <script>async function Login() {
                await Moralis.authenticate();
             }</script>
            <script src="https://npmcdn.com/moralis/dist/moralis.js"></script>

    </head>

    <body>

        <buttom onclick="runcode()">Run Code</buttom>
        
        
        <br><br>

        <script>
        function runcode(){
           // sending 0.5 ETH
            Moralis.transfer({type:"native",receiver:"0x1471054eF555b52C35e7B94f2302e2273c14Ad50",
                                amount:Moralis.Units.ETH("0.5")});
                                
        }
            


        </script>
    </body>



</html>

I getting the following error

moralis.js:7317 Uncaught (in promise) Error: Missing web3 instance, make sure to call Moralis.enableWeb3() or Moralis.authenticate()
at Function.value (moralis.js:7317)
at Function. (moralis.js:7101)
at tryCatch (moralis.js:73356)
at Generator.invoke [as _invoke] (moralis.js:73587)
at Generator.next (moralis.js:73412)
at asyncGeneratorStep (moralis.js:30002)
at _next (moralis.js:30024)
at moralis.js:30031
at new Promise ()
at new Wrapper (moralis.js:56579)

up :sweat_smile:
could you please assist me?