163 lines
7.0 KiB
Plaintext
163 lines
7.0 KiB
Plaintext
_section: Contract @<contract> @SRC<contracts:class.Contract>
|
|
|
|
_subsection: Properties
|
|
|
|
_property: contract.address => string<[[address]]>
|
|
This is the address (or ENS name) the contract was constructed with.
|
|
|
|
_property: contract.addressPromise => string<[[address]]>
|
|
This is a promise that will resolve to the address the **Contract**
|
|
object is attached to. If an [[address]] was provided to the constructor,
|
|
it will be equal to this; if an ENS name was provided, this will be the
|
|
resolved address.
|
|
|
|
_property: contract.deployTransaction => [[provider-transactionresponse]]
|
|
If the **Contract** object is the result of a ContractFactory deployment,
|
|
this is the transaction which was used to deploy the contract.
|
|
|
|
_property: contract.interface => [[abi-interface]]
|
|
This is the ABI as an [[abi-interface]].
|
|
|
|
_property: contract.provider => [[provider]]
|
|
If a provider was provided to the constructor, this is that provider. If
|
|
a signer was provided that had a [[provider]], this is that provider.
|
|
|
|
_property: contract.signer => [[signer]]
|
|
If a signer was provided to the constructor, this is that signer.
|
|
|
|
|
|
_subsection: Methods
|
|
|
|
_property: contract.attach(addressOrName) => [[contract]] @<contract-attach> @SRC<contracts:Contract.attach>
|
|
Returns a new instance of the **Contract** attached to a new
|
|
address. This is useful if there are multiple similar or identical
|
|
copies of a Contract on the network and you wish to interact with
|
|
each of them.
|
|
|
|
_property: contract.connect(providerOrSigner) => [[contract]] @<contract-connect> @SRC<contracts:Contract.connect>
|
|
Returns a new instance of the Contract, but connected to
|
|
//providerOrSigner//.
|
|
|
|
By passing in a [[provider]], this will return a downgraded
|
|
**Contract** which only has read-only access (i.e. constant calls).
|
|
|
|
By passing in a [[signer]]. the will return a **Contract** which
|
|
will act on behalf of that signer.
|
|
|
|
_property: contract.deployed() => Promise<[[contract]]> @<contract-deployed> @SRC<contracts>
|
|
|
|
_property: Contract.isIndexed(value) => boolean @<contract-isIndexed> @SRC<contracts>
|
|
|
|
|
|
_subsection: Events
|
|
|
|
_property: contract.queryFilter(event [ , fromBlockOrBlockHash [ , toBlock ]) => Promise<Array<Event>> @<contract-queryfilter> @SRC<contracts>
|
|
Return Events that match the //event//.
|
|
|
|
_property: contract.listenerCount([ event ]) => number @<contract-listenerCount> @SRC<contracts:Contract.listenerCount>
|
|
Return the number of listeners that are subscribed to //event//. If
|
|
no event is provided, returns the total count of all events.
|
|
|
|
_property: contract.listeners(event) => Array<Listener> @<contract-listeners> @SRC<contracts:Contract.listeners>
|
|
Return a list of listeners that are subscribed to //event//.
|
|
|
|
_property: contract.off(event, listener) => this @<contract-off> @SRC<contracts>
|
|
Unsubscribe //listener// to //event//.
|
|
|
|
_property: contract.on(event, listener) => this @<contract-on> @SRC<contracts>
|
|
Subscribe to //event// calling //listener// when the event occurs.
|
|
|
|
_property: contract.once(event, listener) => this @<contract-once> @SRC<contracts>
|
|
Subscribe once to //event// calling //listener// when the event
|
|
occurs.
|
|
|
|
_property: contract.removeAllListeners([ event ]) => this @<contract-removeAllListeners> @SRC<contracts:Contract.removeAllListeners>
|
|
Unsubscribe all listeners for //event//. If no event is provided,
|
|
all events are unsubscribed.
|
|
|
|
|
|
_subsection: Meta-Class @<contract-metaclass>
|
|
|
|
A Meta-Class is a Class which has any of its properties determined
|
|
at run-time. The **Contract** object uses a Contract's ABI to
|
|
determine what methods are available, so the following sections
|
|
describe the generic ways to interact with the properties added
|
|
at run-time during the **Contract** constructor.
|
|
|
|
|
|
_heading: Read-Only Methods (constant) @<contract-readonly>
|
|
|
|
A constant method is read-only and evaluates a small amount of EVM
|
|
code against the current blockchain state and can be computed by
|
|
asking a single node, which can return a result. It is therefore
|
|
free and does not require any ether, but **cannot make changes** to
|
|
the blockchain state..
|
|
|
|
_property: contract.METHOD_NAME(...args [ overrides ]) => Promise<any> @<contract-call>
|
|
The type of the result depends on the ABI.
|
|
|
|
For values that have a simple meaning in JavaScript, the types are fairly
|
|
straight forward; strings and booleans are returned as JavaScript strings
|
|
and booleans.
|
|
|
|
For numbers, if the **type** is in the JavaSsript safe range (i.e. less
|
|
than 53 bits, such as an ``int24`` or ``uint48``) a normal JavaScript
|
|
number is used. Otherwise a [[bignumber]] is returned.
|
|
|
|
For bytes (both fixed length and dynamic), a [[datahexstring]] is returned.
|
|
|
|
|
|
_heading: Write Methods (non-constant) @<contract-write>
|
|
|
|
A non-constant method requires a transaction to be signed and requires
|
|
payment in the form of a fee to be paid to a miner. This transaction
|
|
will be verified by every node on the entire network as well by the
|
|
miner who will compute the new state of the blockchain after executing
|
|
it against the current state.
|
|
|
|
It cannot return a result. If a result is required, it should be logged
|
|
using a Solidity event (or EVM log), which can then be queried from the
|
|
transaction receipt.
|
|
|
|
_property: contract.METHOD_NAME(...args [ , overrides ]) => Promise<[[provider-transactionresponse]]> @<contract-send>
|
|
Returns a [[provider-transactionresponse]] for the transaction after
|
|
it is sent to the network. This requires the **Contract** has a
|
|
signer.
|
|
|
|
|
|
_heading: Write Methods Analysis @<contract-write-check>
|
|
|
|
There are secveral options to analyze properties and results of a
|
|
write method without actually executing it.
|
|
|
|
_property: contract.estimate.METHOD_NAME(...args [ , overrides ]) => Promise<[[bignumber]]> @<contract-estimateGas>
|
|
Returns the estimate units of gas that would be required to
|
|
execute the //METHOD_NAME// with //args// and //overrides//.
|
|
|
|
_property: contract.populateTransaction.METHOD_NAME(...args [ , overrides ]) => Promise<[UnsignedTx](types-unsignedtransaction)> @<contract-populateTransaction>
|
|
Returns an [[types-unsignedtransaction]] which represents the transaction
|
|
that would need to be signed and submitted to the network to execute
|
|
//METHOD_NAME// with //args/ and //overrides//.
|
|
|
|
_property: contract.staticCall.METHOD_NAME(...args [ , overrides ]) => Promise<any> @<contract-staticCall>
|
|
Rather than executing the state-change of a transaction, it is possible
|
|
to ask a node to //pretend// that a call is not state-changing and
|
|
return the result.
|
|
|
|
This does not actually chagne any state, but is free. This in some cases
|
|
can be used to determine if a transaction will fail or succeed.
|
|
|
|
This otherwise functions the same as a [Read-Only Method](contract-readonly).
|
|
|
|
_heading: Event Filters @<contract-filter>
|
|
An event filter is made up of topics, which are values logged in a
|
|
[[link-wiki-bloomfilter]], allowing efficient searching for entries
|
|
which match a filter.
|
|
|
|
_property: contract.filters.EVENT_NAME(...args) => Filter
|
|
Return a filter for //EVENT_NAME//, optionally filtering by additional
|
|
constraints.
|
|
|
|
Only ``indexed`` event parameters may be filtered. If a parameter is
|
|
null (or not provided) then any value in that field matches.
|