Factory

Struct Factory 

Source
pub struct Factory<T: Middleware> { /* private fields */ }

Implementations§

Source§

impl<T: Middleware> Factory<T>

Source

pub fn new(client: Arc<T>) -> Self

Source

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: The path parameter is a reference to a Path object, 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: The init parameter is of type Init. It represents the initialization parameters for the contract being deployed. The specific structure and fields of the Init type would depend on the contract being deployed.
  • overridden_params: overridden_params is an optional parameter of type TransactionParams. It allows you to override the default transaction parameters when deploying the contract. If you don’t want to override any parameters, you can pass None as 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(())
}
Source

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: The init parameter is of type Init, which is a custom struct or enum that contains the initialization data for the contract.
  • overridden_params: overridden_params is an optional parameter of type Option<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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSend for T
where T: Send,