ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.98k stars 1.86k forks source link

Ethers 6 documentation is lacking Events / Logs in Migrating from v5 #4443

Open oehm-smith opened 1 year ago

oehm-smith commented 1 year ago

Suggestion

Events seems to now be logs, however it is not the same API and there is no information in the migration guide for this.

I'm just learning Solidity through Alchemy Uni. They seem to use Ethers5 and part of my learning process is upgrading to Ethers6. This one has me baffled:

describe("after approval from the arbiter", () => {
        let before;
        let receipt;
        beforeEach(async () => {
            before = await ethers.provider.getBalance(accounts.beneficiary.address);
            let tx = await contract.connect(accounts.arbiter.signer).approve();
            receipt = await tx.wait();
        });

        it("should emit the event", async () => {
            const event = receipt.events.find(x => x.event === "Approved");
            assert(event, "Expect an Approved event to be emitted!");
            const amount = event.args[0];
            assert.equal(
                amount.toString(), deposit.toString(), 
                "Expected the deposit amount to be emitted in the Approved event!"
            );
        });

        ...

I can use receipt.logs to get an array, however there no longer seems to be an event (eg. Approved) and all there is is the topics. I guess I can decode them but surely there exists an easier way?

Could the migration documentation be updated to include this.

MehmeDBDuran commented 4 months ago

Well... Op's issue is months old and I am here struggling with the same issue here. Almost the same "find" approach failing and there is no easy way to filter events by name (or is there?).