Struct ethers::contract::ContractFactory[][src]

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

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_solc::Solc;
use ethers_contract::ContractFactory;
use ethers_providers::{Provider, Http};
use ethers_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::default().compile_source("./tests/contract.sol").unwrap();
let contract = compiled
    .get("./tests/contract.sol", "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.unwrap().clone(), contract.bin.unwrap().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

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more