0

I am attempting to cross-reference my local database and confirm ownership of an NFT token. I have the contract address and the users wallet address and Im trying to get a returned array of all current tokens owned by that user for that given contract. If I visit the etherscan contract page I can manually enter the address of the given wallet and get just what I need:

r

Is there a simple API I can use to get just the current owner of all tokens under a contract? I tried the api from Etherscan below however that doesn't return current ownership, but a list of the transactions.

https://api-rinkeby.etherscan.io/api?module=account&action=tokennfttx&contractaddress=0x1481e948f2cc7886D454532714D011A7D8e9ec2e&address=0xe93FBC84f5743Ec68a03260f4A9A23c708593d02&page=1&offset=10000&startblock=0&endblock=27025780&sort=asc&apikey=$myapikey

Chris
  • 833
  • 2
  • 17
  • 37
  • Does this answer your question? [how can we get token holders from token?](https://stackoverflow.com/questions/68860386/how-can-we-get-token-holders-from-token) – Petr Hejda Mar 23 '22 at 08:20

2 Answers2

1

Try using to OpenSea's Retrieving assets endpoint.

const { data } = await axios.get(
    `https://api.opensea.io/api/v1/collections?asset_owner=${userAddress}`,
    {
        headers: {
            Accept: "application/json",
            "X-API-KEY": process.env.OPENSEA_API,
        },
    }
);

This returns an array of a given user's assets.

Another option is to Get a list of 'ERC721 - Token Transfer Events' by Address using Etherscan API

const tokenTransfersByAddress = async (contractaddress, address) => {
        try {
            const options = {
                method: "GET",
                url: "https://api.etherscan.io/api",
                params: {
                    module: "account",
                    action: "tokennfttx",
                    contractaddress,
                    address,
                    page: "1",
                    offset: "10",
                    sort: "asc",
                    apikey: process.env.ETHERSCAN,
                },
            };

            const { data } = await axios.request(options);
            return data.result;
        } catch (error) {
            console.log(error);
            return [];
        }
    };

This returns an array of transactions a given user has made.

Hope this helps!

Rtroman14
  • 168
  • 1
  • 8
0

You can use a simple tool holders.at to take and export all NFT token holders at any block. It supports Ethereum and Polygon collections.

jackqack
  • 529
  • 5
  • 6