async function execute(event) {
    const func = abiFuncs.find((func) => func.name === event.target.name);
    const inputValues = [];
    func.inputs.forEach((input) => {
      inputValues.push(input.value);
    });

    if (typeof window.ethereum !== "undefined") {
      try {
        await requestAccount();
        const provider = new ethers.providers.Web3Provider(window.ethereum);

        func.response = { type: "loading" };
        setAbiFuncs([...abiFuncs]);

        const contract = new ethers.Contract(
          contractAddress,
          abiFuncs,
          provider.getSigner()
        );

        const res = await contract[func.name].apply(this, inputValues);

        if (typeof res === "object") {
          if (res._hex) {
            func.response = { type: "text", value: parseInt(res._hex, 16) };
          } else if (res.hash) {
            func.response = { type: "hash", value: res.hash };
          } else {
            func.response = {};
            setAlert({
              type: "error",
              msg: "An error has occurred.",
            });
          }
        } else {
          func.response = { type: "text", value: res };
        }
      } catch (err) {
        func.response = {};

        if (err.code === 4001) {
          setAlert({ type: "info", msg: "Operation canceled by user." });
        } else if (err.message) {
          setAlert({ type: "error", msg: getErrorMessage(err.message) });
        } else {
          setAlert({
            type: "error",
            msg: "An error has occurred.",
          });
        }
      }
    } else {
      func.response = {};
      setAlert({ type: "error", msg: "Connect to your Metamask extension." });
    }

    setAbiFuncs([...abiFuncs]);
  }
/**
   * Executes one function of the contract
   */
Executes one function of the contract
Executes one function of the contract
async function execute(event) {
    const func = abiFuncs.find((func) => func.name === event.target.name);
    const inputValues = [];
    func.inputs.forEach((input) => {
      inputValues.push(input.value);
    });
    if (typeof window.ethereum !== "undefined") {
      try {
        await requestAccount();
        const provider = new ethers.providers.Web3Provider(window.ethereum);
        func.response = { type: "loading" };
        setAbiFuncs([...abiFuncs]);
        const contract = new ethers.Contract(
          contractAddress,
          abiFuncs,
          provider.getSigner()
        );
        const res = await contract[func.name].apply(this, inputValues);
        if (typeof res === "object") {
          if (res._hex) {
            func.response = { type: "text", value: parseInt(res._hex, 16) };
          } else if (res.hash) {
            func.response = { type: "hash", value: res.hash };
          } else {
            func.response = {};
            setAlert({
              type: "error",
              msg: "An error has occurred.",
            });
          }
        } else {
          func.response = { type: "text", value: res };
        }
      } catch (err) {
        func.response = {};
        if (err.code === 4001) {
          setAlert({ type: "info", msg: "Operation canceled by user." });
        } else if (err.message) {
          setAlert({ type: "error", msg: getErrorMessage(err.message) });
        } else {
          setAlert({
            type: "error",
            msg: "An error has occurred.",
          });
        }
      }
    } else {
      func.response = {};
      setAlert({ type: "error", msg: "Connect to your Metamask extension." });
    }
    setAbiFuncs([...abiFuncs]);
  }
async function execute ( event ) { const func = abiFuncs . find ( ( func ) => func . name === event . target . name ) ; const inputValues = [ ] ; func . inputs . forEach ( ( input ) => { inputValues . push ( input . value ) ; } ) ; if ( typeof window . ethereum !== "undefined" ) { try { await requestAccount ( ) ; const provider = new ethers . providers . Web3Provider ( window . ethereum ) ; func . response = { type : "loading" } ; setAbiFuncs ( [ ... abiFuncs ] ) ; const contract = new ethers . Contract ( contractAddress , abiFuncs , provider . getSigner ( ) ) ; const res = await contract [ func . name ] . apply ( this , inputValues ) ; if ( typeof res === "object" ) { if ( res . _hex ) { func . response = { type : "text" , value : parseInt ( res . _hex , 16 ) } ; } else if ( res . hash ) { func . response = { type : "hash" , value : res . hash } ; } else { func . response = { } ; setAlert ( { type : "error" , msg : "An error has occurred." , } ) ; } } else { func . response = { type : "text" , value : res } ; } } catch ( err ) { func . response = { } ; if ( err . code === 4001 ) { setAlert ( { type : "info" , msg : "Operation canceled by user." } ) ; } else if ( err . message ) { setAlert ( { type : "error" , msg : getErrorMessage ( err . message ) } ) ; } else { setAlert ( { type : "error" , msg : "An error has occurred." , } ) ; } } } else { func . response = { } ; setAlert ( { type : "error" , msg : "Connect to your Metamask extension." } ) ; } setAbiFuncs ( [ ... abiFuncs ] ) ; }
Executes one function of the contract
Executes one function of the contract