i was following this tutorial on you tube, Interact with Smart Contracts through your website (JS and REACT tutorial).
i have develop my own smartcontract : address-0x17162F8b6508aaFA79b9533e9683edDBA05726b6
its on bsc testnet. its a simple contract with increase counter. while i finish my code i am facing these errors
moralis.js:7565 Uncaught (in promise) Error: Missing web3 instance, make sure to call Moralis.enableWeb3() or Moralis.authenticate()
at Function.value (moralis.js:7565:48)
at Function.<anonymous> (moralis.js:7375:46)
at tryCatch (moralis.js:74788:40)
at Generator.invoke [as _invoke] (moralis.js:75019:22)
at Generator.next (moralis.js:74844:21)
at asyncGeneratorStep (moralis.js:30969:24)
at _next (moralis.js:30991:9)
at moralis.js:30998:7
at new Promise (<anonymous>)
at new Wrapper (moralis.js:57965:24)
my js file
const serverUrl = "https://42o5wyensnv6.usemoralis.com:2053/server"
const appId = "9fjqg7uSqJQKwl8J7SgpMpWQWy4alUJfE4Au7LsR"
Moralis.start({serverUrl, appId})
async function login(){
let user= Moralis.User.current();
if(!user){
try{
user= await Moralis.authenticate({signMessage:" done"});
await Moralis.enableWeb3();
console.log(user)
console.log(user.get('ethAddress'));
}catch(error){
console.log(error)
}
}
}
async function btn(){
let op={
contractAddress:"0x17162F8b6508aaFA79b9533e9683edDBA05726b6",
functionName:"setCount",
Abi:[{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"setCount","outputs":[],"stateMutability":"nonpayable","type":"function"}],
}
await Moralis.executeFunction(op);
document.getElementById('logn').onclick= login;
document.getElementById('count').onclick= btn;
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>web3</title>
<!-- INSTALL THE SDK and WEB3 -->
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
<!-- / -->
</head>
<body>
<button id="logn">login</button>
<button id="count">counter</button>
<div id="fcount" >0</div>
<script src="main.js"></script>
</body>
</html>
what i am doing wrong, any suggestions?