
@solflare-wallet/nft-sdk
NFT SDK used in Solflare wallet.
This SDK accepts a list of mints, triggers fetching NFT metadatas, all JSONs, Metaplex groups,
and does "smart" grouping of everything else using few different rules.
Contents:
Installation
$ npm install @solflare-wallet/nft-sdk
Compatibility with lighthouse-sdk-legacy
This SDK uses @metaplex-foundation/umi@^1.4.1 for V2 compressed NFT support, which may create peer dependency warnings when used alongside lighthouse-sdk-legacy (which requires umi@^0.9.x).
This is expected and safe. The two umi versions are used in separate code paths and don't conflict at runtime.
If you see npm peer dependency warnings during installation:
npm install --legacy-peer-deps
echo "legacy-peer-deps=true" >> .npmrc
{
"overrides": {
"@metaplex-foundation/umi": "^1.4.1"
}
}
Examples
Initialize the library
- Use the default configuration:
import { SolflareNft } from '@solflare-wallet/nft-sdk';
const mints = [new PublicKey(mint1), new PublicKey(mint2)];
const solflare = new SolflareNft({ mints });
- Use other configuration options:
import { SolflareNft } from '@solflare-wallet/nft-sdk';
const solflare = new SolflareNft({
mints,
connection: web3connection
});
Ways to get the data
- SDK exposes .startFetching() method which starts fetching the data and returns a promise with all NFTs and groups.
Waiting for this promise to resolve might take a lot of time for large number of NFTs, so try different method with
listening for changes.
import { SolflareNft } from '@solflare-wallet/nft-sdk';
const solflare = new SolflareNft({ mints });
const response = await solflare.startFetching();
response = {
nfts: [
{
id: 'mint-address-string',
metadataAccount: MetadataAccount,
updateAuthority: PublicKey,
mint: PublicKey,
name: 'NFT name',
symbol: 'symbol',
uri: 'https://uri ...',
sellerFeeBasisPoints: 0,
creators: Creators[],
primarySaleHappened: true,
isMutable: true,
editionNonce: 253,
tokenStandard: TokenStandard | null,
collection: Collection | null,
uses: Uses | null,
metadata: JsonMetadata | null,
group: 'unique-group-identifier-address-or-slug' | null
},
],
groups: [
{
id: 'unique-group-identifier-address-or-slug',
name: 'Group name',
image: 'uri of image used for group',
count: 3,
metaplex: true
},
]
}
- Fetch all data, but listen for change events and update each NFT that received an update
import { SolflareNft, STATUS } from '@solflare-wallet/nft-sdk';
const solflare = new SolflareNft({ mints });
solflare.startFetching();
solflare.on('message', ({ status, payload }) => {
switch (status) {
case STATUS.GLOBAL_START:
console.log('Started fetching.');
break;
case STATUS.METADATA_FINISH:
console.log('Fetched all Metaplex metadata accounts');
console.log('payload', payload);
break;
case STATUS.JSON_FILE_SINGLE_FINISH:
console.log('Fetched single JSON file');
console.log('payload', payload);
break;
case STATUS.JSON_FILE_SINGLE_ERROR:
console.log('Failed to fetch JSON file');
console.log('payload', payload);
break;
case STATUS.JSON_FILES_FINISH:
console.log('Everything finished loading');
console.log('payload', payload);
break;
case STATUS.GLOBAL_FINISH:
console.log('Finished fetching.');
break;
default:
break;
}
});
Compressed NFT Transactions
The SDK provides transaction builders for compressed NFT operations that return V0 transactions.
Transfer Compressed NFT
import { createTransferCompressedNftTransaction } from '@solflare-wallet/nft-sdk';
import { Connection, Keypair } from '@solana/web3.js';
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
const wallet = Keypair.generate();
const tx = await createTransferCompressedNftTransaction({
assetId: 'compressed-nft-asset-id',
walletPublicKey: wallet.publicKey,
destinationPublicKey: recipient.publicKey,
connection,
addressLookupTableAccounts
});
tx.sign([wallet]);
const signature = await connection.sendTransaction(tx);
await connection.confirmTransaction(signature);
Burn Compressed NFT
import { createBurnCompressedNftTransaction } from '@solflare-wallet/nft-sdk';
import { Connection, Keypair } from '@solana/web3.js';
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
const wallet = Keypair.generate();
const tx = await createBurnCompressedNftTransaction({
assetId: 'compressed-nft-asset-id',
walletPublicKey: wallet.publicKey,
connection,
addressLookupTableAccounts
});
tx.sign([wallet]);
const signature = await connection.sendTransaction(tx);
await connection.confirmTransaction(signature);
Note: These functions return VersionedTransaction (V0 format) to support large Merkle tree proofs that exceed legacy transaction size limits. The transactions must be signed before sending, unlike legacy transactions where signers can be passed to sendTransaction().
Learn more