Skip to content

Commit

Permalink
fix: Add validation for getContract params
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Dec 17, 2024
1 parent d8b4e09 commit 4f8244c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-bats-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Validate getContract params
10 changes: 10 additions & 0 deletions packages/thirdweb/src/contract/contract.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,5 +43,14 @@ export type ThirdwebContract<abi extends Abi = []> = Readonly<
export function getContract<const abi extends Abi = []>(
options: ContractOptions<abi>,
): ThirdwebContract<abi> {
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;
}

0 comments on commit 4f8244c

Please sign in to comment.