1
1
import type { Abi } from "abitype" ;
2
2
import type { Chain } from "../chains/types.js" ;
3
3
import type { ThirdwebClient } from "../client/client.js" ;
4
- import { isAddress } from "../utils/address.js" ;
4
+ import { type Address , isAddress } from "../utils/address.js" ;
5
5
6
6
/**
7
7
* @contract
8
8
*/
9
- export type ContractOptions < abi extends Abi = [ ] > = {
9
+ export type ContractOptions <
10
+ abi extends Abi = [ ] ,
11
+ address extends string = string ,
12
+ > = {
10
13
client : ThirdwebClient ;
11
- address : string ;
14
+ address : address ;
12
15
chain : Chain ;
13
16
readonly abi ?: abi ;
14
17
} ;
15
18
16
19
/**
17
20
* @contract
18
21
*/
19
- export type ThirdwebContract < abi extends Abi = [ ] > = Readonly <
20
- ContractOptions < abi >
21
- > ;
22
+ export type ThirdwebContract <
23
+ abi extends Abi = [ ] ,
24
+ address extends string = string ,
25
+ > = Readonly < ContractOptions < abi , address > > ;
22
26
23
27
/**
24
28
* Creates a Thirdweb contract by combining the Thirdweb client and contract options.
@@ -42,7 +46,7 @@ export type ThirdwebContract<abi extends Abi = []> = Readonly<
42
46
*/
43
47
export function getContract < const abi extends Abi = [ ] > (
44
48
options : ContractOptions < abi > ,
45
- ) : ThirdwebContract < abi > {
49
+ ) : ThirdwebContract < abi , Address > {
46
50
if ( ! options . client ) {
47
51
throw new Error (
48
52
`getContract validation error - invalid client: ${ options . client } ` ,
@@ -58,5 +62,5 @@ export function getContract<const abi extends Abi = []>(
58
62
`getContract validation error - invalid chain: ${ options . chain } ` ,
59
63
) ;
60
64
}
61
- return options ;
65
+ return options as ThirdwebContract < abi , Address > ;
62
66
}
0 commit comments