Struct ethers_contract::DeploymentTxFactory
source · pub struct DeploymentTxFactory<B, M> { /* private fields */ }
Available on crate feature
providers
only.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_contract::ContractFactory;
use ethers_core::types::Bytes;
use ethers_providers::{Provider, Http};
// get the contract ABI and bytecode
let abi = Default::default();
let bytecode = Bytes::from_static(b"...");
// 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(abi, bytecode, 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§
source§impl<B, M> DeploymentTxFactory<B, M>
impl<B, M> DeploymentTxFactory<B, M>
sourcepub fn new(abi: Abi, bytecode: Bytes, client: B) -> Self
pub fn new(abi: Abi, bytecode: Bytes, client: B) -> 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.
sourcepub fn deploy_tokens(
self,
params: Vec<Token>
) -> Result<Deployer<B, M>, ContractError<M>>where
B: Clone,
pub fn deploy_tokens(
self,
params: Vec<Token>
) -> Result<Deployer<B, M>, ContractError<M>>where
B: Clone,
Create a deployment tx using the provided tokens as constructor arguments
sourcepub fn deploy<T: Tokenize>(
self,
constructor_args: T
) -> Result<Deployer<B, M>, ContractError<M>>
pub fn deploy<T: Tokenize>( self, constructor_args: T ) -> Result<Deployer<B, 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§
source§impl<B, M> Clone for DeploymentTxFactory<B, M>where
B: Clone,
impl<B, M> Clone for DeploymentTxFactory<B, M>where
B: Clone,
Auto Trait Implementations§
impl<B, M> RefUnwindSafe for DeploymentTxFactory<B, M>where
B: RefUnwindSafe,
M: RefUnwindSafe,
impl<B, M> Send for DeploymentTxFactory<B, M>
impl<B, M> Sync for DeploymentTxFactory<B, M>
impl<B, M> Unpin for DeploymentTxFactory<B, M>
impl<B, M> UnwindSafe for DeploymentTxFactory<B, M>where
B: UnwindSafe,
M: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more