Connect to a Contract
Connect to a deployed smart contract to start interacting with it.
The ABI of the smart contract is resolved automatically for contracts deployed or imported using the dashboard.
Usage
// Instantiate the SDK in either read or read-write mode
const sdk = new ThirdWebSDK("ethereum");
// Connect to your smart contract using the contract address.
const contract = await sdk.getContract("0x...");
To preload the ABI of the smart contract, run npx thirdweb generate in your project.
This is recommended to improve performance and provide type-safety when interacting with your smart contract.
Configuration
address (required)
The address of the smart contract you want to connect to.
const contract = await sdk.getContract(
"0x...", // The address of your smart contract
);
abi (optional)
Optionally, (if you don’t want to use the import feature),
you can provide your smart contract’s ABI to the second parameter of the getContract
method.
Useful when developing on a local node,
where it may be faster to use the ABI than to import the contract using the dashboard.
The ABI is only necessary if you have not deployed your contract with, or imported your contract to the thirdweb dashboard.
const contract = await sdk.getContract(
"0x...", // The address of your smart contract
abi, // The ABI of your smart contract
);