pub struct Factory<T: Middleware> { /* private fields */ }Implementations§
Source§impl<T: Middleware> Factory<T>
impl<T: Middleware> Factory<T>
pub fn new(client: Arc<T>) -> Self
Sourcepub async fn deploy_from_file(
&self,
path: &Path,
init: Init,
overridden_params: Option<TransactionParams>,
do_contract_compression: bool,
) -> Result<BaseContract<T>, Error>
pub async fn deploy_from_file( &self, path: &Path, init: Init, overridden_params: Option<TransactionParams>, do_contract_compression: bool, ) -> Result<BaseContract<T>, Error>
The deploy_from_file function deploys a contract from a file path, with the option to override
transaction parameters.
Arguments:
path: Thepathparameter is a reference to aPathobject, which represents the path to a file. It is used to specify the location of the file from which the contract code will be read.init: Theinitparameter is of typeInit. It represents the initialization parameters for the contract being deployed. The specific structure and fields of theInittype would depend on the contract being deployed.overridden_params:overridden_paramsis an optional parameter of typeTransactionParams. It allows you to override the default transaction parameters when deploying the contract. If you don’t want to override any parameters, you can passNoneas the value for this parameter.do_contract_compression: Set it to true if you want your contract gets compressed before deployment.
Returns:
a Result object with a value of type BaseContract<T> if the operation is successful, or an Error
object if there is an error.
§Example
use zilliqa_rs::providers::{Http, Provider};
use zilliqa_rs::contract::ScillaVariable;
use zilliqa_rs::signers::LocalWallet;
use zilliqa_rs::contract::Init;
use zilliqa_rs::contract::ContractFactory;
use std::path::PathBuf;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
const END_POINT: &str = "http://localhost:5555";
let wallet = "d96e9eb5b782a80ea153c937fa83e5948485fbfc8b7e7c069d7b914dbc350aba".parse::<LocalWallet>()?;
let provider = Provider::<Http>::try_from(END_POINT)?
.with_chain_id(222)
.with_signer(wallet.clone());
let factory = ContractFactory::new(provider.into());
let init = Init(vec![ScillaVariable::new_from_str("_scilla_version", "Uint32", "0")]);
let contract = factory.deploy_from_file(&PathBuf::from("./tests/contracts/Timestamp.scilla"), init, None, false).await?;
println!("addr: {:?}", contract);
Ok(())
}Sourcepub async fn deploy_str(
&self,
contract_code: String,
init: Init,
overridden_params: Option<TransactionParams>,
) -> Result<BaseContract<T>, Error>
pub async fn deploy_str( &self, contract_code: String, init: Init, overridden_params: Option<TransactionParams>, ) -> Result<BaseContract<T>, Error>
The deploy_str function deploys a contract with the given code and initialization parameters, and
returns a BaseContract object.
Arguments:
contract_code: A string containing the code of the contract to be deployed.init: Theinitparameter is of typeInit, which is a custom struct or enum that contains the initialization data for the contract.overridden_params:overridden_paramsis an optional parameter of typeOption<TransactionParams>. It allows the caller to provide custom transaction parameters for deploying the contract.
Returns:
The function deploy_str returns a Result containing either a BaseContract<T> or an Error.
§Example
use zilliqa_rs::providers::{Http, Provider};
use zilliqa_rs::contract::ScillaVariable;
use zilliqa_rs::signers::LocalWallet;
use zilliqa_rs::contract::Init;
use zilliqa_rs::contract::ContractFactory;
use std::path::PathBuf;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
const END_POINT: &str = "http://localhost:5555";
let wallet = "d96e9eb5b782a80ea153c937fa83e5948485fbfc8b7e7c069d7b914dbc350aba".parse::<LocalWallet>()?;
let provider = Provider::<Http>::try_from(END_POINT)?
.with_chain_id(222)
.with_signer(wallet.clone());
let factory = ContractFactory::new(provider.into());
let init = Init(vec![ScillaVariable::new_from_str("_scilla_version", "Uint32", "0")]);
let contract = factory.deploy_str(include_str!("../../tests/contracts/Timestamp.scilla").to_string(), init, None).await?;
println!("addr: {:?}", contract);
Ok(())
}Auto Trait Implementations§
impl<T> Freeze for Factory<T>
impl<T> RefUnwindSafe for Factory<T>where
T: RefUnwindSafe,
impl<T> Send for Factory<T>
impl<T> Sync for Factory<T>
impl<T> Unpin for Factory<T>
impl<T> UnwindSafe for Factory<T>where
T: RefUnwindSafe,
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