Skip to content

Commit a2a61df

Browse files
fix: Add validation for getContract params (#5780)
Co-authored-by: MananTank <[email protected]>
1 parent 59ec04d commit a2a61df

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
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: 16 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,20 @@ 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(
48+
`getContract validation error - invalid client: ${options.client}`,
49+
);
50+
}
51+
if (!isAddress(options.address)) {
52+
throw new Error(
53+
`getContract validation error - invalid address: ${options.address}`,
54+
);
55+
}
56+
if (!options.chain || !options.chain.id) {
57+
throw new Error(
58+
`getContract validation error - invalid chain: ${options.chain}`,
59+
);
60+
}
4561
return options;
4662
}

packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { beforeAll, describe, expect, it } from "vitest";
22
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
3+
import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum-sepolia.js";
34
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
45
import { balanceOf } from "../../extensions/erc1155/__generated__/IERC1155/read/balanceOf.js";
56
import { claimTo } from "../../extensions/erc1155/drops/write/claimTo.js";
@@ -13,7 +14,6 @@ import type { Account, Wallet } from "../interfaces/wallet.js";
1314
import { generateAccount } from "../utils/generateAccount.js";
1415
import { smartWallet } from "./smart-wallet.js";
1516
let wallet: Wallet;
16-
import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum-sepolia.js";
1717

1818
let smartAccount: Account;
1919
let smartWalletAddress: Address;

0 commit comments

Comments
 (0)