0

I'm trying to get event data from the web3 API using events method. In my Vue app methods, I have a method, newDsoValue, that will watch for the events from the beginning and also for every newly fired event.

The method works perfectly fine only for the first time (when I change something in the block of code and save).

But if I refresh the browser tab, it does not load past event instead it will only load new fired events.

The method I'm using to load event data is used to get events from smart contracts written in solidity and deployed on Ethereum blockchain. The API is web3:1.0.0-beta.37 to get the event data.

I already tried mounted hook but no luck.

I also tried clearing browser cache, using another browser but no luck.

If I manually call this method, using a button click, then it also works fine.

I used to log some value in the console just before and after the API call inside the method, the value is perfectly logged in the console on every page refresh. Only the past data is not loaded.

Inside my method, I'm pushing data into an array. From debugging, I came to know that array is loaded with events only first time and if I refresh the page, the array becomes empty.

This is the method:

newDsoValue() {
      AssetLoggingContract.events
        .RejectSetValue({
          fromBlock: 0
        })
        .on("data", event => {
          this.testEvents.push(event);
          console.log(this.testEvents.length);
        })
        .on("error", console.error);
    },

I'm calling this method inside the created as:

created() {
    this.newDsoValue();
  }

I want to run this method on page load and every time I refresh the page it should load all the previous events and also the newly fired events. any help to achieve this? thanks

GitHub repo

0

After hours of research, I could figure out that it is not a problem with either block of code or Vue.js. The problem is with web3 API version and it seems a bug with web3:1.0.0-beta.37.

I updated to the latest version "web3": "^1.0.0-beta.55" and it fixed the issue.

References: can not receive the events #1260

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.