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

getOwnersForContract returns the same list of addresses for any block height #436

Open
izcoser opened this issue Jul 10, 2024 · 2 comments
Labels
bug Something isn't working no-issue-activity

Comments

@izcoser
Copy link

izcoser commented Jul 10, 2024

[REQUIRED] Environment

  • Browser version:
  • Alchemy SDK version: 3.3.1

[REQUIRED] Describe the problem

Code for getting the owners of an NFT collection at a specific block height always returns the same list, presumably the owners at the latest block, even if I input a block height before the contract existed.

How to reproduce:

import dotenv from 'dotenv';
import { Alchemy, Network } from "alchemy-sdk";

dotenv.config();

const config = {
    apiKey: process.env.ALCHEMY_KEY,
    network: Network.ETH_MAINNET,
};
const alchemy = new Alchemy(config);

const main = async () => {

    // BAYC contract address
    const address = "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D";

    // Block number or height
    const block = "1";

    // Get owners 
    const owners = await alchemy.nft.getOwnersForContract(address, { block: block });
    console.log(owners);
};

  const runMain = async () => {
      try {
          await main();
          process.exit(0);
      } catch (error) {
          console.log(error);
          process.exit(1);
      }
  };

runMain();

Also important to note that the documentation seems outdated, because it is calling getOwnersForContract with arguments that do not match the function signature:
const owners = await alchemy.nft.getOwnersForContract(address, false, block);

Thankfully, the endpoint at ${baseURL}/getOwnersForCollection/?contractAddress=${address}&block=${block} seems to work correctly and gives varying lists of owners depending on the block I try.

@izcoser izcoser added the bug Something isn't working label Jul 10, 2024
@izcoser
Copy link
Author

izcoser commented Jul 10, 2024

I have followed all functions calls and arrived at sendAxiosRequest, and to my surprise Alchemy's SDK was using API v3.
Below is the configuration to the axios request (edited the source to add a console log).

{
  configBad: {
    timeout: 0,
    headers: {
      'Accept-Encoding': 'gzip',
      'Alchemy-Ethers-Sdk-Version': '3.3.1',
      'Alchemy-Ethers-Sdk-Method': 'getOwnersForContract'
    },
    method: 'GET',
    url: 'https://eth-mainnet.g.alchemy.com/nft/v3/mykey../getOwnersForContract',
    params: {
      block: '1',
      contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D'
    }
  }
}

This will ignore the params because the block param was removed in V3. This is why my fetch directly on the URL, using v2, worked. So the SDK's docs are still about V2 but the calls are done on V3, or am I confused?

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working no-issue-activity
Projects
None yet
Development

No branches or pull requests

1 participant