Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

ethers-contract: ContractFactory, set deployer to public so defaults may be overrided. #1155

Closed
inconspicuous99 opened this issue Apr 19, 2022 · 1 comment

Comments

@inconspicuous99
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Using abigen!() releases a contract whose deploy method returns ContractDeployer. When deploying ownable contracts you want to set who you're sending it from, especially if your provider has multiple accounts.

Describe the solution you'd like
Set ContractDeployer's deployer field to public.

pub struct ContractDeployer<M, C> {
    /// the actual deployer, exposed for overriding the defaults
    pub deployer: Deployer<M>, // change this


    /// marker for the `Contract` type to create afterwards
    ///
    /// this type will be used to construct it via `From::from(Contract)`
    _contract: PhantomData<C>,
}
  abigen!(OwnableContract, "$CARGO_MANIFEST_DIR/artifacts/OwnableContract.sol/OwnableContract.json");

  let deployer = OwnableContract::deploy(
    Arc::new(provider.clone()),
    "".to_string(),
  ).expect("Failed to create deployer");
  
  let desired_from_address = provider.getAccounts().await?[0];
  deployer.deployer.tx.from = desired_from_address;
  
  deployer.send().await.expect("failed to send");

Describe alternatives you've considered
You could create a SingleSigner middleware and deploy it with it, but you could also expose deployer as public and privatize Deployer's private fields (already being done) and modify the public transaction. (and it's already public for situations like these, was just an oversight not to set ContractDeployer's deployer to public).

Additional context
image

@inconspicuous99
Copy link
Contributor Author

solved by #1156

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant