简体   繁体   中英

Get Current Token Owner for a given NFT Contract

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

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM