BaseContract
Creates a new contract connected to target with the abi and optionally connected to a runner to perform operations on behalf of.
Implements
Properties
Property | Modifier | Type | Description |
---|---|---|---|
fallback | readonly | null | WrappedFallback | The fallback or receive function if any. |
filters | readonly | Record <string , ContractEvent <any []>> | All the Events available on this contract. |
interface | readonly | Interface | The contract Interface. |
runner | readonly | null | ContractRunner | The connected runner. This is generally a Provider or a Signer, which dictates what operations are supported. For example, a Contract connected to a Provider may only execute read-only operations. |
target | readonly | string | Addressable | The target to connect to. This can be an address or any Addressable, such as another contract. To get the resolved address, use the getAddress method. |
Methods
addListener()
Alias for on.
Parameters
Parameter | Type | Description |
---|---|---|
event | ContractEventName | The event to listen for. |
listener | Listener | The listener to call when the event is emitted. |
Returns
Promise
<BaseContract
>
Implementation of
Source
attach()
Return a new Contract instance with the same ABI and runner, but a different target
.
Parameters
Parameter | Type | Description |
---|---|---|
target | string | Addressable | The target to connect to. |
Returns
The new contract instance.
Source
connect()
Return a new Contract instance with the same target and ABI, but a different runner
.
Parameters
Parameter | Type | Description |
---|---|---|
runner | null | ContractRunner | The runner to use. |
Returns
The new contract instance.
Source
deploymentTransaction()
Return the transaction used to deploy this contract.
This is only available if this instance was returned from a ContractFactor.
Returns
null
| ContractTransactionResponse
The transaction used to deploy this contract or null
.
Source
emit()
Emit an event
calling all listeners with args
.
Resolves to true
if any listeners were called.
Parameters
Parameter | Type | Description |
---|---|---|
event | ContractEventName | The event to emit. |
…args | any [] | The arguments to pass to the listeners. |
Returns
Promise
<boolean
>
true
if any listeners were called.
Implementation of
Source
getAddress()
Return the resolved address of this Contract.
Returns
Promise
<string
>
The resolved address.
Implementation of
Source
getDeployedCode()
Return the deployed bytecode or null if no bytecode is found.
Returns
Promise
<null
| string
>
The deployed bytecode or null.
Throws
If the runner does not support .provider.
Source
getEvent()
Return the event for a given name. This is useful when a contract event name conflicts with a JavaScript name
such as prototype
or when using a Contract programatically.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | EventFragment | The name of the event to return. |
Returns
ContractEvent
<any
[]>
The event for the given name.
Source
getFunction()
Return the function for a given name. This is useful when a contract method name conflicts with a JavaScript name
such as prototype
or when using a Contract programatically.
Type parameters
Type parameter | Value |
---|---|
T extends ContractMethod <any [], any , any , T > | ContractMethod <any [], any , any > |
Parameters
Parameter | Type | Description |
---|---|---|
key | string | FunctionFragment | The name of the function to return. |
Returns
T
The function for the given name.
Source
listenerCount()
Resolves to the number of listeners of event
or the total number of listeners if unspecified.
Parameters
Parameter | Type | Description |
---|---|---|
event ? | ContractEventName | The event to count listeners for. |
Returns
Promise
<number
>
The number of listeners.
Implementation of
EventEmitterable
.listenerCount
Source
listeners()
Resolves to the listeners subscribed to event
or all listeners if unspecified.
Parameters
Parameter | Type | Description |
---|---|---|
event ? | ContractEventName | The event to get listeners for. |
Returns
Promise
<Listener
[]>
The listeners.
Implementation of
Source
off()
Remove the listener
from the listeners for event
or remove all listeners if unspecified.
Parameters
Parameter | Type | Description |
---|---|---|
event | ContractEventName | The event to remove the listener from. |
listener ? | Listener | The listener to remove. |
Returns
Promise
<BaseContract
>
This contract instance.
Implementation of
Source
on()
Add an event listener
for the event
.
Parameters
Parameter | Type | Description |
---|---|---|
event | ContractEventName | The event to listen for. |
listener | Listener | The listener to call when the event is emitted. |
Returns
Promise
<BaseContract
>
This contract instance.
Implementation of
Source
once()
Add an event listener
for the event
, but remove the listener after it is fired once.
Parameters
Parameter | Type | Description |
---|---|---|
event | ContractEventName | The event to listen for. |
listener | Listener | The listener to call when the event is emitted. |
Returns
Promise
<BaseContract
>
Implementation of
Source
queryFilter()
Provide historic access to event data for event
in the range fromBlock
(default: 0
) to toBlock
(default:
"latest"
) inclusive.
Parameters
Parameter | Type | Description |
---|---|---|
event | ContractEventName | The event to query. |
fromBlock ? | BlockTag | The block to start querying from. |
toBlock ? | BlockTag | The block to stop querying at. |
Returns
An array of event logs.
Source
removeAllListeners()
Remove all the listeners for event
or remove all listeners if unspecified.
Parameters
Parameter | Type | Description |
---|---|---|
event ? | ContractEventName | The event to remove the listeners from. |
Returns
Promise
<BaseContract
>
This contract instance.
Implementation of
EventEmitterable
.removeAllListeners
Source
removeListener()
Alias for off.
Parameters
Parameter | Type | Description |
---|---|---|
event | ContractEventName | The event to remove the listener from. |
listener | Listener | The listener to remove. |
Returns
Promise
<BaseContract
>
Implementation of
EventEmitterable
.removeListener
Source
waitForDeployment()
Resolve to this Contract once the bytecode has been deployed, or resolve immediately if already deployed.
Returns
Promise
<BaseContract
>
The contract instance.
Throws
If the contract runner does not support .provider.
Source
buildClass()
Create a new Class for the abi
.
Type parameters
Type parameter | Value |
---|---|
T | ContractInterface |
Parameters
Parameter | Type | Description |
---|---|---|
abi | Interface | InterfaceAbi | The ABI to create the class from. |
Returns
Object
The new Class for the ABI.
Source
from()
Create a new BaseContract with a specified Interface.
Type parameters
Type parameter | Value |
---|---|
T | ContractInterface |
Parameters
Parameter | Type | Description |
---|---|---|
target | string | The target to connect to. |
abi | Interface | InterfaceAbi | The ABI to use. |
runner ? | null | ContractRunner | The runner to use. |
Returns
BaseContract
& Omit
<T
, keyof BaseContract
>
The new BaseContract.
Source
Was this page helpful?