title | description | category | published | order |
---|---|---|---|---|
ContractKit (Factory) |
The Contract Kit is responsible for facilitating the creation of Contract instances through the load method. |
ContractKit |
true |
3 |
The ContractKit
class provided by the Contract Kit is a factory class that facilitates the creation of Contract instances. Only one instance is required for each blockchain in the application and should be made widely available in the application.
When using the ContractKit
within a web application, an instance of the class must first be created. The only required argument during the creation of the ContractKit
is an instance of an APIClient, to allow it to make requests to the specified blockchain.
import { ContractKit } from "@wharfkit/contract"
import { APIClient } from "@wharfkit/antelope"
const contractKit = new ContractKit({
client: new APIClient("https://jungle4.greymass.com"),
})
This instance of the ContractKit
can now be used to generate any number of [Contract] instances for the specified blockchain.
A single argument is required to initialize a ContractKit
instance:
client
: The APIClient used to fetch data from the blockchain.
The ContractKit
allows for additional optional parameters to be passed for more advanced use cases.
An optional instance of the ABICache interface to manually specify an alternative cache. By default every instance of the ContractKit
comes with a built-in ABICache, and this is only required for advanced use cases where overriding the default is required.
import { ContractKit } from "@wharfkit/contract"
import { APIClient, ABICache } from "@wharfkit/antelope"
const client = new APIClient("https://jungle4.greymass.com")
const kit = const kit = new ContractKit({
client,
}, {
abiCache: new ABICache(client)
});
An array of existing ABI objects that have already been loaded in the application. This option can be used to pass ABIs directly to the ContractKit instance, eliminating the need for the ContractKit to fetch them using an APIClient.
import { ContractKit } from "@wharfkit/contract"
import { APIClient } from "@wharfkit/antelope"
import abi from "./abi.json" // ABI for a contract that will be loaded
const kit = const kit = new ContractKit({
client,
}, {
abis: [abi]
});
Once a ContractKit
instance is created, the load
method can be used to instantiate a specific Contract instance.
const contract = await contractKit.load("eosio.token")
The only parameter required is the name of the account where the contract is deployed on-chain.