Contracts
Contracts are primarily how we create instantiations of our smart contracts with javascript. It takes in the contract’s ABI, the contract’s address, and the provider or account.
Contracts can make read and write calls to StarkNet through a provided signer, allow users to transform Cairo values, like Uint256
to BigNumber
and to pass their own transformers, similar to JSON.parse
.
Instantiation
To create a new contract instance, you need the contract's abi, address, and a provider or account.
new starknet.Contract(abi, address, providerOrAccount)
To change the address of the connected account:
contract.attach(address)
To change the provider or account:
contract.connect(providerOrAccount)
Properties
- 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 is 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 that was used to deploy the contract.
Methods
- contract.attach(address) => void
Saves the address of the contract deployed on network that will be used for interaction.
where address
is the 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
Populate a method on a contract.