StarknetKit
Docs v1.1.9
Starknet.js 101
Contract

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

  1. contract.abi => Abi

The ABI the contract was constructed with.

  1. contract.address => string

The address the contract was constructed/connected with.

  1. contract.providerOrAccount => ProviderInterface | AccountInterface

Provider or account that is used to interact with the network.

  1. 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

  1. 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.

  1. contract.connect(providerOrAccount) => void

Attaches to new Provider or Account

  1. 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.

  1. contract.call(method, args, options) => Promise < Result >

Calls a method on a contract.

  1. contract.invoke(method, args, options) => Promise < InvokeFunctionResponse >

Invokes a method on a contract.

  1. contract.estimate(method, args, options) => Promise < any >

Estimates a method on a contract.

  1. contract.populate(method, args, options) => Invocation

Populate a method on a contract.