How to get approval for ERC20 and call the function with a argument in the smart contract with

This is the HTML file

    <!-- Moralis SDK code -->
    <script src="[email protected]/dist/web3.min.js"></script>
    <script src=""></script>
    <h1>Moralis Gas Stats</h1>

    <button id="btn-login">Connect</button>
    <button id="btn-approve">Approve</button>
    <!-- stats will go here -->
    <ul id="gas-stats"></ul>

    <script src="./index.js" type="module"></script>
    // connect to Moralis server // refresh stats //get stats on page load <

This is the javascript file

import { UsdtAddress, ERC20_ABI, contractAddresss, Abi } from "./constants";
const serverUrl = "";
const appId = "ktAaYbPzbDwsJTbd7MIxKXZBeU8zPfGrc3T8eFkm";
Moralis.start({ serverUrl, appId });

async function login() {
  let user = Moralis.User.current();
  if (!user) {
    user = await Moralis.authenticate();
  console.log("logged in user:", user);


// bind button click handlers
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-approve").onclick = getTranscation;
const USDtamount = 10;
const options = {
  chain: "0x4",
  contractAddress: UsdtAddres,
  functionName: "approve",
  abi: ERC20_ABI,
  params: { contractAddresss, USDtamount },
const contractOptions = {
  chain: "0x4",
  contractAddress: contractAddresss,
  functionName: "buy",
  abi: Abi,
  parans: { USDtamount },
async function getTranscation() {
  const tx = await Moralis.executeFunction(options);

  const tx2 = await Moralis.executeFunction(contractOptions);
  return tx2;

The metamask wasn’t popping for approval, is there anything required to change in the js file

According to the general standard, the parameters expected are _spender and _value such like

params: {
    _spender: "0x.....b2FF83e1Ae",
    _value: 1000000,

For executeFunction, you don’t need to pass a chain such like this, the chain is determined from the current network of the connected wallet

You can also wrap all your codes in the getTranscation function in a try...catch block and log for error incase there’s any error

Thank you for your response