Need to listen events emitted from contract using React moralis

104 views Asked by At

By following the tutorial from Patrick, I have created a smart cotract in solidity for picking up a winner for a lottery system. So I have added an event called "WinnerPicked", which will be emitted, whenever a winner is picked.

Now, I want to catch this emitted event, in the react frontend. So, is there any way to catch the emmited even in react-moralis ?

I don't find anything for this, in docs. Someone please help.

I cannot provide the complete code here, since it is scrambled across multiple files. But the below pseudo code is helpful.

Raffle.sol

event WinnerPicked(recentWinner)

function getRandomWinnerFromVRF(randomWinner){
    let recentWinner = randomWinner
    emit WinnerPicked(recentWinner)

}

Also I am using react moralis to capture functions inside the contract like the below.

    const { runContractFunction: getEntranceFee } = useWeb3Contract({
        abi: abi,
        contractAddress: raffleAddress,
        functionName: "getEntranceFee",
        params: {},
    });


0

There are 0 answers