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..c69781b56 100644 --- a/packages/cli/src/command-helpers/abi.ts +++ b/packages/cli/src/command-helpers/abi.ts @@ -151,7 +151,12 @@ export const getContractNameForAddress = async ( ): Promise => { try { const contractSourceCode = await fetchSourceCodeFromEtherscan(network, address); - const contractName = contractSourceCode.result[0].ContractName; + let contractName = contractSourceCode.result[0].ContractName; + // Some explorers will return the full path of the contract instead of just the name + const regex = /^contracts\/(?.+)\.sol:\1$/; + + if (regex.test(contractName)) contractName = regex.exec(contractName)?.groups?.contract; + logger('Successfully getContractNameForAddress. contractName: %s', contractName); return contractName; } catch (error) {