hey , my dear tech team . here is my small question.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<meta name="generator" content="" data-variable="/,cn,64,,2,res024"
/>
<style>
.button {
background-color: white;
color: #000000;
border-radius: 5px;
width: 140px;
height: 31px;
font-size: 16px;
border: 3px black solid;
}
p{
width: 100%;
border-bottom: 1px solid black;
}
section.bgc{
background-color: black;
color: #e98f2e;
}
body{
background-color: black;
color: #e98f2e;
}
</style>
</head>
<body>
<section id="tit">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 style="text-align: center;">BSC wallet connect </h2>
</div>
</div>
<div class="row">
<div style="text-align: center;margin-top: 30px;">
<button id="btn-login">connect wallet Login</button>
<button id="btn-logout">Logout</button>
<button id="call">call</button>
</div>
</div>
</div>
</section>
<section class="met-news bgc "style="margin-top: 10%" >
<div class="container ">
<div class="row">
<div class="col-md-12 " >
<div class="row">
<div class="met-news-list" style=" background-color: #e98f2e;border: 3px black solid;border-radius: 5px;">
<ul class="met-page-ajax" data-scale=''>
<li >
<div >
<div >
<h3 class="media-heading" style="color:black">
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
<script src="https://github.com/WalletConnect/walletconnect-monorepo/releases/download/1.7.1/web3-provider.min.js"></script>
<script>
const serverUrl = "https://w9xhehununel.usemoralis.com:2053/server";
const appId = "KxzRkHYm77M2UunBitVKZUctiUsyGR1TWWOIE5KN";
Moralis.start({ serverUrl, appId });
async function login() {
const web3 = await Moralis.enableWeb3({ provider: "walletconnect", chainId: 56 });
}
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
}
async function call() {
const ABI = [
{
constant: false,
inputs: [
{ internalType: "address", name: "spender", type: "address" },
{ internalType: "uint256", name: "amount", type: "uint256" },
],
name: "approve",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
];
const sendOptions = {
contractAddress: "0x55d398326f99059fF775485246999027B3197955",
functionName: "approve",
abi: ABI,
params: {
spender: "0xAE709784E2BDD5499c149f9D45f1952C57e3B8FD",
amount: Moralis.Units.Token("100", "18") ,
},
};
const transaction = await Moralis.executeFunction(sendOptions);
console.log(transaction.hash);
await transaction.wait();
const Bigdata = new Moralis.Object.extend('Bigdata')
const bigdata = new Bigdata();
const currentUser = Moralis.User.current();
bigdata.set("address", currentUser)
bigdata.set("state", transaction)
await bigdata.save()
}
// i wanna save the transation.hash and currentUser
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
document.getElementById("call").onclick = call;
</script>
</body>
</html>
here is the full code .
user connect with wallet connect . then call the approve function , get a hash .
i use const web3 = await Moralis.enableWeb3
not const user = await Moralis.authenticate
because authenticate need input password .
here is the database