I Enable metamask and disable metamask.
but when i try to commit the transaction it fails. does not reach the metamask, what could be the reason?
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.88.1">
<title>SMART CONTRACT</title>
<link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/headers/">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="headerss.css">
<link rel="stylesheet" href="style.css">
<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>
<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
<div class="tradingview-widget-container__widget"></div>
<script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-ticker-tape.js" async>
{
"symbols": [
{
"description": "BINANCE COIN",
"proName": "BINANCE:BNBUSDT"
},
{
"description": "BITCOIN",
"proName": "BINANCE:BTCUSDT"
},
{
"description": "ETHEREUM",
"proName": "BINANCE:ETHUSDT"
},
{
"description": "NEAR",
"proName": "BINANCE:NEARUSDT"
},
{
"description": "TETHER",
"proName": "BINANCEUS:USDTUSD"
},
{
"description": "MATIC",
"proName": "BINANCE:MATICUSDT"
},
{
"description": "AVALANCHE",
"proName": "BINANCE:AVAXUSDT"
},
{
"description": "CARDANO",
"proName": "BINANCE:ADAUSDT"
}
],
"showSymbolLogo": true,
"colorTheme": "light",
"isTransparent": true,
"displayMode": "adaptive",
"locale": "en"
}
</script>
</div>
<!-- TradingView Widget END -->
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-patch-check-fill"
viewBox="0 0 16 16">
<symbol id="bi-patch-check-fill" viewBox="0 0 18 18">
<title>Smart Contract</title>
<path fill-rule="evenodd" clip-rule="evenodd" fill="dodgerblue"
d="M10.067.87a2.89 2.89 0 0 0-4.134 0l-.622.638-.89-.011a2.89 2.89 0 0 0-2.924 2.924l.01.89-.636.622a2.89 2.89 0 0 0 0 4.134l.637.622-.011.89a2.89 2.89 0 0 0 2.924 2.924l.89-.01.622.636a2.89 2.89 0 0 0 4.134 0l.622-.637.89.011a2.89 2.89 0 0 0 2.924-2.924l-.01-.89.636-.622a2.89 2.89 0 0 0 0-4.134l-.637-.622.011-.89a2.89 2.89 0 0 0-2.924-2.924l-.89.01-.622-.636zm.287 5.984-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 1 1 .708-.708L7 8.793l2.646-2.647a.5.5 0 0 1 .708.708z" />
</path>
</symbol>
</svg>
<main>
<h1 class="visually-hidden">Headers examples</h1>
<div class="container">
<header class="d-flex flex-wrap justify-content-center py-3 mb-4 border-bottom">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">
<svg class="bi me-2" width="40" height="32">
<use xlink:href="#bi-patch-check-fill" />
</svg>
<span class="fs-4">Smart Contract</span>
</a>
<ul class="nav nav-pills">
<li onclick="login()" id="btn-login" class="nav-item"><a href="#" class="nav-link active" aria-current="page">Join to Wallet</a></li>
<li class="nav-item"><a href="#" class="nav-link">Deposit</a></li>
<li class="nav-item"><a href="#" class="nav-link">Withdraw</a></li>
<li class="nav-item"><a href="#" class="nav-link">Info</a></li>
<li onclick="logout()" id="btn-logout" class="nav-item"><a href="#" class="nav-link">Disconnect</a></li>
</ul>
</header>
</div>
</main>
</body>
</html>
<main class="col-md-9 ms-sm-4 col-lg-10 px-md-4">
</div>
<p>
<h2>Deposit</h2>
<div id="tableOfDeposit" class="table-responsive">
<h1 class="h6 mb-6 fw-normal">Send BNB and get 0.6% every day!</h1>
</p>
<p>
<div class="form-floating">
<input type="text" class="form-control" id="Amount-Payable" placeholder="Amount-Payable">
<label for="Amount-Payable">
<spann>*</spann>BNB Amount Payable (Min 0.1 BNB)
</label>
</div>
</p>
<p>
<div class="form-floating">
<input type="Upline-Address" class="form-control" id="Uplline-Address" placeholder="Upline-Address">
<label for="Upline-Address">
<spann>*</spann>Uplline Adress Ref Partners (0x0123456789...AbΡ)
</label>
</div>
</p>
<button id="transfer-native" class="w-100 btn btn-lg btn-primary" type="button" onclick="transferNative()">Send BNB and create a deposit</button>
</div>
<p>
<h2>Withdraw</h2>
<div id="tableOfWithdraw" class="table-responsive">
<h1 class="h6 mb-6 fw-normal">Withdraw interest in BNB every 24 hours!</h1>
</div>
</p>
<button id="btn-withdraw" class="w-100 btn btn-lg btn-primary" type="button" onclick="withdraw()">Withdraw interest in BNB</button>
</div>
<p>
<h2>Info</h2>
<div id="tableOfInfo" class="table-responsive">
<h1 class="h6 mb-6 fw-normal">Withdraw interest in BNB every 24 hours!</h1>
</p>
</div>
<p>
<h2>Referral</h2>
<div id="tableOfReferral" class="table-responsive">
<h1 class="h6 mb-6 fw-normal">Withdraw interest in BNB every 24 hours!</h1>
</div>
</p>
<h2>Leaderboard</h2>
<div id="tableOfLeaderboard" class="table-responsive">
<h1 class="h6 mb-6 fw-normal">Withdraw interest in BNB every 24 hours!</h1>
</div>
<p>
<h2>Transactoins</h2>
<div id="tableOfTransaction" class="table-responsive">
<h1 class="h6 mb-6 fw-normal">Withdraw interest in BNB every 24 hours!</h1>
</div>
</p>
</div>
</main>
<script src="main.js"></script>
<script type="text/javascript" src="ERC20Abi.js"></script>
</body>
</html>
Main
`console.log("Hello world");
//connect to Moralis server
const serverUrl = "https://1jjca2c1r4ab.usemoralis.com:2053/server";
const appId = "f21REKbxRDZtrz0D7O7zcVqx7GjVy7cbbYHOdxd8";
Moralis.start({ serverUrl, appId });
// ΠΠΏΠΎΠΏΠΊΠ° ΠΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ ΠΌΠ΅ΡΠ°ΠΌΠ°ΡΠΊ https://docs.moralis.io/moralis-dapp/users/web3-login/metamask
login = async () => {
const user = await Moralis.authenticate();
document.getElementById("btn-login").innerHTML = user.get("ethAddress");
};
const loginButton = document.getElementById("btn-login");
const loginButtonHTML = loginButton.cloneNode(true);
loginButtonHTML.onclick = login;
// Π€ΡΠ½ΠΊΡΠΈΡ ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ Π°Π΄ΡΠ΅ΡΠ° ΠΊΠΎΡΠ΅Π»ΡΠΊΠ° Ρ ΡΠ·Π΅ΡΠ° ΠΏΠΎΡΠ»Π΅ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ
// async function login() {
// const user = await Moralis.authenticate();
// document.getElementById("login").innerhtml = user.get("ethAddress");
// }
// if (document.querySelector("#btn-login") != null) {
// document.querySelector("#btn-login").onclick = login;
// }
// ΠΠ½ΠΎΠΏΠΊΠ° ΠΡΠΊΠ»ΡΡΠ΅Π½ΠΈΡ ΠΌΠ΅ΡΠ°ΠΌΠ°ΡΠΊ
logout = async () => {
const result = await Moralis.User.logOut();
if (result) {
document.getElementById("btn-login").innerHTML = "";
document.getElementById("btn-login").appendChild(loginButtonHTML);
}
};
// if (document.querySelector("#btn-logout") != null) {
// document.querySelector("#btn-logout").onclick = logout;
// }
// Π€ΠΎΡΠΌΠ° ΠΎΡΠΏΡΠ°Π²ΠΊΠΈ Π΄Π°Π½Π½ΡΡ
Π² ΡΠΌΠ°ΡΡ ΠΊΠΎΠ½ΡΡΠ°ΠΊΡ
async function transferNative() {
const amount = document.getElementById("Amount-Payable").value;
const address = document.getElementById("Uplline-Address").value;
// sending 0.1 tokens with 18 decimals to smart contract 0xEc08f00FE90fcf5e205b45Ac067f22C6F0e0854B
const options = {
type: "erc20",
amount: Moralis.Units.Token(amount, "18"),
receiver: "0x2075F1faf71eEEA9D2a649bFbbDDc79543d9fF9F",
contractAddress: "0xEc08f00FE90fcf5e205b45Ac067f22C6F0e0854B",
};
let result = await Moralis.transfer(options);
}
// document.getElementById("#transfer-native").onclick = logout;
async function withdraw() {
const sendOptions = {
contractAddress: "0xEc08f00FE90fcf5e205b45Ac067f22C6F0e0854B",
functionName: "withdraw",
abi: abi,
};
const transaction = await Moralis.executeFunction(sendOptions);
console.log(transaction.hash);
// --> "0x39af55979f5b690fdce14eb23f91dfb0357cb1a27f387656e197636e597b5b7c"
// Wait until the transaction is confirmed
await transaction.wait();
console.log("withdraw done");
}
`