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

feat(contract): interact using ContractInstance #109

Merged
merged 10 commits into from
Jul 3, 2024

Conversation

yash-atreya
Copy link
Member

Motivation

Show how to interact with an already deployed contract.

Solution

Use the ContractInstance interface.

PR Checklist

  • Added Documentation
  • Breaking changes

examples/contracts/examples/contract_instance.rs Outdated Show resolved Hide resolved
let init_val = counter_instance.function("number", &[])?.call().await?;

// Get the Uint value from the result
let init_val = init_val.first().unwrap().as_uint().unwrap().0;
Copy link
Member

Choose a reason for hiding this comment

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

Honestly this is not a great example because we know ahead of time the functions we're going to call, and the return types of the functions, which is where sol! should be used.

Copy link
Member Author

@yash-atreya yash-atreya Jun 17, 2024

Choose a reason for hiding this comment

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

I think this example just serves an introduction ContractInstance API interface. I can add another example where we call the function by the selector and match DynSolValue on the return.

Copy link
Member Author

Choose a reason for hiding this comment

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

And anyways, we still require an abi so don't we always have some idea of which function we're trying to call.

Copy link
Member

Choose a reason for hiding this comment

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

No because the ABI is supposed to be dynamic, think Foundry that executes fuzz functions with arbitrary parameters

Cargo.toml Outdated Show resolved Hide resolved
@zerosnacks
Copy link
Member

zerosnacks commented Jun 17, 2024

Not entirely clear why we need this example, I think we should steer users to using the sol! macro, even if that means manually constructing an interface (see: https://github.com/alloy-rs/examples/blob/main/examples/transactions/examples/gas_price_usd.rs)

Could we instead enhance https://github.com/alloy-rs/examples/blob/main/examples/contracts/examples/interact_with_abi.rs?

Or alternatively - implement it to resolve #52?

@gakonst
Copy link
Member

gakonst commented Jun 17, 2024

I think we want 1 example using Dyn ABI for both normal structs and tuples, given CLIs which don't know the ABI ahead of time can't leverage the sol macro?

@yash-atreya yash-atreya merged commit 6aaf31d into main Jul 3, 2024
4 checks passed
@zerosnacks zerosnacks deleted the yash/contract_instance branch July 3, 2024 08:15
zerosnacks added a commit that referenced this pull request Jul 3, 2024
* update linting rules

* minor tweaks, restructuring of contract_instance

* avoid unwrap()
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.

4 participants