I'm currently struggling on obtaining logs of the events emitted from my smart contract on the frontend dapp. The smart contract code itself should work just fine as it emits the event perfectly fine on Substrate UI. It's just the frontend dapp that I'm struggling to do so. This is what I did on my smart contract:

//snippets of code
pub struct GameResult {
  win: bool
pub fn playgame(&mut self, amount: Balance) -> Result<(), BetError> {

I don't really know the syntax to log events on the frontend side but this is my current code for the frontend:

     { signer: props.signer },
     ({events=[], status}) => {
        if (status.isFinalized) {
            props.api.query.system.events((events) => {
                events.forEach(({ event }) => {
                  if (
                      event.section === "GameContract" &&
                      event.method === "GameResult"
                      ) {
                      console.log("GameResult", event.toJSON());

With the above code, when I do signAndSend, got event arrays and the GameResult events did not get logged. What am I doing wrong? I think my syntax is wrong. Let me know thanks!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.