Struct ethers_contract::ContractFactory
source · [−]pub struct ContractFactory<M> { /* private fields */ }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.bytecode().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
sourceimpl<M: Middleware> ContractFactory<M>
impl<M: Middleware> ContractFactory<M>
sourcepub fn new(abi: Abi, bytecode: Bytes, client: Arc<M>) -> Self
pub fn new(abi: Abi, bytecode: Bytes, client: Arc<M>) -> Self
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_tokens(
self,
params: Vec<Token>
) -> Result<Deployer<M>, ContractError<M>>
sourcepub fn deploy<T: Tokenize>(
self,
constructor_args: T
) -> Result<Deployer<M>, ContractError<M>>
pub fn deploy<T: Tokenize>(
self,
constructor_args: T
) -> Result<Deployer<M>, ContractError<M>>
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
sourceimpl<M> Clone for ContractFactory<M>
impl<M> Clone for ContractFactory<M>
Auto Trait Implementations
impl<M> RefUnwindSafe for ContractFactory<M> where
M: RefUnwindSafe,
impl<M> Send for ContractFactory<M> where
M: Send + Sync,
impl<M> Sync for ContractFactory<M> where
M: Send + Sync,
impl<M> Unpin for ContractFactory<M>
impl<M> UnwindSafe for ContractFactory<M> where
M: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more