Docs

Generate

You can generate precompiled, optimized type safe functions and events for any deployed contract using the thirdweb CLI.

npx thirdweb generate <chainId>/<contract-address>

This will generate a new thirdweb directory in your own project, containing the precompiled functions for the contract at the given address.

Example: Generating an extension for a USDC contract on Optimism

npx thirdweb generate 10/0x0b2c639c533813f4aa9d7837caf62653d097ff85

This will generate the following file thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85.ts in your project, containing:

  • Precompiled, type-safe event definitions
  • Precompiled, type-safe function definitions

You can inspect the generated code, modify it, and use it in your project.

Example: Using a generated extension function

import { permit } from "/thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85";
const contract = getContract({
client,
chain: optimism,
address: USDC_ADDRESS,
});
// Type-safe function to do a permit transaction
const transaction = permit({
owner: ...,
spender: ...,
value: ...,
deadline: ...,
signature: ...,
});
await sendTransaction({ transaction, account });

Example: Using a generated event

import { transferEvent } from "/thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85";
const contract = getContract({
client,
chain: optimism,
address: USDC_ADDRESS,
});
// Type-safe event listener
const events = await getContractEvents({
contract,
events: [
transferEvent({
from: ...,
to: ...,
})
],
});