LogoLogo
SupportGithubSign InGet Access
  • Introduction
  • GETTING STARTED
    • SDK Quick Start
    • API Quick Start
  • Guides
    • Web
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Web authentication methods
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Configure a custom subdomain
      • Eject a wallet
      • Using the EIP-1193 Provider
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • iOS
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Manage ERC20 tokens
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
          • Passkey + Enclave Storage
        • Recover a wallet
      • Troubleshooting Tips
      • Feature Flags
    • Android
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • React Native
      • Create a wallet
      • Send tokens
      • Sign a transaction
      • Simulate a transaction
      • Back up a wallet
      • Recover a wallet
      • Cross-device sessions
      • Manage wallet lifecycle states
      • Connect with WalletConnect
      • Build a WebView
      • Perform swaps
      • Add custom signature hooks
      • MPC progress callbacks
      • Portal API methods
      • Eject a wallet
      • Legacy documentation
        • Back up a wallet
          • Backup Options
        • Recover a wallet
    • Enclave MPC API
      • Create a client
      • Create a wallet
      • Send tokens
      • Sign Ethereum transactions
      • Sign Solana transactions
      • Sign Tron transactions
      • Sign Stellar Transaction
      • Concurrent Transactions
      • Back up a wallet
      • Eject a wallet
  • Reference
    • iOS
      • createWallet
      • backupWallet
      • recoverWallet
      • ejectPrivateKeys
      • registerBackupMethod
      • setGDriveConfiguration
      • setPasskeyConfiguration
      • setPasskeyAuthenticationAnchor
      • setPassword
      • availableRecoveryMethods
      • doesWalletExist
      • isWalletBackedUp
      • isWalletOnDevice
      • isWalletRecoverable
      • getBalances
      • getAssets
      • getNftAssets
      • getTransactions
      • sendSol
      • evaluateTransaction
      • buildEip155Transaction
      • buildSolanaTransaction
      • getWalletCapabilities
    • Android
      • Reference Documentation
    • React Native
      • @portal-hq/core
      • Storage adapters
        • Cloud storage
          • @portal-hq/gdrive-storage
          • @portal-hq/icloud-storage
        • Mobile storage
          • @portal-hq/keychain
          • @portal-hq/mobile-key-values
    • Enclave MPC API
      • V1 endpoints
    • Client API
      • V3 endpoints
      • V1 endpoints
    • Custodian API
      • V3 endpoints
      • V1 endpoints
    • Swaps API
      • V3 endpoints
      • V1 endpoints
  • Resources
    • Flutter
      • iOS
      • Android
    • Error codes
      • Overview
      • Legacy Documentation
        • MPC errors
        • Network errors
        • General errors
        • Encryption errors
        • Portal Connect errors
    • Portal's MPC architecture
    • Authentication and API Keys
    • Self-Managed Backups
    • Alert Webhooks
    • Wallet lifecycle
    • Backup options
      • Password/PIN
      • GDrive
      • iCloud
      • Passkey + Enclave
    • WalletConnect metadata
    • Advanced security scanning
    • Account abstraction
    • Security firewall
    • Eject
    • Security
    • Blockchain support
    • Chain ID formatting
    • Testnet faucets
    • Going to Production
    • Rate Limits
    • Multi-backup migration guide
    • Multi-wallet migration guides
      • Migrating from Android SDK v3.x.x to v4.x.x
      • Migrating from iOS SDK v3.0.x to v3.2.x
  • Support
    • Changelog
      • Android
      • iOS
      • React Native
      • Web
      • Past Releases
        • 2024 Releases
        • 2023 Releases
    • Celo Hackathon Hub
    • Glossary
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Reference
  2. iOS

getNftAssets

Retrieves NFT assets for the specified blockchain. This method fetches all NFTs (Non-Fungible Tokens) owned by the wallet.

Function Signature

public func getNftAssets(
    _ chainId: String
) async throws -> [NftAsset]

Parameters

  • chainId: The chain identifier in CAIP-2 format (e.g., "eip155:1" for Ethereum mainnet, "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" for Solana mainnet)

Returns

An array of NftAsset objects, each containing:

  • nftID: Unique identifier for the NFT

  • name: NFT name

  • description: NFT description

  • imageURL: URL of the NFT image

  • chainID: Blockchain identifier

  • contractAddress: NFT contract address

  • tokenID: Token identifier

  • collection: Collection information

  • lastSale: Last sale details containing:

    • price: Sale price

    • currency: Currency used

    • date: Sale date

  • rarity: Rarity information:

    • rank: Rarity rank

    • score: Rarity score

  • floorPrice: Current floor price information:

    • price: Floor price value

    • currency: Currency

  • detailedInfo: Extended NFT information including:

    • ownerCount: Number of owners

    • tokenCount: Total tokens

    • createdDate: Creation date

    • attributes: NFT attributes

    • owners: Ownership details

    • extendedCollectionInfo: Collection metadata

    • extendedSaleInfo: Sale history

    • marketplaceInfo: Marketplace listings

    • mediaInfo: Media preview URLs and metadata

Example Usage

// Basic NFT fetch and display
do {
    let nfts = try await portal.getNftAssets("eip155:1")
    
    print("Your NFT Collection:")
    for nft in nfts {
        print("\nNFT: \(nft.name ?? "Unnamed")")
        if let description = nft.description {
            print("Description: \(description)")
        }
        if let imageURL = nft.imageURL {
            print("Image: \(imageURL)")
        }
        
        // Display rarity information if available
        if let rarity = nft.rarity {
            if let rank = rarity.rank {
                print("Rarity Rank: #\(rank)")
            }
            if let score = rarity.score {
                print("Rarity Score: \(score)")
            }
        }
        
        // Display current market value
        if let floor = nft.floorPrice,
           let price = floor.price,
           let currency = floor.currency {
            print("Floor Price: \(price) \(currency)")
        }
    }
} catch {
    print("Error fetching NFTs: \(error)")
}

// Example with marketplace information
do {
    let nfts = try await portal.getNftAssets("eip155:1")
    
    for nft in nfts {
        print("\nNFT: \(nft.name ?? "Unnamed")")
        
        // Display marketplace listings
        if let marketplaceInfo = nft.detailedInfo?.marketplaceInfo {
            print("Listed on:")
            for listing in marketplaceInfo {
                if let name = listing.marketplaceName,
                   let floorPrice = listing.floorPrice,
                   let price = floorPrice.value,
                   let token = floorPrice.paymentToken {
                    print("- \(name): \(price) \(token.symbol ?? "")")
                    if let usdValue = floorPrice.valueUsdCents {
                        print("  USD Value: $\(Double(usdValue) / 100)")
                    }
                }
            }
        }
        
        // Display media previews
        if let previews = nft.detailedInfo?.mediaInfo?.previews {
            print("\nMedia Previews:")
            if let small = previews.imageSmallURL {
                print("Small: \(small)")
            }
            if let medium = previews.imageMediumURL {
                print("Medium: \(medium)")
            }
            if let large = previews.imageLargeURL {
                print("Large: \(large)")
            }
        }
    }
} catch {
    print("Error processing NFTs: \(error)")
}

// Example with collection statistics
do {
    let nfts = try await portal.getNftAssets("eip155:1")
    
    // Group NFTs by collection
    let collections = Dictionary(grouping: nfts) { 
        $0.collection?.name ?? "Unknown Collection" 
    }
    
    for (collectionName, collectionNFTs) in collections {
        print("\nCollection: \(collectionName)")
        
        if let firstNFT = collectionNFTs.first,
           let collectionInfo = firstNFT.detailedInfo?.extendedCollectionInfo {
            print("Statistics:")
            print("Distinct Owners: \(collectionInfo.distinctOwnerCount ?? 0)")
            print("Distinct NFTs: \(collectionInfo.distinctNftCount ?? 0)")
            print("Total Supply: \(collectionInfo.totalQuantity ?? 0)")
            
            // Display social links
            var socials: [String] = []
            if let twitter = collectionInfo.twitterUsername {
                socials.append("Twitter: @\(twitter)")
            }
            if let discord = collectionInfo.discordURL {
                socials.append("Discord: \(discord)")
            }
            if let instagram = collectionInfo.instagramUsername {
                socials.append("Instagram: @\(instagram)")
            }
            
            if !socials.isEmpty {
                print("\nSocial Links:")
                socials.forEach { print($0) }
            }
        }
        
        // Calculate collection value
        let totalValue = collectionNFTs.compactMap { 
            $0.floorPrice?.price 
        }.reduce(0, +)
        
        if totalValue > 0 {
            print("\nEstimated Collection Value: \(totalValue)")
        }
    }
} catch {
    print("Error analyzing collections: \(error)")
}

Implementation Notes

  • All fields in the NFT response are optional and should be safely unwrapped

  • The method provides rich metadata useful for marketplace integration

  • Floor prices and sale history can be used for portfolio valuation

  • Media previews include multiple resolutions for efficient loading

PreviousgetAssetsNextgetTransactions

Last updated 4 months ago

Was this helpful?