Skip to content

Commit

Permalink
Support parsing full path contract name from block explorers
Browse files Browse the repository at this point in the history
  • Loading branch information
0237h committed Nov 25, 2024
1 parent 098b433 commit a34c9cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cyan-spoons-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

Support parsing full path contract name from block explorers
7 changes: 6 additions & 1 deletion packages/cli/src/command-helpers/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ export const getContractNameForAddress = async (
): Promise<string> => {
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\/(?<contract>.+)\.sol:\1$/;

if (regex.test(contractName)) contractName = regex.exec(contractName)?.groups?.contract;

logger('Successfully getContractNameForAddress. contractName: %s', contractName);
return contractName;
} catch (error) {
Expand Down

0 comments on commit a34c9cf

Please sign in to comment.