[][src]Struct ethers_contract::ContractFactory

pub struct ContractFactory<M> { /* fields omitted */ }

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 client = Provider::<Http>::try_from("http://localhost:8545").unwrap();
let client = std::sync::Arc::new(client);

// 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<M: Middleware> ContractFactory<M>[src]

pub fn new(abi: Abi, bytecode: Bytes, client: Arc<M>) -> 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<M>, ContractError<M>>
[src]

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:

  1. If there are no constructor arguments, you should pass () as the argument.
  2. The default poll duration is 7 seconds.
  3. The default number of confirmations is 1 block.

Trait Implementations

impl<M: Clone> Clone for ContractFactory<M>[src]

impl<M: Debug> Debug for ContractFactory<M>[src]

Auto Trait Implementations

impl<M> RefUnwindSafe for ContractFactory<M> where
    M: RefUnwindSafe
[src]

impl<M> Send for ContractFactory<M> where
    M: Send + Sync
[src]

impl<M> Sync for ContractFactory<M> where
    M: Send + Sync
[src]

impl<M> Unpin for ContractFactory<M>[src]

impl<M> UnwindSafe for ContractFactory<M> where
    M: RefUnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,