Struct ethcontract::contract::Instance

source ·
pub struct Instance<T: Transport> {
    pub defaults: MethodDefaults,
    /* private fields */
}
Expand description

Represents a contract instance at an address. Provides methods for contract interaction.

Fields§

§defaults: MethodDefaults

Default method parameters to use when sending method transactions or querying method calls.

Implementations§

source§

impl<T: Transport> Instance<T>

source

pub fn at(web3: Web3<T>, interface: Arc<Interface>, address: Address) -> Self

Creates a new contract instance with the specified web3 provider with the given Abi at the given Address.

Note that this does not verify that a contract with a matching Abi is actually deployed at the given address.

source

pub fn with_deployment_info( web3: Web3<T>, interface: Arc<Interface>, address: Address, deployment_information: Option<DeploymentInformation> ) -> Self

Creates a new contract instance with the specified web3 provider with the given Abi at the given Address and an optional transaction hash. This hash is used to retrieve contract related information such as the creation block (which is useful for fetching all historic events).

Note that this does not verify that a contract with a matching Abi is actually deployed at the given address nor that the transaction hash, when provided, is actually for this contract deployment.

source

pub async fn deployed( web3: Web3<T>, contract: Contract ) -> Result<Self, DeployError>

Locates a deployed contract based on the current network ID reported by the web3 provider from the given Contract’s ABI and networks.

Note that this does not verify that a contract with a matching Abi is actually deployed at the given address.

source

pub fn builder<P>( web3: Web3<T>, contract: Contract, params: P ) -> Result<DeployBuilder<T, Self>, DeployError>
where P: Tokenize,

Creates a contract builder with the specified web3 provider and the given Contract byte code. This allows the contract deployment transaction to be configured before deploying the contract.

Deploys a contract with the specified web3 provider with the given Contract byte code and linking libraries.

source

pub fn web3(&self) -> Web3<T>

Retrieve the underlying web3 provider used by this contract instance.

source

pub fn abi(&self) -> &Abi

Retrieves the contract ABI for this instance.

source

pub fn address(&self) -> Address

Returns the contract address being used by this instance.

source

pub fn deployment_information(&self) -> Option<DeploymentInformation>

Returns the hash for the transaction that deployed the contract if it is known, None otherwise.

source

pub fn method<P, R>( &self, signature: impl Into<Signature<P, R>>, params: P ) -> AbiResult<MethodBuilder<T, R>>
where P: Tokenize, R: Tokenize,

Returns a method builder to setup a call or transaction on a smart contract method. Note that calls just get evaluated on a node but do not actually commit anything to the block chain.

source

pub fn view_method<P, R>( &self, signature: impl Into<Signature<P, R>>, params: P ) -> AbiResult<ViewMethodBuilder<T, R>>
where P: Tokenize, R: Tokenize,

Returns a view method builder to setup a call to a smart contract. View method builders can’t actually send transactions and only query contract state.

source

pub fn fallback<D>(&self, data: D) -> AbiResult<MethodBuilder<T, ()>>
where D: Into<Vec<u8>>,

Returns a method builder to setup a call to a smart contract’s fallback function.

This method will error if the ABI does not contain an entry for a fallback function.

source

pub fn event<E>(&self, signature: H256) -> AbiResult<EventBuilder<T, E>>
where E: Tokenize,

Returns a event builder to setup an event stream for a smart contract that emits events for the specified Solidity event by name.

source

pub fn all_events(&self) -> AllEventsBuilder<T, RawLog>

Returns a log stream that emits a log for every new event emitted after the stream was created for this contract instance.

Trait Implementations§

source§

impl<T: Clone + Transport> Clone for Instance<T>

source§

fn clone(&self) -> Instance<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Transport> Debug for Instance<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Transport> Deploy<T> for Instance<T>

§

type Context = Linker

The type of the contract instance being created.
source§

fn abi(cx: &Self::Context) -> &Abi

Gets a reference the contract ABI.
source§

fn bytecode(cx: &Self::Context) -> &Bytecode

Gets a reference to the contract bytecode.
source§

fn from_deployment( web3: Web3<T>, address: Address, transaction_hash: H256, cx: Self::Context ) -> Self

Create a contract instance from the specified deployment.

Auto Trait Implementations§

§

impl<T> Freeze for Instance<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Instance<T>
where T: RefUnwindSafe,

§

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

§

impl<T> Sync for Instance<T>
where T: Sync,

§

impl<T> Unpin for Instance<T>
where T: Unpin,

§

impl<T> UnwindSafe for Instance<T>
where T: UnwindSafe,

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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