pub struct Contract { /* private fields */ }
Expand description
Represents a Soroban smart contract
Provides functionality to deploy and interact with Soroban smart contracts. A Contract instance can represent either an undeployed contract (with just WASM bytecode) or a deployed contract (with client configuration for interacting with it).
Implementations§
Source§impl Contract
impl Contract
Sourcepub fn new(
wasm_path: &str,
client_configs: Option<ClientContractConfigs>,
) -> Result<Self, SorobanHelperError>
pub fn new( wasm_path: &str, client_configs: Option<ClientContractConfigs>, ) -> Result<Self, SorobanHelperError>
Sourcepub fn from_configs(client_configs: ClientContractConfigs) -> Self
pub fn from_configs(client_configs: ClientContractConfigs) -> Self
Sourcepub fn new_with_reader<T: FileReader>(
wasm_path: &str,
client_configs: Option<ClientContractConfigs>,
file_reader: T,
) -> Result<Self, SorobanHelperError>
pub fn new_with_reader<T: FileReader>( wasm_path: &str, client_configs: Option<ClientContractConfigs>, file_reader: T, ) -> Result<Self, SorobanHelperError>
Creates a new Contract instance from a WASM file path and custom file reader
§Parameters
wasm_path
- Path to the contract’s WASM fileclient_configs
- Optional configuration for interacting with an already deployed instancefile_reader
- Custom file reader for reading the WASM file adopting theFileReader
trait.
§Returns
A new Contract instance or an error if the file couldn’t be read
Sourcepub async fn deploy(
self,
env: &Env,
account: &mut Account,
constructor_args: Option<Vec<ScVal>>,
) -> Result<Self, SorobanHelperError>
pub async fn deploy( self, env: &Env, account: &mut Account, constructor_args: Option<Vec<ScVal>>, ) -> Result<Self, SorobanHelperError>
Deploys the contract to the Soroban network
This method performs two operations:
- Uploads the contract WASM bytecode if it doesn’t exist on the network
- Creates a contract instance with the uploaded WASM
If the contract has a constructor function, the provided constructor arguments will be passed to it during deployment.
§Parameters
env
- The environment to use for deploymentaccount
- The account that will deploy the contract and pay for the transactionconstructor_args
- Optional arguments to pass to the contract’s constructor
§Returns
The Contract instance updated with client configuration for the deployed contract
Sourcepub fn contract_id(&self) -> Option<ContractId>
pub fn contract_id(&self) -> Option<ContractId>
Returns the contract ID if the contract has been deployed
§Returns
The contract ID or None if the contract has not been deployed
Sourcepub async fn invoke(
&mut self,
function_name: &str,
args: Vec<ScVal>,
) -> Result<SorobanTransactionResponse, SorobanHelperError>
pub async fn invoke( &mut self, function_name: &str, args: Vec<ScVal>, ) -> Result<SorobanTransactionResponse, SorobanHelperError>
Invokes a function on the deployed contract
§Parameters
function_name
- The name of the function to invokeargs
- The arguments to pass to the function
§Returns
The transaction response from the network
§Errors
Returns an error if the contract has not been deployed or if there’s an issue with the invocation
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Contract
impl !RefUnwindSafe for Contract
impl Send for Contract
impl Sync for Contract
impl Unpin for Contract
impl !UnwindSafe for Contract
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more