Build with EPS #1 - check an NFT balance

Use EPS to check ERC721 balances

Build with EPS #1 - check an NFT balance
Photo by Elina Emurlaeva / Unsplash

Want to integrate EPS in your project? Great! There is a wealth of technical information in our gitbook, but maybe you want the TLDR?

Sure you do. Come on, let's get EPS in there. It might take you less than five minutes....

The below instructions are for solidity, but apply just as well to external smart contract calls, for example from javascript / typescript.

Checking an NFT balance

A common use case for EPS is token gating, i.e. only allowing something to happen if a user holds a given token, or a defined balance of a token.

This could be allowing a wallet to register for an allowlist if they hold a bored ape. Or entry to the app if they hold a byWassie.

In simple implementations you may be doing something like this to get the holder's balance of an NFT:

uint256 userBalance = IERC721(collectionAddress).balanceOf(userAddress); 

To use EPS you just need the following changes:

Import the EPS portal.

This provides a valid EPS object. (EPS is at the same address on all supported chains, no need to hunt through docs to find the right address to add to your constructor, it's already taken care of).

import "@eternalproxy/contracts/EPSPortal.sol";
Change the balance lookup to use EPS

Alter your balance lookup to the below:

uint256 userBalance = epsPortal.beneficiaryBalanceOf(collectionAddress, userAddress, 0);

And that's it.

The EPS Portal is 100% backwards compatible, and will return holders balances correctly whether the address has an EPS proxy or not.

If there is no proxy in place the address gets its balance as normal.

If there is a proxy in place the address gets the sum of it's native balance (i.e. at that address) plus that held on the cold wallet.

Just like that, your users can prove they own assets without using the wallet that holds them

Stay safe out there.