Created
April 28, 2025 09:22
-
-
Save porco-rosso-j/814a943322177360b3cc43025d9d71e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-console */ | |
import { readFileSync } from "fs"; | |
import { join } from "path"; | |
import { | |
callExplorerApi, | |
generateVerifyInstancePayload, | |
generateVerifyInstanceUrl, | |
} from "../src/api-utils"; | |
import { config } from "../src/config"; | |
import { | |
ArtifactObject, | |
ContractDeployerMetadata, | |
VerifyInstanceArgs, | |
} from "../src/types"; | |
// npm run verify-deployment 0x2a0a0b73257c8171817a4703832808221d37cb2b1c7776c29e633b6d1ae21ec3 | |
// Load the token contract artifact directly from the known path | |
const tokenContractArtifactPath = join( | |
__dirname, | |
"./kernel_account-KernelAccount.json" | |
); | |
const tokenContractArtifactJson = JSON.parse( | |
readFileSync(tokenContractArtifactPath, "utf8") | |
); | |
// Parse command line arguments | |
const args = process.argv.slice(2); | |
const contractInstanceAddress = args[0] || ""; // Default empty string | |
if (!contractInstanceAddress) { | |
console.error("Error: Contract instance address is required"); | |
console.error("Usage: npm run verify-deployment <contractInstanceAddress>"); | |
process.exit(1); | |
} | |
const contractLoggingName = "Kernel Account"; | |
// HARDCODED EXAMPLES | |
// Example constructor arguments for a Token contract (must be strings) | |
const EXAMPLE_CONSTRUCTOR_ARGS: string[] = []; | |
// Example public keys string | |
const EXAMPLE_PUBLIC_KEYS_STRING = | |
"0x2858f8c97a2772ab022475f2210960e49a2681eaf9ff9feaaaf678c86555d31d"; | |
// Example deployer address | |
const EXAMPLE_DEPLOYER = | |
"0x0000000000000000000000000000000000000000000000000000000000000000"; | |
// Example salt value | |
const EXAMPLE_SALT = | |
"0x0000000000000000000000000000000000000000000000000000000000000001"; | |
// Example deployer metadata | |
const EXAMPLE_DEPLOYER_METADATA: ContractDeployerMetadata = { | |
name: "KernelAccountContract", | |
description: "Account contract for Obsidion Wallet", | |
version: "1.0.0", | |
license: "Apache-2.0", | |
author: "Obsidion Labs Limited", | |
repository: "https://github.com/obsidionlabs/obsidion-wallet", | |
}; | |
const verifyContractInstanceDeployment = async ( | |
contractLoggingName: string, | |
contractInstanceAddress: string, | |
verifyArgs: VerifyInstanceArgs, | |
deployerMetadata: ContractDeployerMetadata | |
): Promise<void> => { | |
const url = generateVerifyInstanceUrl( | |
config.explorerApi.url, | |
contractInstanceAddress | |
); | |
const payload = { | |
verifiedDeploymentArguments: generateVerifyInstancePayload(verifyArgs), | |
deployerMetadata, | |
}; | |
console.log(`Generated URL: ${url}`); | |
console.log(`Payload structure: ${JSON.stringify(Object.keys(payload))}`); | |
console.log( | |
`Constructor args: ${JSON.stringify(verifyArgs.constructorArgs)}` | |
); | |
console.log(`Deployer metadata: ${JSON.stringify(deployerMetadata)}`); | |
const postData = JSON.stringify(payload); | |
await callExplorerApi({ | |
loggingString: `🧐 verifyContractInstanceDeployment ${contractLoggingName}`, | |
urlStr: url, | |
postData, | |
method: "POST", | |
}); | |
}; | |
// Main function | |
void (async (): Promise<void> => { | |
console.log( | |
`Verifying deployment for contract instance address: ${contractInstanceAddress}` | |
); | |
try { | |
// Using hardcoded example values with the correct parameter structure | |
const verifyArgs: VerifyInstanceArgs = { | |
publicKeysString: EXAMPLE_PUBLIC_KEYS_STRING, | |
deployer: EXAMPLE_DEPLOYER, | |
salt: EXAMPLE_SALT, | |
constructorArgs: [], | |
artifactObj: tokenContractArtifactJson as ArtifactObject, | |
}; | |
await verifyContractInstanceDeployment( | |
contractLoggingName, | |
contractInstanceAddress, | |
verifyArgs, | |
EXAMPLE_DEPLOYER_METADATA | |
); | |
console.log("Verification completed successfully!"); | |
} catch (error) { | |
console.error("Error during verification:", error); | |
process.exit(1); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment