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

fix(contract): rm IntoFuture for CallBuilder #1945

Merged
merged 1 commit into from
Jan 24, 2025
Merged

Conversation

yash-atreya
Copy link
Member

Motivation

Contract calls like contract.balanceOf cannot be directly awaited despite the IntoFuture impl as it requires Self: 'static. Ref: rust-lang/rust#63063.

Awaiting calls results in an ambiguous error for users. See https://t.me/ethers_rs/43016.

let bal = contract.balanceOf(addr).await.unwrap()
// Error: argument requires that borrow lasts for `'static`

The appropriate way to call a contract is:

let bal = contract.balanceOf(addr).call().await.unwrap();

The above error doesn't suggest this.

Solution

Remove the IntoFuture impl for CallBuilder.

Users now have to use .call(). Moreover, using .await results in a slightly better error: CallBuilder is not a future.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@mattsse
Copy link
Member

mattsse commented Jan 24, 2025

what does this type borrow, do we have an example here?

@DaniPopes
Copy link
Member

DaniPopes commented Jan 24, 2025

call() takes &self

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me have one last look to see if i can make this work

@mattsse
Copy link
Member

mattsse commented Jan 24, 2025

ngl the lifetimes of the ethcall type are a bit confusing

@DaniPopes
Copy link
Member

It could be fixable with implementing for &CallBuilder but then .await does not auto borrow so you would have to do (&callbuilder).await

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, let's open an issue to track re-adding this impl

@mattsse mattsse merged commit c475390 into main Jan 24, 2025
26 checks passed
@mattsse mattsse deleted the yash/rm-fut-call-builder branch January 24, 2025 10:04
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.

3 participants