diff --git a/.changeset/shy-bats-eat.md b/.changeset/shy-bats-eat.md new file mode 100644 index 00000000000..243e7f0b8a2 --- /dev/null +++ b/.changeset/shy-bats-eat.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Validate getContract params diff --git a/packages/thirdweb/src/contract/contract.ts b/packages/thirdweb/src/contract/contract.ts index af8258a2976..7b74b43d430 100644 --- a/packages/thirdweb/src/contract/contract.ts +++ b/packages/thirdweb/src/contract/contract.ts @@ -1,6 +1,7 @@ import type { Abi } from "abitype"; import type { Chain } from "../chains/types.js"; import type { ThirdwebClient } from "../client/client.js"; +import { isAddress } from "../utils/address.js"; /** * @contract @@ -42,5 +43,14 @@ export type ThirdwebContract = Readonly< export function getContract( options: ContractOptions, ): ThirdwebContract { + if (!options.client) { + throw new Error("getContract validation error: Client is required"); + } + if (!isAddress(options.address)) { + throw new Error("getContract validation error: Invalid address"); + } + if (!options.chain || !options.chain.id) { + throw new Error("getContract validation error: Chain is required"); + } return options; }