UNPKG

opensea-js

Version:

TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data

105 lines (104 loc) 4.46 kB
import { BigNumberish, Overrides } from "ethers"; import { AssetWithTokenStandard } from "../types"; import { SDKContext } from "./context"; /** * Asset transfer and approval operations */ export declare class AssetsManager { private context; constructor(context: SDKContext); /** * Get an account's balance of any Asset. This asset can be an ERC20, ERC1155, or ERC721. * @param options * @param options.accountAddress Account address to check * @param options.asset The Asset to check balance for. tokenStandard must be set. * @returns The balance of the asset for the account. * * @throws Error if the token standard does not support balanceOf. */ getBalance({ accountAddress, asset, }: { accountAddress: string; asset: AssetWithTokenStandard; }): Promise<bigint>; /** * Transfer an asset. This asset can be an ERC20, ERC1155, or ERC721. * @param options * @param options.asset The Asset to transfer. tokenStandard must be set. * @param options.amount Amount of asset to transfer. Not used for ERC721. * @param options.fromAddress The address to transfer from * @param options.toAddress The address to transfer to * @param options.overrides Transaction overrides, ignored if not set. */ transfer({ asset, amount, fromAddress, toAddress, overrides, }: { asset: AssetWithTokenStandard; amount?: BigNumberish; fromAddress: string; toAddress: string; overrides?: Overrides; }): Promise<void>; /** * Bulk transfer multiple assets using OpenSea's TransferHelper contract. * This method is more gas-efficient than calling transfer() multiple times. * Note: All assets must be approved for transfer to the OpenSea conduit before calling this method. * @param options * @param options.assets Array of assets to transfer. Each asset must have tokenStandard set. * @param options.fromAddress The address to transfer from * @param options.overrides Transaction overrides, ignored if not set. * @returns Transaction hash of the bulk transfer * * @throws Error if any asset is missing required fields (tokenId for NFTs, amount for ERC20/ERC1155). * @throws Error if any asset is not approved for transfer to the OpenSea conduit. * @throws Error if the fromAddress is not available through wallet or provider. */ bulkTransfer({ assets, fromAddress, overrides, }: { assets: Array<{ asset: AssetWithTokenStandard; toAddress: string; amount?: BigNumberish; }>; fromAddress: string; overrides?: Overrides; }): Promise<string>; /** * Batch approve multiple assets for transfer to the OpenSea conduit. * This method checks which assets need approval and batches them efficiently: * - 0 approvals needed: Returns early * - 1 approval needed: Sends single transaction * - 2+ approvals needed: Uses Multicall3 to batch all approvals in one transaction * * @param options * @param options.assets Array of assets to approve for transfer * @param options.fromAddress The address that owns the assets * @param options.overrides Transaction overrides, ignored if not set. * @returns Transaction hash of the approval transaction, or undefined if no approvals needed * * @throws Error if the fromAddress is not available through wallet or provider. */ batchApproveAssets({ assets, fromAddress, overrides, }: { assets: Array<{ asset: AssetWithTokenStandard; amount?: BigNumberish; }>; fromAddress: string; overrides?: Overrides; }): Promise<string | undefined>; /** * Check if an asset is approved for transfer to a specific operator (conduit). * @param asset The asset to check approval for * @param owner The owner address * @param operator The operator address (conduit) * @param amount Optional amount for ERC20 tokens * @returns True if approved, false otherwise */ private checkAssetApproval; /** * Get a TransferHelper contract instance. * @returns Contract instance for TransferHelper */ private getTransferHelperContract; /** * Get a Multicall3 contract instance. * @returns Contract instance for Multicall3 */ private getMulticall3Contract; }