alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
758 stars 131 forks source link

[Documentation] Add documentation about `sol!` and `abi_encode` #678

Closed tcoratger closed 2 months ago

tcoratger commented 2 months ago

Component

sol-types

Describe the feature you would like

In order to obtain the calldata for a function call like:

sol! {
    #[sol(rpc)]
    contract ERC20Contract {
        function balanceOf(address account) external view returns (uint256);
        function allowance(address owner, address spender) external view returns (uint256);
    }
}

let calldata = ERC20Contract::balanceOfCall { account: evm_address }.abi_encode();

It wasn't clear to me that we can do that this way as all the sol! macro examples that can be found here: https://github.com/alloy-rs/alloy/blob/main/crates/contract/README.md require a Provider.

I had to search for a while before I figured out that I could simply use the strategy with abi_encode to achieve the same goal.

As a result, maybe we should add more documentation in the sol-types README or in the alloy-contract README (so I don't know if it's a cross-repo issue) to inform the user of the possibility of carrying out these use cases (and maybe others) without needing to use the provider flow.

Additional context

No response

DaniPopes commented 2 months ago

We have plenty of documentation on the macro itself through doccomments and in the examples repo (rendered in the book).