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

TransactionResponse type is wrong for wait #971

Closed
roderik opened this issue Jul 23, 2020 · 9 comments
Closed

TransactionResponse type is wrong for wait #971

roderik opened this issue Jul 23, 2020 · 9 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@roderik
Copy link

roderik commented Jul 23, 2020

    const block = await provider.getBlockWithTransactions(blockNumber);
    for (const transaction of block.transactions) {
       await transaction.wait(2)
    }

==> TypeError: transaction.wait is not a function

The type of TransationResponse is

export interface TransactionResponse extends Transaction {
    hash: string;
    blockNumber?: number;
    blockHash?: string;
    timestamp?: number;
    confirmations: number;
    from: string;
    raw?: string;
    wait: (confirmations?: number) => Promise<TransactionReceipt>;
}

I think it needs to be

export interface TransactionResponse extends Transaction {
    hash: string;
    blockNumber?: number;
    blockHash?: string;
    timestamp?: number;
    confirmations: number;
    from: string;
    raw?: string;
    wait?: (confirmations?: number) => Promise<TransactionReceipt>;
}

Or there need to be two types, one for getBlockWithTransactions and one for send

FYI, the use case is an indexer, so I need for each block the tx + receipt, the wait function with 1 or 0 as confirmations seemed like an elegant solution which would allow me not to pass around the provider.

@ricmoo
Copy link
Member

ricmoo commented Jul 23, 2020

You are probably right that I am not adding it in that case. Surprised TypeScript didn’t complain.

I will add a .wait to those objects. :)

@ricmoo ricmoo added investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels Jul 23, 2020
@zemse
Copy link
Collaborator

zemse commented Jul 24, 2020

Yesterday I was seeing a similar problem here:

providerETH.on(filter, async (log: ethers.Event) => {
  const tx = await event.getTransaction(); // this throws getTransaction is not a function
});

(await plasmaManagerInstanceETH.queryFilter(
  filter,
  6889863,
  'latest'
)).forEach(event => {
   const tx = await event.getTransaction(); // this works
});

@kimxilxyong
Copy link

I have "wait is not a function", i'm using it as per v5 migration examples. I really would like to use ethers instead of web3 because of the much cleaner architecture, but the need to get informed about the confirmed blocks is fundamental.
Has there been any progress? Should i try directly from the git?

const txResponse = await contract.Donation(donorName, { value: wei, });
const txReceipt = await txResponse.wait(24);      // this throws wait is not a function

@ricmoo
Copy link
Member

ricmoo commented Nov 25, 2020

@zemse I think you meant log instead of event in your callback (looks like you copy-pasted, but changed the signature ;))

providerETH.on(filter, async (log: ethers.Event) => {
  //               v----- here
  const tx = await event.getTransaction(); // this throws getTransaction is not a function
});

@ricmoo
Copy link
Member

ricmoo commented Nov 25, 2020

@kimxilxyong Can you add a console.log(txResponse) before the .wait line to see what was returned? If it was marked as "pure" or "view" in the ABI, it may be returning a value from the contract as a eth_call result rather than a send transaction... Just a thought. Let me know what the console.log returns. :)

@zemse
Copy link
Collaborator

zemse commented Nov 25, 2020

I think I made an error while copy pasting that time. Redoing it right now in browser and adding some screenshots

providerESN.on(dayswappersInstanceESN.filters.Authorised(), console.log)

After that I made a transaction that emits the above event. Then got this console log.

Screenshot 2020-11-25 at 1 37 53 PM

With queryfilter

Screenshot 2020-11-25 at 1 40 14 PM

The query filter one is definitely filled up with methods. Maybe my mistake is that the typing in async (log: ethers.Event) => { was an incorrect assumption. What type should I have put there? This is because I have developed a habit to continuously provide typescript enough info (prevent anys) so that it finds things I do wrong when I'm not in full senses.

Maybe we can do some typescript overloading if possible, so that whatever type is there (in case of pending, block and other ons), it comes implicit. Would you like if I try this and PR?

@roderik
Copy link
Author

roderik commented Dec 8, 2020

@zemse console.log at runtime does not check anything typescript related. If you trick typescript to believe the object is an Event, then that only affects the compiler. If you would do ('some string' as any) as Event your IDE/compiler would believe it was an Event, but console.log would still return 'some string'

@ricmoo ricmoo added bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels Jul 23, 2021
@ricmoo
Copy link
Member

ricmoo commented Jul 23, 2021

This has been fixed in 5.4.2. Try it out and let me know if you still have any problems.

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Jul 23, 2021
@ricmoo
Copy link
Member

ricmoo commented Aug 7, 2021

Closing now, but let me know if you continue to have issues.

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

4 participants