pub struct Contract {
pub compiled_contract: CompiledContract,
pub wallet: WalletUnlocked,
}
Expand description
Contract
is a struct to interface with a contract. That includes things such as
compiling, deploying, and running transactions against a contract.
The contract has a wallet attribute, used to pay for transactions and sign them.
It allows doing calls without passing a wallet/signer each time.
Fields§
§compiled_contract: CompiledContract
§wallet: WalletUnlocked
Implementations§
Source§impl Contract
impl Contract
pub fn new(compiled_contract: CompiledContract, wallet: WalletUnlocked) -> Self
pub fn compute_contract_id_and_state_root( compiled_contract: &CompiledContract, ) -> (ContractId, Bytes32)
Sourcepub fn method_hash<D: Tokenizable + Parameterize + Debug>(
provider: &Provider,
contract_id: Bech32ContractId,
wallet: &WalletUnlocked,
signature: Selector,
args: &[Token],
log_decoder: LogDecoder,
) -> Result<ContractCallHandler<D>, Error>
pub fn method_hash<D: Tokenizable + Parameterize + Debug>( provider: &Provider, contract_id: Bech32ContractId, wallet: &WalletUnlocked, signature: Selector, args: &[Token], log_decoder: LogDecoder, ) -> Result<ContractCallHandler<D>, Error>
Creates an ABI call based on a function selector and
the encoding of its call arguments, which is a slice of Token
s.
It returns a prepared ContractCall
that can further be used to
make the actual transaction.
This method is the underlying implementation of the functions
generated from an ABI JSON spec, i.e, this is what’s generated:
quote! {
#doc
pub fn #name(&self #input) -> #result {
Contract::method_hash(#tokenized_signature, #arg)
}
}
For more details see code_gen/functions_gen.rs
in fuels-core
.
Note that this needs a wallet because the contract instance needs a wallet for the calls
Sourcepub async fn deploy(
binary_filepath: &str,
wallet: &WalletUnlocked,
params: TxParameters,
storage_configuration: StorageConfiguration,
) -> Result<Bech32ContractId, Error>
pub async fn deploy( binary_filepath: &str, wallet: &WalletUnlocked, params: TxParameters, storage_configuration: StorageConfiguration, ) -> Result<Bech32ContractId, Error>
Loads a compiled contract and deploys it to a running node
Sourcepub async fn deploy_with_parameters(
binary_filepath: &str,
wallet: &WalletUnlocked,
params: TxParameters,
storage_configuration: StorageConfiguration,
salt: Salt,
) -> Result<Bech32ContractId, Error>
pub async fn deploy_with_parameters( binary_filepath: &str, wallet: &WalletUnlocked, params: TxParameters, storage_configuration: StorageConfiguration, salt: Salt, ) -> Result<Bech32ContractId, Error>
Loads a compiled contract with salt and deploys it to a running node
Sourcepub async fn deploy_loaded(
compiled_contract: &CompiledContract,
wallet: &WalletUnlocked,
params: TxParameters,
) -> Result<Bech32ContractId, Error>
pub async fn deploy_loaded( compiled_contract: &CompiledContract, wallet: &WalletUnlocked, params: TxParameters, ) -> Result<Bech32ContractId, Error>
Deploys a compiled contract to a running node To deploy a contract, you need a wallet with enough assets to pay for deployment. This wallet will also receive the change.
pub fn load_contract( binary_filepath: &str, storage_path: &Option<String>, ) -> Result<CompiledContract, Error>
pub fn load_contract_with_parameters( binary_filepath: &str, storage_path: &Option<String>, salt: Salt, ) -> Result<CompiledContract, Error>
Sourcepub async fn contract_deployment_transaction(
compiled_contract: &CompiledContract,
params: TxParameters,
) -> Result<(Create, Bech32ContractId), Error>
pub async fn contract_deployment_transaction( compiled_contract: &CompiledContract, params: TxParameters, ) -> Result<(Create, Bech32ContractId), Error>
Crafts a transaction used to deploy a contract
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> 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