feat(cli): add blockExplorers option on registry init (#4149)

### Description

- adds blockExplorers option on registry init

### Drive-by changes

- none

### Related issues

- none

### Backward compatibility

- yes

### Testing

- manual
pull/4131/merge
Noah Bayindirli 🥂 4 months ago committed by GitHub
parent 74cd350db1
commit 40255575c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/great-candles-battle.md
  2. 41
      typescript/cli/src/config/chain.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': minor
---
Adds blockExplorers option on registry init.

@ -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,

Loading…
Cancel
Save