Contracts allow you to transform Cairo values, like
BigNumber. It could also allow users to pass their own transformers, similar to
Creating an instance
new starknet.Contract(abi, address, providerOrAccount)
contract.attach(address) for changing the address of the connected contract
contract.connect(providerOrAccount) for changing the provider or account
contract.abi => Abi
The ABI the contract was constructed with.
contract.address => string
The address the contract was constructed/connected with.
contract.providerOrAccount => ProviderInterface | AccountInterface
Provider or account that are used to interact with the network.
contract.deployTransactionHash => string | null
If the Contract object is the result of a ContractFactory deployment, this is the transaction which was used to deploy the contract.
contract.attach(address) => void
Saves the address of the contract deployed on network that will be used for interaction.
address - address of the contract.
contract.connect(providerOrAccount) => void
Attaches to new Provider or Account
contract.deployed() => Promise < Contract >
If the Contract object is the result of a ContractFactory deployment, this method will wait for the transaction to be resolved.
contract.call(method, args, options) => Promise < Result >
Calls a method on a contract.
contract.invoke(method, args, options) => Promise < InvokeFunctionResponse >
Invokes a method on a contract.
contract.estimate(method, args, options) => Promise < any >
Estimates a method on a contract.
contract.populate(method, args, options) => Invocation
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.
A constant method (denoted view in Cairo) is read-only and evaluates a small amount of Cairo code against the current blockchain state. It is therefore free and does not require any fee, but cannot make changes to the blockchain state...
contract.METHOD_NAME(...args [ , overrides ]) => Promise < Result >
The type of the result depends on the ABI. Result object will be returned with each parameter available positionally and if the parameter is named, it will also be available by its name.
The overrides object for a read-only method may include:
Write Methods (non-constant)
A non-constant method requires a transaction to be signed and requires payment in the form of a fee to be paid.
contract.METHOD_NAME(...args [ , overrides ]) => Promise < AddTransactionResponse >
Returns a AddTransactionResponse for the transaction after it is sent to the network. This requires that Contract has a signer.
The overrides object for write methods may include any of:
- overrides.signature - Signature that will be used for the transaction
- overrides.maxFee - Max Fee for the transaction
- overrides.nonce - Nonce for the transaction
Write Methods Analysis
There are several options to analyze properties and results of a write method without actually executing it.
contract.estimateGas.METHOD_NAME( ...args ) => Promise < EstimateFeeResponse >
Returns the estimate units of gas that would be required to execute the METHOD_NAME with args and overrides.
contract.populateTransaction.METHOD_NAME( ...args [ , overrides ] ) ⇒ Call
Returns an Call object which represents the transaction that would need to be signed and submitted to the network to execute METHOD_NAME with args and overrides.
The overrides are identical to the overrides above for write methods.