@ -1,10 +1,11 @@
import { confirm , input } from '@inquirer/prompts' ;
import { confirm , input , select } from '@inquirer/prompts' ;
import { ethers } from 'ethers' ;
import { stringify as yamlStringify } from 'yaml' ;
import {
ChainMetadata ,
ChainMetadataSchema ,
ExplorerFamily ,
ZChainName ,
} from '@hyperlane-xyz/sdk' ;
import { ProtocolType } from '@hyperlane-xyz/utils' ;
@ -89,6 +90,8 @@ export async function createChainConfig({
rpcUrls : [ { http : rpcUrl } ] ,
} ;
await addBlockExplorerConfig ( metadata ) ;
await addBlockOrGasConfig ( metadata ) ;
await addNativeTokenConfig ( metadata ) ;
@ -111,6 +114,42 @@ export async function createChainConfig({
}
}
async function addBlockExplorerConfig ( metadata : ChainMetadata ) : Promise < void > {
const wantBlockExplorerConfig = await confirm ( {
default : false ,
message : 'Do you want to add a block explorer config for this chain' ,
} ) ;
if ( wantBlockExplorerConfig ) {
const name = await input ( {
message : 'Enter a human readable name for the explorer:' ,
} ) ;
const url = await input ( {
message : 'Enter the base URL for the explorer:' ,
} ) ;
const apiUrl = await input ( {
message : 'Enter the base URL for requests to the explorer API:' ,
} ) ;
const family = ( await select ( {
message : 'Select the type (family) of block explorer:' ,
choices : Object.entries ( ExplorerFamily ) . map ( ( [ _ , value ] ) = > ( { value } ) ) ,
pageSize : 10 ,
} ) ) as ExplorerFamily ;
const apiKey =
( await input ( {
message :
"Optional: Provide an API key for the explorer, or press 'enter' to skip. Please be sure to remove this field if you intend to add your config to the Hyperlane registry:" ,
} ) ) ? ? undefined ;
metadata . blockExplorers = [ ] ;
metadata . blockExplorers [ 0 ] = {
name ,
url ,
apiUrl ,
family ,
} ;
if ( apiKey ) metadata . blockExplorers [ 0 ] . apiKey = apiKey ;
}
}
async function addBlockOrGasConfig ( metadata : ChainMetadata ) : Promise < void > {
const wantBlockOrGasConfig = await confirm ( {
default : false ,