Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ethers from dependencies to devDependencies #140

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

Gideonnn
Copy link
Contributor

Context

This project has dependencies to both ethers and viem. We want to use only viem here, like in other projects.

Changes proposed in this pull request

The only change this pr contains right now is moving the ethers dependency from dependencies to devDependencies, since it is only used to fetch the products, and in test files.

This is not the proper fix though, removing the ethers import in build-products.js (and later in the test files) was the original goal, but that did not seemed to work for some reason I could not figure out.

Notes

I have tried to fetch the products with viem instead of ethers, but I could not get any other output than an empty array. I would like to document here the things I tried for future reference.

First I replaced the contract creation in the buildProducts function. I outcommented the current code:

const provider = new ethers.providers.JsonRpcProvider(PROVIDER_URL);
const coverEthers = new ethers.Contract(addresses.Cover, Cover, provider);

And replaced it with:

const publicClient = createPublicClient({
  chain: mainnet,
  transport: http(PROVIDER_URL),
});

const coverViem = getContract({
  address: addresses.Cover,
  abi: Cover,
  client: publicClient,
});

Then I tried to fetch the events in fetchProductTypes by trying out a few ways:

I tried the createContractEventFilter function (docs). I tried playing with the fromBlock/toBlock params (took the values from the frontend) but that did not work. I also tried using the getAbiItem function instead of supplying the abi like this, also with no result.

const filter = await publicClient.createContractEventFilter({
  address: coverViem.address,
  abi: coverViem.abi,
  eventName: 'ProductTypeSet',
  // fromBlock: BigInt(7700000),
  // toBlock: BigInt(16791580),
});
const events = await publicClient.getFilterLogs({ filter });
console.log('events:', events); // events: []

I tried the getContractsEvents function, with the same result as above:

const events = await publicClient.getContractEvents({
  abi: Cover,
  eventName: 'ProductTypeSet',
  fromBlock: BigInt(7700000),
  toBlock: BigInt(16791580),
});
console.log('events:', events); // events: []

The getEvents function did also not give me any result:

const events = await coverViem.getEvents.ProductTypeSet();
console.log('events:', events); // events: []

All this while the ethers code returns the correct events without issues

@roxdanila roxdanila merged commit 4d03c5b into master Jun 4, 2024
1 of 2 checks passed
@roxdanila roxdanila deleted the feat/115-ethers-cleanup branch June 4, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants