Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph add errors with getaddrinfo ENOTFOUND api-localhost.etherscan.io on localhost #1748

Closed
schmidsi opened this issue Oct 25, 2024 · 4 comments · Fixed by #1751
Closed
Assignees

Comments

@schmidsi
Copy link
Member

Steps to reproduce:

  1. Have a subgraph with network: localhost in subgraph.yaml
  2. Run graph add 0x5FbDB2315678afecb367f032d93F642f64180aa3 (or any other address)

Result:

✖ Failed to fetch ABI from Etherscan: getaddrinfo ENOTFOUND api-localhost.etherscan.io
    Error: getaddrinfo ENOTFOUND api-localhost.etherscan.io
    Code: ENOTFOUND

Expected result:

  • CLI should ask for path to ABI
@schmidsi
Copy link
Member Author

This works:

graph add 0x5FbDB2315678afecb367f032d93F642f64180aa3 --abi /Users/schmidsi/Development/@schmidsi/savp-prototype/packages/hardhat/deployments/localhost/LittleBigPicture.json
✖ Failed to fetch Start Block: Failed to fetch contract creation transaction hash
✔ Start Block · 0
✖ Failed to fetch Contract Name: getaddrinfo ENOTFOUND api-localhost.etherscan.io
✔ Contract Name · SAVP
✔ Running codegen

But the command never exits.

@0237h 0237h added this to Tooling Oct 30, 2024
@0237h 0237h moved this to Bug in Tooling Oct 30, 2024
@0237h
Copy link
Collaborator

0237h commented Oct 30, 2024

Hi @schmidsi,

The error comes from the default case of the getEtherscanLikeAPIUrl method which tries to create a Etherscan URL given the network name (here localhost):

const getEtherscanLikeAPIUrl = (network: string) => {
  switch (network) {
    case 'mainnet':
      return `https://mainnet.abi.pinax.network/api`;
    [...]
    default:
      return `https://api-${network}.etherscan.io/api`; // `localhost` falls into the default case
  }
};

Obviously, this isn't right. ABI should be provided (or asked if missing) in the case of localhost as you mentioned.

After that, the graph add command flow also makes calls to loadStartBlockForContract and loadContractNameForAddress which both resolves to making call to the Etherscan API, which is why you're getting an error as well even after providing the ABI.


To solve this, would you mind clarifying what you're trying to achieve ?

If I understand correctly, your goal is to keep the network set to localhost for local development while also being able to fetch and add external contract datasources ?
In that case, you might have to specify the network you're trying to load the ABI from (e.g. mainnet) before running graph add. That way the CLI knows where to fetch the ABI, startBlock and contract name.

@0237h 0237h self-assigned this Oct 30, 2024
0237h added a commit to 0237h/graph-tooling that referenced this issue Oct 30, 2024
The command will now skip Etherscan lookups if detecting the network
as `localhost`. User will be prompted to enter all relevant information.

Closes graphprotocol#1748
@0237h 0237h moved this from Bug to 👀 In review in Tooling Oct 30, 2024
0237h added a commit that referenced this issue Oct 31, 2024
The command will now skip Etherscan lookups if detecting the network
as `localhost`. User will be prompted to enter all relevant information.

Closes #1748
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Tooling Oct 31, 2024
@schmidsi
Copy link
Member Author

schmidsi commented Nov 1, 2024

loadStartBlockForContract should work on localhost actually. The JSON RPC server usually runs at http://127.0.0.1:8545/.

To answer your questions:

If I understand correctly, your goal is to keep the network set to localhost for local development while also being able to fetch and add external contract datasources ?
Not sure. Yes, I want to keep the network set to localhost, but I want to add another contract deployed on my local dev chain.

In that case, you might have to specify the network you're trying to load the ABI from (e.g. mainnet) before running graph add. That way the CLI knows where to fetch the ABI, startBlock and contract name.
In my scenario, I don't want to interact with mainnet at all. I'm developing some smart contracts locally and want to develop the subgraph in parallel. This is actually the preferred way of subgraph development for new projects in my opinion.

What you are referring to would be if I run a local mainnet fork. In that case, I would set the network to mainnet but point my local Graph Node to my local fork endpoint. That should work out of the box.

@0237h
Copy link
Collaborator

0237h commented Nov 4, 2024

Thanks for the feedback @schmidsi.

loadStartBlockForContract should work on localhost actually. The JSON RPC server usually runs at http://127.0.0.1:8545/.

This method needs the transaction hash where the contract is created (which is what the Etherscan lookup returns) and then makes an RPC call for fetching the start block.

So it could work fully locally if the user provides the correct tx_hash, which is not currently implemented in the flow. But since the user would need to input the tx_hash I think we should rather ask for the block number directly, like it is done now.

Regarding your answers, the implementation that will be available in the next release should be able to cover your use case. Feel free to open new issues if that's not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants