pub struct Contract {
pub compiled_contract: CompiledContract,
}
Expand description
Contract is a struct to interface with a contract. That includes things such as compiling, deploying, and running transactions against a contract.
Fields§
§compiled_contract: CompiledContract
Implementations§
Source§impl Contract
impl Contract
pub fn new(compiled_contract: CompiledContract) -> Self
pub fn compute_contract_id(compiled_contract: &CompiledContract) -> ContractId
Sourcepub async fn call(
contract_id: ContractId,
encoded_selector: Option<Selector>,
encoded_args: Option<Vec<u8>>,
fuel_client: &FuelClient,
gas_price: Word,
gas_limit: Word,
maturity: Word,
custom_inputs: bool,
) -> Result<Vec<Receipt>, String>
pub async fn call( contract_id: ContractId, encoded_selector: Option<Selector>, encoded_args: Option<Vec<u8>>, fuel_client: &FuelClient, gas_price: Word, gas_limit: Word, maturity: Word, custom_inputs: bool, ) -> Result<Vec<Receipt>, String>
Calls an already-deployed contract code. Note that this is a “generic” call to a contract and it doesn’t, yet, call a specific ABI function in that contract.
Sourcepub fn method_hash<D: Detokenize>(
fuel_client: &FuelClient,
compiled_contract: &CompiledContract,
signature: Selector,
output_params: &[ParamType],
args: &[Token],
) -> Result<ContractCall<D>, Error>
pub fn method_hash<D: Detokenize>( fuel_client: &FuelClient, compiled_contract: &CompiledContract, signature: Selector, output_params: &[ParamType], args: &[Token], ) -> Result<ContractCall<D>, Error>
Creates an ABI call based on a function selector and
the encoding of its call arguments, which is a slice of Tokens.
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
.
Sourcepub async fn launch_and_deploy(
compiled_contract: &CompiledContract,
) -> Result<(FuelClient, ContractId), Error>
pub async fn launch_and_deploy( compiled_contract: &CompiledContract, ) -> Result<(FuelClient, ContractId), Error>
Launches a local fuel-core
network and deploys a contract to it.
If you want to deploy a contract against another network of
your choosing, use the deploy
function instead.
Sourcepub async fn deploy(
compiled_contract: &CompiledContract,
fuel_client: &FuelClient,
) -> Result<ContractId, Error>
pub async fn deploy( compiled_contract: &CompiledContract, fuel_client: &FuelClient, ) -> Result<ContractId, Error>
Deploys a compiled contract to a running node
Sourcepub fn compile_sway_contract(
project_path: &str,
salt: Salt,
) -> Result<CompiledContract, Error>
pub fn compile_sway_contract( project_path: &str, salt: Salt, ) -> Result<CompiledContract, Error>
Compiles a Sway contract
Sourcepub fn contract_deployment_transaction(
compiled_contract: &CompiledContract,
) -> (Transaction, ContractId)
pub fn contract_deployment_transaction( compiled_contract: &CompiledContract, ) -> (Transaction, ContractId)
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, U> FlattenInto<U> for Twhere
U: FlattenFrom<T>,
impl<T, U> FlattenInto<U> for Twhere
U: FlattenFrom<T>,
fn flatten_into(self) -> U
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> 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