How to get event info with useWeb3ExecuteFunction in react

function addBank (address bankAddress,
string memory bankName,
uint256 pincode,
string memory country,
string memory state,
string memory ifscCode,
string memory region) public{
require(msg.sender==admin,“Error:: only owner of the smart contract can Add BANK”);
if(admin==msg.sender){

        bank memory b;
        if(bankMap[bankAddress].exist){
            revert("ERROR::Bank Already exist!!!");
        }
        b.bankAddress=bankAddress;
        b.bankName=bankName;
        b.pincode=pincode;
        b.state=state;
        b.region=region;
        b.ifscCode=ifscCode;
        b.exist=true;
        b.kyc_count=0;
        b.upvotes=0;
       
        bankMap[bankAddress]=b;
        bankLength++;
        emit bankCreated(
            b.bankAddress, 
            b.bankName, 
            b.pincode, 
            b.country, 
            b.state, 
            b.ifscCode,
            b.region,
            b.role,
            b.kyc_count,
            b.upvotes
        );
    }
    else{
        revert("ERROR:: you cannot add bank!!!");
    }
}

event bankCreated(
address bankAddress,
string bankName,
uint256 pincode,
string country,
string state,
string ifscCode,
string region,
uint role,
uint256 kyc_count,
uint256 upvotes
);

i have created an event called bankcreated and i am emitting this event when i am calling function callled Addbank from my react frontend;

but i can’t see the results of it in my frontend…how can i use moralis useWeb3ExecuteFunction() for doing it…i want data direclty from smart contract to my frontend ,i don’t want to save it in moralis database

in the results for useWeb3ExecuteFunction, you should also get the event info, maybe you need to use await, onSuccess, I don’t know the exact syntax for react

const addBank= async(accountDetails)=>{
const web3 = await Moralis.enableWeb3();
console.log(“I was callled”);
console.log(“acc::”,accountDetails)
let options={
contractAddress:“0xc98F4Fe06FF5C2B67b3ef759Ddfa7eC7D8118A35”,
functionName:“addBank”,
abi:[
{
“inputs”: [
{
“internalType”: “address”,
“name”: “bankAddress”,
“type”: “address”
},
{
“internalType”: “string”,
“name”: “bankName”,
“type”: “string”
},
{
“internalType”: “uint256”,
“name”: “pincode”,
“type”: “uint256”
},
{
“internalType”: “string”,
“name”: “country”,
“type”: “string”
},
{
“internalType”: “string”,
“name”: “state”,
“type”: “string”
},
{
“internalType”: “string”,
“name”: “ifscCode”,
“type”: “string”
},
{
“internalType”: “string”,
“name”: “region”,
“type”: “string”
}
],
“name”: “addBank”,
“outputs”: [],
“stateMutability”: “nonpayable”,
“type”: “function”
},
],
params:{
bankAddress:accountDetails.ethAddress,
bankName:accountDetails.name,
pincode:accountDetails.pincode,
country:accountDetails.country,
state:accountDetails.state,
ifscCode:accountDetails.ifscCode,
region:accountDetails.region

        }
    }
    await contractProcessor.fetch({
        params:options,
        onSuccess:(succ)=>{
            console.log("SUCCESSSSS!!!!!",succ)
            setSuccess(true);
            setErr('');
        },
        onError:(error)=>{
            console.log("ERRRRORLLL",error)
            setSuccess(false)
            setErr(error.data.message);

        }
    })

}

This is my react code, but i can’t see the event output in console the onscuccess just returns the recipet

you can see here how to post code on forum:

it would be easier to read after that

await contractProcessor.fetch({
  params: options,
  onSuccess: (succ) => {
    console.log("SUCCESSSSS!!!!!", succ); // Logged once the transaction is submitted

    return succ.wait().then((tx) => {
      setSuccess(true);
      setErr("");
      console.log(tx); // Logged once the transaction is confirmed
    });
  },
  onError: (error) => {
    console.log("ERRRRORLLL", error);
    setSuccess(false);
    setErr(error.data.message);
  },
}); 

Can you try this way.

1 Like