1

I am using Ganache as my test network and I am running React as my front end.

My ComponentWillMount() is as follows:

componentWillMount() {
   getWeb3
    .then(results => {
      this.setState({
        web3: results.web3
      }, () => {
        let filter = this.state.web3.eth.filter('latest');
        filter.watch(function(error, result) {
          console.log(error);
          console.log('Filter', result);
        });
      })
    })
    .catch(() => {
      console.log('Error finding web3.')
    })
  }

I use a button to call issue() function:

issue() {
    const issuance = contract(IssuanceContract)
    issuance.setProvider(this.state.web3.currentProvider)

    var issuanceInstance

    this.state.web3.eth.getAccounts((error, accounts) => {

      issuance.deployed().then((instance) => {
        issuanceInstance = instance

        return issuanceInstance.Issue('Test', {from: accounts[0]})
      }).then((receipt) => {
        console.log('Transaction receipt', receipt);
      })
    })
  }

Upon searching a lot in stackexchange, I tried to add Events into solidity code:

event EventIssue(uint itemId)

And I fire the event from the Issue function:

EventIssue(myItemId);

I get the output of the receipt, but no output for filter (neither for error). In Metamask I can see that the transaction is pending, and then it gets mined, and I was assuming that when it gets mined I see the output using the filter. Am I missing something?

Update 23/02/2018: This doesn't work either:

issuanceInstance.EventIssue('latest').watch((error, result) => {
   console.log(result);
});

Your Answer

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

Browse other questions tagged or ask your own question.