UNPKG

p-sdk-wallet

Version:

A comprehensive wallet SDK for React Native (pwc), supporting multi-chain and multi-account features.

242 lines (241 loc) 10.1 kB
import { ChainId } from '../../config/chains'; import { NFTDetailExtended, NFTOptions, NFTBalance } from '../../types/nft'; import { Vault } from '../../Vault'; /** * Pure blockchain NFT service * Reads all data directly from smart contracts without third-party APIs */ export declare class NFTService { private chainService?; private vault?; private chainId; /** * Creates a new NFTService instance. * @param chainId - The chain ID to operate on * @param vault - Optional vault instance for write operations * @param fromAddress - Optional sender address for write operations */ constructor(chainId: ChainId, vault?: Vault, fromAddress?: string); /** * Initialize chain service for write operations * @param vault - The vault instance * @param fromAddress - The sender's address */ private initializeChainService; /** * Initialize chain service for write operations after construction * @param vault - The vault instance * @param fromAddress - The sender's address */ initializeForWrite(vault: Vault, fromAddress: string): Promise<void>; /** * Gets comprehensive NFT detail by reading directly from blockchain. * @param contractAddress - NFT contract address * @param tokenId - Token ID (string) * @param options - Optional parameters for additional data * @param options.includeMetadata - Whether to fetch and include metadata (default: false) * @param options.includeHistory - Whether to fetch transaction history (default: false) * @param options.includeCollection - Whether to fetch collection information (default: false) * @returns Promise resolving to extended NFT detail * @example * ```typescript * const nftDetail = await nftService.getNFTDetail( * '0xContract...', * '123', * { includeMetadata: true, includeHistory: true } * ); * console.log('NFT:', nftDetail.name, 'Owner:', nftDetail.owner); * ``` */ getNFTDetail(contractAddress: string, tokenId: string, options?: NFTOptions): Promise<NFTDetailExtended>; /** * Gets on-chain NFT data directly from smart contract * @param contractAddress - NFT contract address * @param tokenId - Token ID * @returns Promise resolving to on-chain data */ private getOnChainData; /** * Gets EVM NFT on-chain data * @param contractAddress - NFT contract address * @param tokenId - Token ID * @returns Promise resolving to on-chain data */ private getEVMOnChainData; /** * Gets Solana NFT on-chain data * @param contractAddress - NFT mint address * @param tokenId - Token ID (not used for Solana) * @returns Promise resolving to on-chain data */ private getSolanaOnChainData; /** * Resolves metadata from tokenURI (IPFS or HTTP) * @param tokenURI - Token URI * @returns Promise resolving to metadata */ private resolveMetadata; /** * Gets transaction history from blockchain events * @param contractAddress - NFT contract address * @param tokenId - Token ID * @returns Promise resolving to transaction history */ private getTransactionHistory; /** * Gets collection information from contract * @param contractAddress - NFT contract address * @returns Promise resolving to collection info */ private getCollectionInfo; /** * Gets NFT balance for an address from a specific contract. * Supports both ERC-721 and ERC-1155 contracts. * @param address - Wallet address to check balance for * @param contractAddress - NFT contract address * @param tokenId - (Optional) Token ID for ERC-1155 contracts * @returns Promise resolving to NFT balance information * @example * ```typescript * // For ERC-721 * const balance = await nftService.getNFTBalance('0xAccount...', '0xContract...'); * console.log('ERC-721 Count:', balance.count); * * // For ERC-1155 * const balance = await nftService.getNFTBalance('0xAccount...', '0xContract...', '123'); * console.log('ERC-1155 Balance:', balance.count); * ``` */ getNFTBalance(address: string, contractAddress: string, tokenId?: string): Promise<NFTBalance>; /** * Gets ERC-1155 token balance for a specific address and token ID. * @param address - Wallet address to check balance for * @param contractAddress - ERC-1155 contract address * @param tokenId - Token ID to check balance for * @returns Promise resolving to the balance amount as bigint * @example * ```typescript * const balance = await nftService.getERC1155Balance('0xAccount...', '0xContract...', '123'); * console.log('ERC-1155 Balance:', balance.toString()); * ``` */ getERC1155Balance(address: string, contractAddress: string, tokenId: string): Promise<bigint>; /** * Gets all ERC-1155 token balances for an address from a specific contract. * @param address - Wallet address to check balances for * @param contractAddress - ERC-1155 contract address * @param tokenIds - Array of token IDs to check * @returns Promise resolving to array of balance objects * @example * ```typescript * const balances = await nftService.getERC1155Balances('0xAccount...', '0xContract...', ['123', '456', '789']); * balances.forEach(balance => { * console.log(`Token ${balance.tokenId}: ${balance.amount.toString()}`); * }); * ``` */ getERC1155Balances(address: string, contractAddress: string, tokenIds: string[]): Promise<Array<{ tokenId: string; amount: bigint; }>>; /** * Gets mint timestamp from blockchain * @param contractAddress - NFT contract address * @param tokenId - Token ID * @returns Promise resolving to mint timestamp */ private getMintTimestamp; /** * Gets last transfer timestamp from blockchain * @param contractAddress - NFT contract address * @param tokenId - Token ID * @returns Promise resolving to last transfer timestamp */ private getLastTransferTimestamp; /** * Estimates gas cost for transferring an NFT * @param fromAddress - The sender's address * @param toAddress - The recipient's address * @param contractAddress - The NFT contract address * @param tokenId - The token ID to transfer * @param amount - (Optional) Amount to transfer (for ERC-1155, default 1 for ERC-721) * @returns Promise resolving to the estimated gas cost as bigint * @example * ```typescript * const gasEstimate = await nftService.estimateGasForTransfer( * '0xSender...', * '0xRecipient...', * '0xContract...', * '123' * ); * console.log('Estimated gas:', gasEstimate.toString()); * ``` */ estimateGasForTransfer(fromAddress: string, toAddress: string, contractAddress: string, tokenId: string, amount?: string): Promise<bigint>; /** * Estimates gas cost for various NFT operations * @param operation - The operation to estimate gas for * @param contractAddress - The NFT contract address * @param params - Operation-specific parameters * @returns Promise resolving to the estimated gas cost as bigint * @example * ```typescript * // Estimate gas for transfer * const transferGas = await nftService.estimateGas('transfer', contractAddress, { * fromAddress: '0xSender...', * toAddress: '0xRecipient...', * tokenId: '123' * }); * * // Estimate gas for approve * const approveGas = await nftService.estimateGas('approve', contractAddress, { * toAddress: '0xSpender...', * tokenId: '123' * }); * ``` */ estimateGas(operation: 'transfer' | 'approve' | 'setApprovalForAll', contractAddress: string, params: { fromAddress?: string; toAddress: string; tokenId?: string; amount?: string; approved?: boolean; }): Promise<bigint>; /** * Transfers an NFT using Vault (RECOMMENDED). Supports both ERC-721 and ERC-1155. * @param fromAddress - The sender's address * @param toAddress - The recipient's address * @param contractAddress - The NFT contract address * @param tokenId - The token ID to transfer * @param amount - (Optional) Amount to transfer (for ERC-1155, default 1 for ERC-721) * @returns Promise resolving to the transaction response */ transferNFTWithVault(fromAddress: string, toAddress: string, contractAddress: string, tokenId: string, amount?: string): Promise<any>; /** * @deprecated Use transferNFTWithVault instead for better security * Transfers an NFT from one address to another. Supports both ERC-721 and ERC-1155. * @param fromAddress - The sender's address * @param toAddress - The recipient's address * @param contractAddress - The NFT contract address * @param tokenId - The token ID to transfer * @param amount - (Optional) Amount to transfer (for ERC-1155, default 1 for ERC-721) * @returns Promise resolving to the transaction response */ transferNFT(fromAddress: string, toAddress: string, contractAddress: string, tokenId: string, amount?: string): Promise<any>; /** * Checks if an address is owner or approved for ERC-1155 token * @param address - Address to check * @param contractAddress - ERC-1155 contract address * @param tokenId - Token ID * @returns Promise resolving to boolean indicating if address can transfer */ canTransferERC1155(address: string, contractAddress: string, tokenId: string): Promise<boolean>; /** * Creates a contract instance with wallet for gas estimation * @param contractAddress - Contract address * @param abi - Contract ABI * @param fromAddress - Address to use for signing * @returns Promise resolving to contract instance with wallet */ private createContractWithWallet; }