alloy-rs / alloy

Transports, Middleware, and Networks for the Alloy project
https://alloy.rs
Apache License 2.0
646 stars 231 forks source link

[Feature] Infer `EthereumSigner` automatically in the signer layer of the `ProviderBuilder` #810

Open zerosnacks opened 5 months ago

zerosnacks commented 5 months ago

Component

provider, pubsub, signers

Describe the feature you would like

Given

let signer = LocalWallet::random();

We currently require the signer to be cast into EthereumSigner::from(signer) when using the signer layer in the ProviderBuilder as follows:

let provider = ProviderBuilder::new()
    .with_recommended_fillers()
    .signer(EthereumSigner::from(signer))
    .on_http(rpc_url);

The proposed API:

let provider = ProviderBuilder::new()
    .with_recommended_fillers()
    .signer(signer)
    .on_http(rpc_url);

Additional context

No response

prestwich commented 5 months ago

change would need to consider #638 and #535 #575 (edited to fix link)

prestwich commented 5 months ago

sorry that should be #575

gakonst commented 5 months ago

This seems simple but under the hood has a bunch of extra work needed to allow calling .signer(...) multiple times which would collect credentials in 1 EthereumSigner. Right now if you call .signer(...) multiple times it is not great behavior bc it might create a new SignerFiller or override the existing signer.

This will get bundled with the credential/wallet rewrite, might need .signer(...) -> SignerBuilder