@floornfts/get-token-balances
Get Ethereum token balances using the OpenSea and Alchemy API
Installation & Setup
Install
npm i @floornfts/get-token-balances --save
Configuration
Create a new instance of TokenBalanceChecker
and provide the following configuration:
alchemyAPIKey: Your Alchemy API key
import TokenBalanceChecker from '@floornfts/get-token-balances';
const balanceChecker = new TokenBalanceChecker({
alchemyAPIKey: 'YOUR_ALCHEMY_API_KEY',
});
Usage
For most NFTs, you can use the getTokenBalances
method. This will use Alchemy to get the token balances.
You can pass a single contract address or an array of contract addresses.
const [tokenBalance] = await balanceChecker.getTokenBalances(
'0xa0c3122e71fd972e868fddae76e3ed2b174ceaf9',
'0xd640C898B0902bD02f69dE0FE8d0bd560956DB76'
);
const [tokenBalance] = await balanceChecker.getTokenBalances(
[
'0xa0c3122e71fd972e868fddae76e3ed2b174ceaf9',
'0x2d92c4f9f75308d0b9b098b142369032e4f901ff',
],
'0xd640C898B0902bD02f69dE0FE8d0bd560956DB76'
);
Open Sea Storefront NFTs
For NFTs created via OpenSea, you can use the getOSTokenBalances
method. Instead of providing contract addresses, you pass collection slugs.
const [tokenBalance] = await balanceChecker.getOSTokenBalances(
'floor-app',
'0xd640C898B0902bD02f69dE0FE8d0bd560956DB76'
);
ENS names will automatically be resolved
License
MIT