Giter Site home page Giter Site logo

multicall-example's Introduction

NFT Hack: How to Get The Owner of Multiple ERC-721 Tokens

Get the owner of batch for ERC-721 tokens by using Multicall

Question

Is there a way to get the owner of multiple ERC-721 tokens?

Overview

Most NFTs follow the ERC-721 standard, which must implement certain functions such as Transfer, balanceOf, ownerOf etc. In this example we'll focus on ownerOf which returns the owner (address) of the NFT.

// solidity
function ownerOf(uint256 _tokenId) external view returns (address);

Each _tokenId has an owner. For example, token id 1 belongs to address 0xdD4c825203f97984e7867F11eeCc813A036089D1.

Problem

The problem is you can only get one owner at a time. The diagram below is how a user gets the owner of each token. The user will have to send three separate requests to the blockchain to get the balance of token 1, 2 and 3. This is ok if you have a few tokens but what if there are over 2 million tokens? Not efficient. In short, many lines under Network Request = bad;

1_0SmuZSpqfiSoxd8V8S50NQ

Solution: Multicall

Multicall aggregates results from multiple contract constant function calls. 

Source: https://github.com/makerdao/multicall

Multicall is a smart contract that calls your NFT contract. What makes this efficient is you only need one network request to the blockchain. The Multicall contract will call all of the functions in a loop and return all of the data.

1_XAewrl_BLexvFo_fAI6TrA

Conclusion

Using Multicall is a clever way to get data without multiple network requests. This is especially useful for getting the ownerOf a list of NFTs or functions that only returns one value.

multicall-example's People

Contributors

leon-do avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.