Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

getPastEvents is not a function #81

Closed
johnmpotter opened this issue Jun 11, 2018 · 4 comments
Closed

getPastEvents is not a function #81

johnmpotter opened this issue Jun 11, 2018 · 4 comments

Comments

@johnmpotter
Copy link
Contributor

johnmpotter commented Jun 11, 2018

What's the best way to access past events for a given contract event? If I call the getPastEvents method on a specific contract from the drizzle context, it throws an error that it's not a function.

TypeError: this.drizzle.contracts.Contract.getPastEvents is not a function

Or maybe there's a "Drizzle way" for accessing past events that i'm not aware of. Thank you!

@johnmpotter
Copy link
Contributor Author

My short-term solution was to fork drizzle and add the raw web3Contract instance to the drizzle contract and just use that when calling getPastEvents.

johnmpotter@0ff0995

I believe the reason the function isn't being added to the DrizzleContract instance has to do with Object.assign, but i'm not sure what the solution would be. I'll leave this open incase someone smarter than myself has the answer.

@kartojal
Copy link

I'm using drizzle and drizzle-react packages, and a way to use getPastEvents is to use the "web3" instance that comes with Drizzle, injecting the contract ABI and the deployed contract address to new web3.eth.Contract(abi, address, options), creating a raw Web3 contract instance, with all the web3 methods.

Some pseudocode example, can be wrapped into a function for reusing it:

const web3 = drizzle.web3;
const yourContract = drizzle.contracts.YourContract;
const yourContractWeb3 = new web3.eth.Contract(yourContract.abi, yourContract.address);
const pastEvents = await yourContractWeb3.getPastEvents(
  'eventName or allEvents',
  {
     fromBlock: 0,
     toBlock: 'latest'
  }
);

Could try to recreate a Fiddle for a real React example if you want 😄 Hope it works for you.

@soundyogi
Copy link
Contributor

soundyogi commented Dec 11, 2018

@kartojal answer is correct.

To access getPastEvents you need to access a web3 contract instance.

This Issue can be closed.

Related: trufflesuite/drizzle#149

@OnlyOneJMJQ
Copy link
Contributor

@johnmpotter @soundyogi is correct, @kartojal has the right idea.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants