Skip to content

Commit 93271b0

Browse files
authored
Support parsing full path contract name from block explorers (#1771)
* Replace regex with index and substring In case name of the file doesn't match the actual contract name, the regex would not be valid. Instead, we just pick the contract name following colon.
1 parent 098b433 commit 93271b0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/cyan-spoons-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': patch
3+
---
4+
5+
Support parsing full path contract name from block explorers

packages/cli/src/command-helpers/abi.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ export const getContractNameForAddress = async (
151151
): Promise<string> => {
152152
try {
153153
const contractSourceCode = await fetchSourceCodeFromEtherscan(network, address);
154-
const contractName = contractSourceCode.result[0].ContractName;
154+
let contractName: string = contractSourceCode.result[0].ContractName;
155+
156+
// Some explorers will return the full path of the contract instead of just the name
157+
// Example: contracts/SyncSwapRouter.sol:SyncSwapRouter
158+
if (contractName.includes(':'))
159+
contractName = contractName.substring(contractName.lastIndexOf(':') + 1);
160+
155161
logger('Successfully getContractNameForAddress. contractName: %s', contractName);
156162
return contractName;
157163
} catch (error) {

0 commit comments

Comments
 (0)