@biolimitless/user-nfts
v0.2.0
Published
signature validators utils
Downloads
2
Readme
@biolimitless/user-nfts
Install
npm i @biolimitless/user-nfts
Utils
For load NFTs list by owner address
function loadAccountNft(
url: string, // provide url depends on environments
account: Address, // provide address of searched user
): Promise<AccountNftDetails[]>
For initialize NFTs list types
function mapAccountNft<T extends string>(
data: AccountNftDetails[], // provide loaded list of NFTs
nftTypes: NftTypes<T>[], // provide types of known NFTs
): AccountNftDetails<T>[]
Types
type AccountNftDetails<T extends string = string> = {
contract: Address
owner: Address
tokenId: string
mintedAt: number // timestamp of mint in seconds
type?: T
}
type NftTypes<T extends string = string> = { nftAddress: Address; type: T }
Address - see core package
Usage example:
const testUrl = 'http://localhost:8000/subgraphs/name/biolimitless'
const testAccount = Address.from('0x47F110C21FE169c2728cFE5C075b38CA1Bdf476e')
const nft1 = Address.from('0xDC64A140AA3E981100A9BECA4E685F962F0CF6C9')
const nft2 = Address.from('0x2279B7A0A67DB372996A5FAB50D91EAA73D2EBE6')
const nftList = await loadAccountNft(testUrl, testAccount)
console.log({ nftList })
/*
{
"nftList": [
{
"contract": Address.from('0xDC64A140AA3E981100A9BECA4E685F962F0CF6C9'),
"owner": Address.from('0x47F110C21FE169c2728cFE5C075b38CA1Bdf476e'),
"tokenId": "1",
"mintedAt": 1722421198
},
{
"contract": Address.from('0x2279B7A0A67DB372996A5FAB50D91EAA73D2EBE6'),
"owner": Address.from('0x47F110C21FE169c2728cFE5C075b38CA1Bdf476e'),
"tokenId": "2",
"mintedAt": 1722421198
}
]
}
*/
const typedList = mapAccountNft(nftList, [
{ nftAddress: nft1, type: 'nft1' },
{ nftAddress: nft2, type: 'nft2' },
])
console.log({ typedList })
/*
{
"nftList": [
{
"contract": Address.from('0xDC64A140AA3E981100A9BECA4E685F962F0CF6C9'),
"owner": Address.from('0x47F110C21FE169c2728cFE5C075b38CA1Bdf476e'),
"tokenId": "1",
"mintedAt": 1722421198,
type: "nft1"
},
{
"contract": Address.from('0x2279B7A0A67DB372996A5FAB50D91EAA73D2EBE6'),
"owner": Address.from('0x47F110C21FE169c2728cFE5C075b38CA1Bdf476e'),
"tokenId": "2",
"mintedAt": 1722421198,
type: "nft2"
}
]
}
*/