[SOLVED]How to display event with Moralis?

Hi guys,

I’ve got several enums in solidity :

enum  WorkflowStatus {
        RegisteringVoters,
        ProposalsRegistrationStarted,
        ProposalsRegistrationEnded,
        VotingSessionStarted,
        VotingSessionEnded,
        VotesTallied
    }

In my front, I can click on a button which gonna call my function :

function startProposalsRegistering() external onlyOwner {
        require(workflowStatus == WorkflowStatus.RegisteringVoters, 'Registering proposals cant be started now');
        workflowStatus = WorkflowStatus.ProposalsRegistrationStarted;
        emit WorkflowStatusChange(WorkflowStatus.RegisteringVoters, WorkflowStatus.ProposalsRegistrationStarted);
    }

As you can see the workFlow change when I call this function. I would like to create an other button which gonna display the current workFlow, How can I do that with Moralis ?

You could listen to WorkflowStatusChange events on your contract and then update your button with this data.

You could also sync this event to your server and then subscribe to live queries.

Thanks for the link, I did it but still the same problem, I can’t get the actual event, I need to know if The status is RegisteringVoters, ProposalsRegistrationStarted etc… And in the database I don’t have the information so I can’t fetch it or I’m doing something wrong…

Finally I found how to do :partying_face:

 const {
        runContractFunction: voting,
        data: enterTxResponse,
        isLoading,
        isFetching,
    } = useWeb3Contract({
        abi: [
            {
                "inputs": [],
                "name": "workflowStatus",
                "outputs": [
                    {
                        "internalType": "enum Voting.WorkflowStatus",
                        "name": "",
                        "type": "uint8"
                    }
                ],
                "stateMutability": "view",
                "type": "function",
                "constant": true
            },
        ],
        contractAddress: 'contractAddress',
        functionName: "workflowStatus",
        params: {},
    })

<button
                onClick={async () =>
                    await voting({
                        onSuccess: (mess) => {
                            handleSuccess()
                            console.log(mess)
                        },
                        onError: (err) => {
                            console.log(err)
                        }
                    })
                }
            >
                Change status
            </button>

The console.log give me the right event :slight_smile:

Thanks guys for your time !

2 Likes