[−][src]Struct ethers_contract::ContractFactory
To deploy a contract to the Ethereum network, a ContractFactory
can be
created which manages the Contract bytecode and Application Binary Interface
(ABI), usually generated from the Solidity compiler.
Once the factory's deployment transaction is mined with sufficient confirmations,
the Contract
object is returned.
Example
use ethers::{ utils::Solc, contract::ContractFactory, providers::{Provider, Http}, signers::Wallet }; use std::convert::TryFrom; // first we'll compile the contract (you can alternatively compile it yourself // and pass the ABI/Bytecode let compiled = Solc::new("./tests/contract.sol").build().unwrap(); let contract = compiled .get("SimpleStorage") .expect("could not find contract"); // connect to the network let provider = Provider::<Http>::try_from("http://localhost:8545").unwrap(); let client = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc" .parse::<Wallet>()?.connect(provider); // create a factory which will be used to deploy instances of the contract let factory = ContractFactory::new(contract.abi.clone(), contract.bytecode.clone(), &client); // The deployer created by the `deploy` call exposes a builder which gets consumed // by the async `send` call let contract = factory .deploy("initial value".to_string())? .confirmations(0usize) .send() .await?; println!("{}", contract.address());
Implementations
impl<'a, P, S> ContractFactory<'a, P, S> where
S: Signer,
P: JsonRpcClient,
[src]
S: Signer,
P: JsonRpcClient,
pub fn new(abi: Abi, bytecode: Bytes, client: &'a Client<P, S>) -> Self
[src]
Creates a factory for deployment of the Contract with bytecode, and the constructor defined in the abi. The client will be used to send any deployment transaction.
pub fn deploy<T: Tokenize>(
self,
constructor_args: T
) -> Result<Deployer<'a, P, S>, ContractError>
[src]
self,
constructor_args: T
) -> Result<Deployer<'a, P, S>, ContractError>
Constructs the deployment transaction based on the provided constructor
arguments and returns a Deployer
instance. You must call send()
in order
to actually deploy the contract.
Notes:
- If there are no constructor arguments, you should pass
()
as the argument. - The default poll duration is 7 seconds.
- The default number of confirmations is 1 block.
Trait Implementations
impl<'a, P: Clone, S: Clone> Clone for ContractFactory<'a, P, S>
[src]
fn clone(&self) -> ContractFactory<'a, P, S>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a, P: Debug, S: Debug> Debug for ContractFactory<'a, P, S>
[src]
Auto Trait Implementations
impl<'a, P, S> RefUnwindSafe for ContractFactory<'a, P, S> where
P: RefUnwindSafe,
S: RefUnwindSafe,
P: RefUnwindSafe,
S: RefUnwindSafe,
impl<'a, P, S> Send for ContractFactory<'a, P, S> where
P: Sync,
S: Sync,
P: Sync,
S: Sync,
impl<'a, P, S> Sync for ContractFactory<'a, P, S> where
P: Sync,
S: Sync,
P: Sync,
S: Sync,
impl<'a, P, S> Unpin for ContractFactory<'a, P, S>
impl<'a, P, S> UnwindSafe for ContractFactory<'a, P, S> where
P: RefUnwindSafe,
S: RefUnwindSafe,
P: RefUnwindSafe,
S: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,