@@ -52,13 +52,13 @@ def encode_function_signature(function_abi: Dict[str, Any]) -> Optional[str]:
5252 encoded_signature = Web3 .keccak (text = function_signature )[:4 ]
5353 return encoded_signature .hex ()
5454
55- def foundry_project_abis (project_dir : str , build_dirname : None ) -> Dict [str , List [Dict [str , Any ]]]:
55+ def foundry_project_abis (project_dir : str , build_dirname : Optional [ str ] = None ) -> Dict [str , List [Dict [str , Any ]]]:
5656 """
5757 Load all ABIs for project contracts and return then in a dictionary keyed by contract name.
5858
5959 Inputs:
6060 - project_dir
61- Path to brownie project
61+ Path to foundry project
6262 """
6363 if build_dirname is None :
6464 build_dirname = "out"
@@ -81,7 +81,7 @@ def foundry_project_abis(project_dir: str, build_dirname: None) -> Dict[str, Lis
8181
8282 return abis
8383
84- def brownie_project_abis (project_dir : str , build_dirname : None ) -> Dict [str , List [Dict [str , Any ]]]:
84+ def brownie_project_abis (project_dir : str , build_dirname : Optional [ str ] = None ) -> Dict [str , List [Dict [str , Any ]]]:
8585 """
8686 Load all ABIs for project contracts and return then in a dictionary keyed by contract name.
8787
@@ -107,3 +107,32 @@ def brownie_project_abis(project_dir: str, build_dirname: None) -> Dict[str, Lis
107107 abis [contract_name ] = contract_abi
108108
109109 return abis
110+
111+ def hardhat_project_abis (project_dir : str , build_dirname : Optional [str ] = None ):
112+ """
113+ Load all ABIs for project contracts and return then in a dictionary keyed by contract name.
114+
115+ Inputs:
116+ - project_dir
117+ Path to foundry project
118+ """
119+ if build_dirname is None :
120+ build_dirname = "artifacts"
121+
122+ build_dir = os .path .join (project_dir , build_dirname )
123+ build_files = glob .glob (os .path .join (build_dir , "**/*.json" ), recursive = True )
124+
125+ abis : Dict [str , List [Dict [str , Any ]]] = {}
126+
127+ for filepath in build_files :
128+ contract_name , _ = os .path .splitext (os .path .basename (filepath ))
129+ with open (filepath , "r" ) as ifp :
130+ contract_artifact = json .load (ifp )
131+
132+ try :
133+ contract_abi = contract_artifact .get ("abi" , [])
134+ abis [contract_name ] = contract_abi
135+ except Exception :
136+ continue
137+
138+ return abis
0 commit comments