diff --git a/clients/js/src/cmds/verifyVaa.ts b/clients/js/src/cmds/verifyVaa.ts index 07700a18e8..ed86a29e7a 100644 --- a/clients/js/src/cmds/verifyVaa.ts +++ b/clients/js/src/cmds/verifyVaa.ts @@ -1,14 +1,19 @@ -// The verify-vaa command invokes the parseAndVerifyVM method on the core contract on Ethereum to verify the specified VAA. +// The verify-vaa command invokes the parseAndVerifyVM method on the core contract on the specified EVM chain to verify the specified VAA. import { Implementation__factory } from "@certusone/wormhole-sdk/lib/esm/ethers-contracts"; -import { CONTRACTS } from "@certusone/wormhole-sdk/lib/esm/utils/consts"; +import { + CONTRACTS, + CHAINS, + assertChain, + assertEVMChain +} from "@certusone/wormhole-sdk/lib/esm/utils/consts"; import { ethers } from "ethers"; import yargs from "yargs"; import { NETWORKS, NETWORK_OPTIONS } from "../consts"; import { assertNetwork } from "../utils"; export const command = "verify-vaa"; -export const desc = "Verifies a VAA by querying the core contract on Ethereum"; +export const desc = "Verifies a VAA by querying the core contract on the specified EVM chain"; export const builder = (y: typeof yargs) => y .option("vaa", { @@ -17,22 +22,41 @@ export const builder = (y: typeof yargs) => type: "string", demandOption: true, }) - .option("network", NETWORK_OPTIONS); + .option("network", NETWORK_OPTIONS) + .option("chain", { + alias: "c", + describe: "chain name", + choices: Object.keys(CHAINS) as ChainName[], + demandOption: true, + } as const) + .option("contract-address", { + alias: "a", + describe: "Contract to verify VAA on (override config)", + type: "string", + demandOption: false, + }) + .option("rpc", { + describe: "RPC endpoint", + type: "string", + demandOption: false, + }) export const handler = async ( argv: Awaited["argv"]> ) => { - const network = argv.network.toUpperCase(); + const chain = argv.chain; + assertChain(chain); + assertEVMChain(chain); + + const network = (argv.network ?? "mainnet").toUpperCase(); assertNetwork(network); - const buf = Buffer.from(String(argv.vaa), "hex"); - const contract_address = CONTRACTS[network].ethereum.core; + const rpc = argv.rpc ?? NETWORKS[network][chain].rpc; + const contract_address = argv["contract-address"] ?? CONTRACTS[network][chain].core; if (!contract_address) { - throw Error(`Unknown core contract on ${network} for ethereum`); + throw Error(`Unknown core contract on ${network} for ${chain}`); } - - const provider = new ethers.providers.JsonRpcProvider( - NETWORKS[network].ethereum.rpc - ); + const buf = Buffer.from(String(argv.vaa), "hex"); + const provider = new ethers.providers.JsonRpcProvider(rpc); const contract = Implementation__factory.connect(contract_address, provider); const result = await contract.parseAndVerifyVM(buf); if (result[1]) {