I did all the steps required to use Moralis with react but and i get this Typescript error. What i miss ?
Error :
Failed to compile.
/Users/augustin/code/Etherum/Lottery/lottery/src/App.tsx
TypeScript error in /Users/augustin/code/Etherum/Lottery/lottery/src/App.tsx(41,13):
Cannot find name 'Moralis'. TS2304
39 | note: "Thanks for your participation"
40 | },
> 41 | msgValue: Moralis.Units.ETH(0.001)
| ^
42 | }
43 | await Moralis.executeFunction(options);
44 | }
Code :
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { useMoralis } from "react-moralis";
function App() {
const { authenticate, isAuthenticated, isAuthenticating, user, account, logout } = useMoralis();
const login = async () => {
if (!isAuthenticated) {
await authenticate({signingMessage: "Log in using Moralis" })
.then(function (user) {
console.log("logged in user:", user);
console.log(user!.get("ethAddress"));
})
.catch(function (error) {
console.log(error);
});
}
}
const logOut = async () => {
await logout();
console.log("logged out");
}
async function enter() {
let options = {
contractAddress: "0x9111eF993A41d97862E76E8A47FC4074E4907b50",
functionName: "enter",
abi: [{"inputs": [],"name": "enter","outputs": [],"stateMutability": "payable","type": "function"}],
params:{
note: "Thanks for your participation"
},
msgValue: Moralis.Units.ETH(0.001)
}
await Moralis.executeFunction(options);
}
return (
<div>
<h1>Moralis Hello World!</h1>
<button onClick={login}>Moralis Metamask Login</button>
<button onClick={logOut} disabled={isAuthenticating}>Logout</button>
<button onClick={enter}>Enter</button>
</div>
);
}
export default App;
Thanks for your help guys