Generate
Detects all contract addresses in your project, then fetches and stores each smart contract’s ABI in memory (inside node_modules
);
improving the performance of the SDK when using functions such as getContract
and
useContract
.
Once the ABIs are cached locally, the SDK becomes strongly typed when interacting with your smart contracts.
Providing you with Intellisense and type-checking when using functions such as
contract.call
, in the TypeScript SDK,
or useContractRead
, and useContractWrite
in the React SDK.
npx thirdweb generate
Configuration
After the first generation, a thirdweb.json
file is created at the root of your project containing configuration for the command:
// An example thirdweb.json file
{
"chainIds": [80001],
"contracts": [
{
"address": "0x5523B2CB564579aAf2947B8d08e2187ff35aE4b2",
"chainId": 80001
}
]
}
To add additional contracts to the generation process, add a new object into the contracts
array in the thirdweb.json
file:
{
"chainIds": [80001],
"contracts": [
{
"address": "0x5523B2CB564579aAf2947B8d08e2187ff35aE4b2",
"chainId": 80001
},
{
"address": "some-other-contract-address",
"chainId": 80001
}
]
}
postinstall Script
A postinstall
script is also created that performs the generate
command
after your dependencies are installed; enabling the same ABI caching process and performance improvements in your deployment environments.
You can view and customize the script inside of your package.json
.
Usage
The command recursively checks all files in your project for valid smart contract addresses and fetches the ABIs for each contract.
The ABIs are then stored locally in the projects node_modules/@thirdweb-dev/generated-abis
directory.
Functions that require the fetching of a smart contract such as getContract
and useContract
will now use the cached ABIs instead of
fetching them each time the function is called. This improves the performance of your application and allows the SDK to become strongly
typed when interacting with your smart contracts.
npx thirdweb generate [options]
Options
-p
--path <string>
Path to project
-k
--key <string>
Optional parameter to use passed in secret key, most useful for continuous integration use cases