File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { erc20bytecode } from "../../../constants/bytecodes/erc20";
66import { TransactionService } from "../../../services/transaction.service" ;
77import { getBlockExplorerUrl , getContractAddressFromEvent } from "../../../utils/other" ;
88import { logRequest , logStep , logError } from '../../../utils/loggingUtils' ;
9- import { verifyContract } from "../../../utils/contractVerification" ;
9+ import { isContractVerified , verifyContract } from "../../../utils/contractVerification" ;
1010import { erc20JsonInputMetadata } from "../../../constants/contractJsonInputs/erc20" ;
1111
1212type ERC20DeployRequestBody = {
@@ -150,7 +150,7 @@ export async function erc20Deploy(fastify: FastifyInstance) {
150150
151151 logStep ( request , 'Deploy transaction success' , { txHash : receipt ?. hash } ) ;
152152
153- if ( process . env . VERIFY_CONTRACT_ON_DEPLOY === 'true' ) {
153+ if ( process . env . VERIFY_CONTRACT_ON_DEPLOY === 'true' && ! isContractVerified ( deployedContractAddress , chainId ) ) {
154154 logStep ( request , 'Verifying contract' , {
155155 chainId,
156156 contractAddress : deployedContractAddress ,
Original file line number Diff line number Diff line change @@ -42,6 +42,22 @@ export const verifyContract = async (params: VerifyContractParams) => {
4242 return response ;
4343}
4444
45+ export const getContractSourceCode = async ( contractAddress : string , chainId : string ) => {
46+ const url = `${ ETHERSCAN_V2_API } ?chainid=${ chainId } &module=contract&action=getsourcecode&address=${ contractAddress } &apikey=${ process . env . ETHERSCAN_API_KEY } ` ;
47+ console . log ( 'URL' , url ) ;
48+ const response = await fetch ( url , {
49+ method : 'GET' ,
50+ } )
51+ . then ( res => res . json ( ) )
52+ . catch ( console . error ) ;
53+ return response . result [ 0 ] . SourceCode ;
54+ }
55+
56+ export const isContractVerified = async ( contractAddress : string , chainId : string ) => {
57+ const sourceCode = await getContractSourceCode ( contractAddress , chainId ) ;
58+ return sourceCode !== null && sourceCode !== undefined ;
59+ }
60+
4561/**
4662 * Extracts the first source file from the sources object and returns it in the format "contract/{name.sol}:{name}".
4763 * @param sources The sources object from the contract JSON input.
You can’t perform that action at this time.
0 commit comments