npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

solbids-layer2-sdk

v3.1.6

Published

SDK for Solbids Layer 2 Bidding System on Solana

Readme

Solbids Layer 2 SDK

A comprehensive TypeScript SDK for interacting with the Solbids Layer 2 bidding system on Solana.

Installation

npm install @solbids/layer2-sdk
# or
yarn add @solbids/layer2-sdk

Quick Start

import { SolbidsSDK } from "@solbids/layer2-sdk";
import { Connection, PublicKey } from "@solana/web3.js";
import { WalletAdapter } from "@solana/wallet-adapter-base";

// Initialize SDK with wallet address only
const connection = new Connection("https://api.devnet.solana.com");
const walletAddress = new PublicKey("..."); // User's wallet address
const sdk = new SolbidsSDK(connection, walletAddress);

// Build transaction to buy bids
const ownerPublicKey = new PublicKey("..."); // Platform owner's public key
const transaction = await sdk.buyBids(10, ownerPublicKey);

// Sign, send, and confirm with priority fee
const signature = await sdk.signAndSendTransaction(
  transaction,
  wallet, // Wallet adapter with signTransaction method
  300000 // Priority fee in micro-lamports
);
console.log("Transaction:", signature);

// Check bid balance (read-only, no transaction needed)
const balance = await sdk.getBidBalance(ownerPublicKey);
console.log("Bid balance:", balance);

Features

  • ✅ Buy bid credits (Layer 2 bidding)
  • ✅ Place bids on auctions
  • ✅ Create auctions (Standard Token, Token-2022, pNFT, Core NFT)
  • ✅ Claim assets as auction winner (all asset types)
  • ✅ Withdraw assets (all asset types)
  • ✅ Register and manage owners
  • ✅ Create and manage products
  • ✅ Manage auction lifecycle (start, end)
  • ✅ Admin operations (initialize, pause, update config, claim fees)
  • ✅ Query auction, product, owner, and user data
  • ✅ Get vault balances (owner and admin fee vaults)
  • ✅ Bid package system (create discount packages, bulk purchases)
  • ✅ Full TypeScript support
  • ✅ Automatic asset type detection
  • ✅ Complete contract method coverage (41 methods total)

API Reference

Initialization

import { SolbidsSDK } from "@solbids/layer2-sdk";
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("https://api.devnet.solana.com");
const walletAddress = new PublicKey("..."); // User's wallet address
const sdk = new SolbidsSDK(connection, walletAddress);

Note: The SDK only needs the wallet address for initialization. Transaction signing is handled separately via signAndSendTransaction().

User Operations

buyBids(bidCount: number, ownerKey: PublicKey)

Build a transaction to purchase bid credits from a specific platform/owner at regular price.

Parameters:

  • bidCount: Number of bids to purchase
  • ownerKey: REQUIRED - Platform/owner's public key (the wallet that registered as owner)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const ownerPublicKey = new PublicKey("..."); // Platform owner's public key
const transaction = await sdk.buyBids(10, ownerPublicKey);

// Then sign, send, and confirm
const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

buyBidsWithPackage(ownerKey: PublicKey, packageId: string)

Build a transaction to purchase bid credits using a discount package.

Parameters:

  • ownerKey: REQUIRED - Platform/owner's public key
  • packageId: Package ID (created by the owner)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const ownerPublicKey = new PublicKey("..."); // Platform owner's public key
const transaction = await sdk.buyBidsWithPackage(ownerPublicKey, "package-1");

// Then sign, send, and confirm
const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

getBidBalance(ownerKey: PublicKey, userKey?: PublicKey)

Get user's current bid balance.

Parameters:

  • ownerKey: REQUIRED - Platform/owner's public key
  • userKey: Optional - User's public key (defaults to SDK wallet address)
const ownerPublicKey = new PublicKey("..."); // Platform owner's public key
const balance = await sdk.getBidBalance(ownerPublicKey);
console.log(`You have ${balance} bids`);

getUser(ownerKey: PublicKey, userKey?: PublicKey)

Get user account data.

Parameters:

  • ownerKey: REQUIRED - Platform/owner's public key
  • userKey: Optional - User's public key (defaults to SDK wallet address)
const ownerPublicKey = new PublicKey("..."); // Platform owner's public key
const user = await sdk.getUser(ownerPublicKey);
console.log("User data:", user);

Bidding Operations

placeBid(auctionCreator: PublicKey, auctionId: string | Uint8Array, bidCount: number)

Place bids on an auction. Uses correct PDA derivation matching the contract.

Parameters:

  • auctionCreator: Auction creator's public key
  • auctionId: Auction ID (string or Uint8Array)
  • bidCount: Number of bids to place

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const auctionCreator = new PublicKey("...");
const transaction = await sdk.placeBid(auctionCreator, "auction-123", 3);

// Then sign, send, and confirm
const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

Product Operations

createProduct(productId: string, name: string, description: string, imageUrls: string[], category: string, tags: string[], metadata: string, ownerKey?: PublicKey)

Build a transaction to create a product.

Parameters:

  • productId: Product ID (string)
  • name: Product name
  • description: Product description
  • imageUrls: Array of image URLs (max 5)
  • category: Product category
  • tags: Array of tags (max 10)
  • metadata: Additional metadata (JSON string)
  • ownerKey: Optional - Owner's public key (defaults to SDK wallet address)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.createProduct(
  "product-1",
  "My Product",
  "Product description",
  ["https://example.com/image1.jpg"],
  "Category",
  ["tag1", "tag2"],
  JSON.stringify({ custom: "data" })
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

updateProduct(productId: string | Uint8Array, creator: PublicKey, name?: string, description?: string, imageUrls?: string[], category?: string, tags?: string[], metadata?: string)

Build a transaction to update a product.

Parameters:

  • productId: Product ID (string or Uint8Array)
  • creator: Product creator's public key
  • name: Optional - Product name
  • description: Optional - Product description
  • imageUrls: Optional - Array of image URLs
  • category: Optional - Product category
  • tags: Optional - Array of tags
  • metadata: Optional - Additional metadata

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.updateProduct(
  "product-1",
  creatorPublicKey,
  "Updated Name",
  "Updated Description"
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

deactivateProduct(productId: string | Uint8Array, creator: PublicKey)

Build a transaction to deactivate a product.

Parameters:

  • productId: Product ID (string or Uint8Array)
  • creator: Product creator's public key

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.deactivateProduct("product-1", creatorPublicKey);
const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

getProduct(creator: PublicKey, productId: string | Uint8Array)

Get product data.

Returns: Product account data or null if not found

const product = await sdk.getProduct(creatorPublicKey, "product-1");

getAllProducts()

Get all products.

Returns: Array of all products

const products = await sdk.getAllProducts();

Auction Operations

createAuction(auctionId: string, productId: string, productCreator: PublicKey, startTime: Date, endTime: Date, startingPrice: number, bidIncrement: number, bidTimeExtension: number, assetMint: PublicKey, assetAmount?: number, reservePrice?: number, buyNowPrice?: number, ownerKey?: PublicKey)

Build a transaction to create an auction. Auto-detects asset type (Standard Token, Token-2022, pNFT, or Core NFT) and routes to the appropriate method.

Parameters:

  • auctionId: Auction ID (string)
  • productId: Product ID (string)
  • productCreator: Product creator's public key
  • startTime: Auction start time (Date)
  • endTime: Auction end time (Date)
  • startingPrice: Starting price in SOL
  • bidIncrement: Bid increment in SOL
  • bidTimeExtension: Time extension per bid in seconds
  • assetMint: Asset mint address (or Core asset address for Core NFTs)
  • assetAmount: Optional - Asset amount (default: 1, used for tokens)
  • reservePrice: Optional - Reserve price in SOL
  • buyNowPrice: Optional - Buy now price in SOL
  • ownerKey: Optional - Owner's public key (defaults to SDK wallet address)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.createAuction(
  "auction-1",
  "product-1",
  productCreatorPublicKey,
  new Date(Date.now() + 60000), // Start in 1 minute
  new Date(Date.now() + 3600000), // End in 1 hour
  1.0, // Starting price: 1 SOL
  0.1, // Bid increment: 0.1 SOL
  60, // Time extension: 60 seconds per bid
  assetMintPublicKey,
  1, // Asset amount (1 for NFTs)
  0.5, // Reserve price: 0.5 SOL (optional)
  10.0 // Buy now price: 10 SOL (optional)
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

createAuctionStandard(...) / createAuctionPNFT(...) / createAuctionCoreNFT(...)

Explicit methods for creating auctions with specific asset types. Use createAuction() for automatic detection, or these methods for explicit control.

// Standard Token or Token-2022
const transaction = await sdk.createAuctionStandard(
  "auction-1",
  "product-1",
  productCreatorPublicKey,
  startTime,
  endTime,
  1.0,
  0.1,
  60,
  assetMintPublicKey,
  1,
  0.5,
  10.0,
  assetInfo, // AssetInfo from detectAssetType()
  ownerKey
);

// pNFT
const transaction = await sdk.createAuctionPNFT(
  "auction-1",
  "product-1",
  productCreatorPublicKey,
  startTime,
  endTime,
  1.0,
  0.1,
  60,
  assetMintPublicKey,
  1,
  0.5,
  10.0,
  assetInfo, // AssetInfo from detectAssetType()
  ownerKey
);

// Core NFT
const transaction = await sdk.createAuctionCoreNFT(
  "auction-1",
  "product-1",
  productCreatorPublicKey,
  startTime,
  endTime,
  1.0,
  0.1,
  60,
  coreAssetPublicKey, // Core asset address (not a mint)
  0.5,
  10.0,
  ownerKey
);

startAuction(auctionCreator: PublicKey, auctionId: string | Uint8Array)

Build a transaction to start an auction (activate it).

Parameters:

  • auctionCreator: Auction creator's public key
  • auctionId: Auction ID (string or Uint8Array)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.startAuction(
  auctionCreatorPublicKey,
  "auction-1"
);
const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

endAuction(auctionCreator: PublicKey, auctionId: string | Uint8Array)

Build a transaction to end an auction.

Parameters:

  • auctionCreator: Auction creator's public key
  • auctionId: Auction ID (string or Uint8Array)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.endAuction(auctionCreatorPublicKey, "auction-1");
const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

getAuction(auctionCreator: PublicKey, auctionId: string | Uint8Array)

Get auction data.

Returns: Auction account data or null if not found

const auction = await sdk.getAuction(auctionCreatorPublicKey, "auction-1");
console.log("Current highest bid:", auction.highestBid.toString());
console.log("Status:", auction.status);

getAllAuctions()

Get all auctions.

Returns: Array of all auctions

const auctions = await sdk.getAllAuctions();

Asset Claiming Operations

claimAsset(auctionCreator: PublicKey, auctionId: string | Uint8Array, assetMint: PublicKey)

Build a transaction to claim asset as auction winner. Auto-detects asset type and routes to the appropriate method.

Parameters:

  • auctionCreator: Auction creator's public key
  • auctionId: Auction ID (string or Uint8Array)
  • assetMint: Asset mint address (or Core asset address for Core NFTs)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.claimAsset(
  auctionCreatorPublicKey,
  "auction-1",
  assetMintPublicKey
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

Note: The SDK automatically detects the asset type (Standard Token, Token-2022, pNFT, or Core NFT) and routes to the appropriate contract method. You don't need to specify the asset type manually.

Buy Now Operations

buyNow(auctionCreator: PublicKey, auctionId: string | Uint8Array, assetMint?: PublicKey)

Build a transaction to buy an asset at the buy-now price. Auto-detects asset type and routes to the appropriate method.

Parameters:

  • auctionCreator: Auction creator's public key
  • auctionId: Auction ID (string or Uint8Array)
  • assetMint: Optional - Asset mint address (or Core asset for Core NFTs). If not provided, will use auction's stored asset_mint.

Returns: Promise<Transaction> - Transaction object (not signed or sent)

Note: This method is only available when:

  • The auction has a buyNowPrice set
  • The auction has started
  • The auction has not ended
  • The asset has not been claimed
const transaction = await sdk.buyNow(
  auctionCreatorPublicKey,
  "auction-1",
  assetMintPublicKey // Optional - auto-detected from auction if not provided
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

Note: The SDK automatically detects the asset type (Standard Token, Token-2022, pNFT, or Core NFT) and routes to the appropriate contract method. You don't need to specify the asset type manually.

Asset Withdrawal Operations

withdrawAsset(auctionCreator: PublicKey, auctionId: string | Uint8Array, assetMint?: PublicKey)

Build a transaction to withdraw asset back to creator when auction ended without a winner. Auto-detects asset type and routes to the appropriate method.

Parameters:

  • auctionCreator: Auction creator's public key
  • auctionId: Auction ID (string or Uint8Array)
  • assetMint: Optional - Asset mint address (or Core asset for Core NFTs). If not provided, will use auction's stored asset_mint.

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.withdrawAsset(
  auctionCreatorPublicKey,
  "auction-1",
  assetMintPublicKey // Optional - auto-detected from auction if not provided
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

Note: The SDK automatically detects the asset type (Standard Token, Token-2022, pNFT, or Core NFT) and routes to the appropriate contract method. You don't need to specify the asset type manually.

Owner Operations

registerOwner(name: string, description: string, website: string, contactEmail: string, bidPrice: number, ownerKey?: PublicKey)

Build a transaction to register as a platform owner.

Parameters:

  • name: Owner name
  • description: Owner description
  • website: Website URL
  • contactEmail: Contact email
  • bidPrice: Price per bid in SOL
  • ownerKey: Optional - Owner's public key (defaults to SDK wallet address)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.registerOwner(
  "My Platform",
  "Platform description",
  "https://example.com",
  "[email protected]",
  0.1 // Bid price in SOL
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

updateOwner(ownerKey: PublicKey, name?: string, description?: string, website?: string, contactEmail?: string)

Build a transaction to update owner information.

Parameters:

  • ownerKey: Owner's public key
  • name: Optional - Owner name
  • description: Optional - Owner description
  • website: Optional - Website URL
  • contactEmail: Optional - Contact email

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.updateOwner(
  ownerPublicKey,
  "Updated Name",
  "Updated Description"
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

getOwner(ownerKey: PublicKey)

Get owner account data.

Returns: Owner account data or null if not found

const owner = await sdk.getOwner(ownerPublicKey);

getAllOwners()

Get all owners (fetches all program accounts).

Returns: Array of all owners with publicKey and ownerKey included

const owners = await sdk.getAllOwners();
owners.forEach((owner) => {
  console.log(`Owner: ${owner.name} - Key: ${owner.ownerKey.toString()}`);
});

getOwnerVaultBalance(ownerKey: PublicKey)

Get owner vault balance in SOL.

Returns: Balance in SOL

const balance = await sdk.getOwnerVaultBalance(ownerPublicKey);
console.log(`Vault balance: ${balance} SOL`);

claimOwnerFunds(amount: number, ownerKey?: PublicKey)

Build a transaction to claim funds from owner vault.

Parameters:

  • amount: Amount to claim in SOL (0 = claim all)
  • ownerKey: Optional - Owner's public key (defaults to SDK wallet address)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.claimOwnerFunds(1.5); // Claim 1.5 SOL, or 0 for all

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

Bid Package Operations

Owners can create discount packages to offer bulk bid purchases at reduced prices.

createBidPackage(packageId: string, bidCount: number, discountedPrice: number, ownerKey: PublicKey)

Build a transaction to create a bid package with a discount.

Parameters:

  • packageId: Unique package identifier (max 50 characters)
  • bidCount: Number of bids in the package
  • discountedPrice: Discounted price in SOL
  • ownerKey: Owner's public key

Returns: Promise<Transaction> - Transaction object (not signed or sent)

Note: The original price is automatically calculated based on the owner's regular bid price.

const transaction = await sdk.createBidPackage(
  "package-1",
  1000, // 1000 bids
  0.85, // 0.85 SOL (discounted from regular price)
  ownerPublicKey
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

updateBidPackage(packageId: string, ownerKey: PublicKey, bidCount?: number, discountedPrice?: number, isActive?: boolean)

Build a transaction to update an existing bid package.

Parameters:

  • packageId: Package identifier
  • ownerKey: Owner's public key
  • bidCount: Optional - New bid count
  • discountedPrice: Optional - New discounted price in SOL
  • isActive: Optional - Whether the package is active

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.updateBidPackage(
  "package-1",
  ownerPublicKey,
  1000, // New bid count
  0.80, // New discounted price
  true // Active status
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

getBidPackage(ownerKey: PublicKey, packageId: string)

Get bid package data.

Parameters:

  • ownerKey: Owner's public key
  • packageId: Package identifier

Returns: Bid package data or null if not found

const package = await sdk.getBidPackage(ownerPublicKey, "package-1");
console.log(`Package: ${package.bidCount} bids for ${package.discountedPrice} SOL`);
console.log(`Original price: ${package.originalPrice} SOL`);
console.log(`Active: ${package.isActive}`);

getAllBidPackages(ownerKey: PublicKey)

Get all bid packages for a specific owner.

Parameters:

  • ownerKey: Owner's public key

Returns: Array of all bid packages

const packages = await sdk.getAllBidPackages(ownerPublicKey);
packages.forEach((pkg) => {
  console.log(`${pkg.packageId}: ${pkg.bidCount} bids for ${pkg.discountedPrice} SOL`);
});

getActiveBidPackages(ownerKey: PublicKey)

Get all active bid packages for a specific owner.

Parameters:

  • ownerKey: Owner's public key

Returns: Array of active bid packages

const activePackages = await sdk.getActiveBidPackages(ownerPublicKey);

Admin Operations

initialize(authority: PublicKey, feePercentage: number)

Build a transaction to initialize the contract.

Parameters:

  • authority: Authority public key
  • feePercentage: Fee percentage (0-100)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.initialize(authorityPublicKey, 5); // 5% fee

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

updateConfig(newAuthority?: PublicKey | null, newFeePercentage?: number | null)

Build a transaction to update contract configuration.

Parameters:

  • newAuthority: Optional - New authority public key (null to keep current)
  • newFeePercentage: Optional - New fee percentage (0-100, null to keep current)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.updateConfig(
  newAuthorityPublicKey, // or null to keep current
  6 // or null to keep current
);

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

emergencyPause(paused: boolean)

Build a transaction to emergency pause/unpause the contract.

Parameters:

  • paused: Whether to pause (true) or unpause (false)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.emergencyPause(true); // Pause contract

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

claimAdminFees(amount: number)

Build a transaction to claim admin fees.

Parameters:

  • amount: Amount to claim in SOL (0 = claim all)

Returns: Promise<Transaction> - Transaction object (not signed or sent)

const transaction = await sdk.claimAdminFees(0); // Claim all admin fees

const signature = await sdk.signAndSendTransaction(transaction, wallet, 300000);

Config Operations

getConfig()

Get contract configuration.

Returns: Config account data or null if not found

const config = await sdk.getConfig();
console.log("Fee percentage:", config.feePercentage);
console.log("Authority:", config.authority.toString());
console.log("Paused:", config.paused);

getAdminFeeVaultBalance()

Get admin fee vault balance in SOL.

Returns: Balance in SOL

const balance = await sdk.getAdminFeeVaultBalance();
console.log(`Admin fee vault balance: ${balance} SOL`);

Transaction Signing

signAndSendTransaction(transaction: Transaction, wallet: WalletInterface, priorityFeeMicroLamports?: number, options?: TransactionOptions)

Sign, send, and confirm a transaction with priority fee.

Parameters:

  • transaction: Transaction object to sign and send
  • wallet: Wallet interface with publicKey and signTransaction method
  • priorityFeeMicroLamports: Priority fee in micro-lamports (default: 300000)
  • options: Optional transaction options (skipPreflight, commitment)

Returns: Promise<TransactionSignature> - Transaction signature

const signature = await sdk.signAndSendTransaction(
  transaction,
  wallet,
  300000, // Priority fee
  { skipPreflight: false }
);

Utilities

The SDK also exports utility functions:

import {
  // PDA helpers
  getConfigPDA,
  getOwnerPDA,
  getProductPDA,
  getAuctionPDA,
  getUserPDA,
  getBidPDA,
  getBidPackagePDA,
  getOwnerVaultPDA,
  getAdminFeeVaultPDA,
  getEscrowTokenAccountPDA,
  getEscrowAuthorityPDA,

  // ID generators
  generateProductId,
  generateAuctionId,
  generateBidId,

  // Conversions
  solToLamports,
  lamportsToSol,

  // Asset detection
  detectAssetType,
  detectTokenProgram,
  detectPNFT,
  detectCoreNFT,
  TOKEN_2022_PROGRAM_ID,
  TOKEN_METADATA_PROGRAM_ID,
  MPL_CORE_PROGRAM_ID,
  AssetInfo,
} from "@solbids/layer2-sdk";

Examples

Complete Bidding Flow

import { SolbidsSDK } from "@solbids/layer2-sdk";
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("https://api.devnet.solana.com");
const sdk = new SolbidsSDK(connection, walletAddress);

// 1. Buy bids from a platform
const ownerPublicKey = new PublicKey("..."); // Platform owner's public key
const buyBidsTx = await sdk.buyBids(20, ownerPublicKey);
const buyBidsSig = await sdk.signAndSendTransaction(buyBidsTx, wallet, 300000);

// 2. Check balance
const balance = await sdk.getBidBalance(ownerPublicKey);
console.log(`You have ${balance} bids`);

// 3. Place bid on auction
const auctionCreator = new PublicKey("...");
const placeBidTx = await sdk.placeBid(auctionCreator, "auction-1", 5);
const placeBidSig = await sdk.signAndSendTransaction(
  placeBidTx,
  wallet,
  300000
);

// 4. Check auction status
const auction = await sdk.getAuction(auctionCreator, "auction-1");
console.log("Current highest bid:", auction.highestBid.toString());

// 5. Optionally, buy now if available
if (auction.buyNowPrice && auction.buyNowPrice > 0) {
  const buyNowTx = await sdk.buyNow(auctionCreator, "auction-1", assetMint);
  const buyNowSig = await sdk.signAndSendTransaction(buyNowTx, wallet, 300000);
}

// 6. If you win, claim the asset
if (auction.winner?.equals(walletAddress)) {
  const claimTx = await sdk.claimAsset(auctionCreator, "auction-1", assetMint);
  const claimSig = await sdk.signAndSendTransaction(claimTx, wallet, 300000);
}

Complete Auction Creation Flow

import { SolbidsSDK } from "@solbids/layer2-sdk";
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("https://api.devnet.solana.com");
const sdk = new SolbidsSDK(connection, walletAddress);

// 1. Create a product
const createProductTx = await sdk.createProduct(
  "product-1",
  "My NFT",
  "A cool NFT",
  ["https://example.com/image.jpg"],
  "Art",
  ["digital", "art"],
  JSON.stringify({ collection: "My Collection" })
);
const productSig = await sdk.signAndSendTransaction(
  createProductTx,
  wallet,
  300000
);

// 2. Create an auction (auto-detects asset type)
const assetMint = new PublicKey("..."); // Your NFT mint address
const createAuctionTx = await sdk.createAuction(
  "auction-1",
  "product-1",
  walletAddress, // Product creator
  new Date(Date.now() + 60000), // Start in 1 minute
  new Date(Date.now() + 3600000), // End in 1 hour
  1.0, // Starting price: 1 SOL
  0.1, // Bid increment: 0.1 SOL
  60, // Time extension: 60 seconds
  assetMint,
  1, // Asset amount (1 for NFTs)
  0.5, // Reserve price (optional)
  10.0 // Buy now price (optional)
);
const auctionSig = await sdk.signAndSendTransaction(
  createAuctionTx,
  wallet,
  300000
);

// 3. Start the auction (optional - auction will auto-activate at start_time)
const startTx = await sdk.startAuction(walletAddress, "auction-1");
const startSig = await sdk.signAndSendTransaction(startTx, wallet, 300000);

Asset Type Detection

import { detectAssetType, AssetInfo } from "@solbids/layer2-sdk";

const assetMint = new PublicKey("...");
const assetInfo: AssetInfo = await detectAssetType(connection, assetMint);

console.log("Asset type:", assetInfo.type); // 'standard' | 'token2022' | 'pnft' | 'core_nft'
console.log("Is NFT:", assetInfo.isNFT);
console.log("Is Token-2022:", assetInfo.isToken2022);
console.log("Is pNFT:", assetInfo.isPNFT);
console.log("Is Core NFT:", assetInfo.isCoreNFT);

if (assetInfo.isPNFT) {
  console.log("Metadata:", assetInfo.metadata?.toString());
  console.log("Edition:", assetInfo.edition?.toString());
}

Asset Type Support

The SDK supports all Solana asset types:

  • Standard SPL Token - Regular fungible tokens and NFTs
  • SPL Token-2022 - Enhanced token program with additional features
  • pNFT (Programmable NFT) - NFTs with royalties and programmable features
  • MPL Core NFT - Metaplex Core NFTs

All methods automatically detect the asset type and use the appropriate contract method. The SDK handles all asset type detection internally - you only need to use the main methods (createAuction(), claimAsset(), withdrawAsset(), buyNow()).

Complete Method List

Transaction Methods (Main Public API)

Core Methods (Auto-detect asset type):

  • buyBids() - Purchase bid credits at regular price
  • buyBidsWithPackage() - Purchase bid credits using discount package
  • registerOwner() - Register as platform owner
  • updateOwner() - Update owner information
  • createProduct() - Create a product
  • updateProduct() - Update product information
  • deactivateProduct() - Deactivate a product
  • createAuction() - Create auction (auto-detects asset type: Standard, Token-2022, pNFT, or Core NFT)
  • createAuctionStandard() - Create standard token auction (explicit method)
  • createAuctionPNFT() - Create pNFT auction (explicit method)
  • createAuctionCoreNFT() - Create Core NFT auction (explicit method)
  • startAuction() - Start/activate an auction
  • endAuction() - End an auction
  • placeBid() - Place bids on an auction
  • buyNow() - Buy asset at buy-now price (auto-detects asset type)
  • claimAsset() - Claim asset as winner (auto-detects asset type)
  • withdrawAsset() - Withdraw asset back to creator (auto-detects asset type)
  • claimOwnerFunds() - Claim funds from owner vault
  • claimAdminFees() - Claim admin fees
  • initialize() - Initialize the contract
  • updateConfig() - Update contract configuration
  • emergencyPause() - Pause/unpause the contract
  • createBidPackage() - Create discount bid package
  • updateBidPackage() - Update bid package

Note: The main methods (createAuction(), claimAsset(), withdrawAsset(), buyNow()) automatically detect asset type. Use the explicit methods (createAuctionStandard(), createAuctionPNFT(), createAuctionCoreNFT()) only if you need explicit control over the asset type.

Query Methods (15)

  • getConfig() - Get contract configuration
  • getOwner() - Get owner account data
  • getAllOwners() - Get all owners
  • getUser() - Get user account data
  • getBidBalance() - Get user's bid balance
  • getOwnerVaultBalance() - Get owner vault balance
  • getAdminFeeVaultBalance() - Get admin fee vault balance
  • getProduct() - Get product data
  • getAllProducts() - Get all products
  • getAuction() - Get auction data
  • getAllAuctions() - Get all auctions
  • getBidPackage() - Get bid package data
  • getAllBidPackages() - Get all bid packages for an owner
  • getActiveBidPackages() - Get active bid packages for an owner

Total: 41 methods - Complete coverage of all contract functionality

Note: The main public API focuses on auto-detecting methods. Specific asset type methods (like claimAssetPNFT, withdrawAssetPNFT, etc.) are internal and not part of the public API.

Version

Current version: 3.1.0

This version includes:

  • All contract methods fully implemented (41 total)
  • Bid package system with discount pricing
  • Support for all asset types (Standard, Token-2022, pNFT, Core NFT)
  • Automatic asset type detection in main methods
  • Simplified public API - only main auto-detect methods exposed
  • Complete query methods for all account types
  • Full TypeScript support

License

MIT