Skip to content

Commit 4f8244c

Browse files
fix: Add validation for getContract params
1 parent d8b4e09 commit 4f8244c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.changeset/shy-bats-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Validate getContract params

packages/thirdweb/src/contract/contract.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Abi } from "abitype";
22
import type { Chain } from "../chains/types.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import { isAddress } from "../utils/address.js";
45

56
/**
67
* @contract
@@ -42,5 +43,14 @@ export type ThirdwebContract<abi extends Abi = []> = Readonly<
4243
export function getContract<const abi extends Abi = []>(
4344
options: ContractOptions<abi>,
4445
): ThirdwebContract<abi> {
46+
if (!options.client) {
47+
throw new Error("getContract validation error: Client is required");
48+
}
49+
if (!isAddress(options.address)) {
50+
throw new Error("getContract validation error: Invalid address");
51+
}
52+
if (!options.chain || !options.chain.id) {
53+
throw new Error("getContract validation error: Chain is required");
54+
}
4555
return options;
4656
}

0 commit comments

Comments
 (0)