@@ -11,6 +11,30 @@ export const loadAbiFromSourcify = async (
1111  ABICtor : typeof  ABI , 
1212  network : string , 
1313  address : string , 
14+ ) : Promise < ABI >  => 
15+   await  withSpinner ( 
16+     `Fetching ABI from Sourcify` , 
17+     `Failed to fetch ABI from Sourcify` , 
18+     `Warnings while fetching ABI from Sourcify` , 
19+     async  ( )  =>  { 
20+       const  chainId  =  await  getSourcifyChainId ( network ) ; 
21+       const  result  =  await  fetch ( `https://repo.sourcify.dev/contracts/full_match/${ chainId } ${ address }  ) ; 
22+       const  json  =  await  result . json ( ) ; 
23+ 
24+       // Etherscan returns a JSON object that has a `status`, a `message` and 
25+       // a `result` field. The `status` is '0' in case of errors and '1' in 
26+       // case of success 
27+       if  ( result . ok )  { 
28+         return  new  ABICtor ( 'Contract' ,  undefined ,  immutable . fromJS ( json . output . abi ) ) ; 
29+       } 
30+       throw  new  Error ( 'ABI not found, try loading it from a local file' ) ; 
31+     } , 
32+   ) ; 
33+ 
34+ export  const  loadAbiFromEtherscan  =  async  ( 
35+   ABICtor : typeof  ABI , 
36+   network : string , 
37+   address : string , 
1438) : Promise < ABI >  => 
1539  await  withSpinner ( 
1640    `Fetching ABI from Sourcify` , 
@@ -202,8 +226,10 @@ const getSourcifyChainId = async (network: string) => {
202226  // Can fail if network name doesn't follow https://chainlist.org name convention 
203227  const  match  =  json . find ( ( e : any )  =>  e . name . toLowerCase ( ) . includes ( network . replace ( '-' ,  ' ' ) ) ) ; 
204228
205-   if  ( match )  return  match . chainId ; 
206-   throw  new  Error ( `Could not find chain id for "${ network }  ) ; 
229+   if  ( match ) 
230+     return  match . chainId ; 
231+   else 
232+     throw  new  Error ( `Could not find chain id for "${ network }  ) ; 
207233} ; 
208234
209235const  getEtherscanLikeAPIUrl  =  ( network : string )  =>  { 
0 commit comments