diff --git a/.changeset/cyan-spoons-greet.md b/.changeset/cyan-spoons-greet.md new file mode 100644 index 000000000..c4161fd56 --- /dev/null +++ b/.changeset/cyan-spoons-greet.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +Support parsing full path contract name from block explorers diff --git a/packages/cli/src/command-helpers/abi.ts b/packages/cli/src/command-helpers/abi.ts index b30dcb6de..024fcb4f5 100644 --- a/packages/cli/src/command-helpers/abi.ts +++ b/packages/cli/src/command-helpers/abi.ts @@ -151,7 +151,13 @@ export const getContractNameForAddress = async ( ): Promise => { try { const contractSourceCode = await fetchSourceCodeFromEtherscan(network, address); - const contractName = contractSourceCode.result[0].ContractName; + let contractName: string = contractSourceCode.result[0].ContractName; + + // Some explorers will return the full path of the contract instead of just the name + // Example: contracts/SyncSwapRouter.sol:SyncSwapRouter + if (contractName.includes(':')) + contractName = contractName.substring(contractName.lastIndexOf(':') + 1); + logger('Successfully getContractNameForAddress. contractName: %s', contractName); return contractName; } catch (error) {