A Solana auction smart contract for NFT auctions. Sellers list NFTs with a start price and duration; bidders place bids in HTO token. The highest bidder wins when the auction ends, with automatic royalty and fee distribution.
- Create auction — List an NFT with start price and duration (1–14 days). NFT is escrowed by the program.
- Place bid — Bid in HTO token; first bid must meet start price; outbids require ≥5% or 10 HTO increase. Previous bidder is refunded automatically.
- Auction extension — Last 10 minutes: any new bid extends the end time by 10 minutes.
- Cancel auction — Seller can cancel only if there are no bids; NFT is returned.
- Claim auction — After end time, seller or winner can claim: NFT goes to winner, HTO to seller (minus 2% platform fee and creator royalties).
The project is an Anchor program (Solana smart contract) that implements an NFT auction with SPL token bids (HTO). It uses Metaplex Token Metadata for NFT verification and creator royalty distribution.
Solana-Auction-Smart-Contract/
├── programs/
│ └── auction/
│ ├── src/
│ │ ├── lib.rs # Program entry, instructions, account contexts
│ │ ├── account.rs # GlobalPool, AuctionPool state
│ │ ├── error.rs # AuctionError enum
│ │ └── utils.rs # Constants, ATA creation, SPL transfers
│ └── Cargo.toml
├── tests/
│ └── auction.ts # Anchor/TypeScript integration tests
├── cli/ # Optional CLI (wallet-specific scripts)
├── Anchor.toml # Anchor config (program ID, cluster, scripts)
├── Cargo.toml # Workspace (programs/*)
└── package.json # Node deps and test script
| Component | Description |
|---|---|
| Program ID | 6VwSgSesAeqqSw3uXsU8BGMxMAqSzFVQxPPUDUVX8Qw4 (devnet in Anchor.toml) |
| Instructions | initialize, create_auction, cancel_auction, place_bid, claim_auction |
| State accounts | GlobalPool (super admin), AuctionPool (per-auction: seller, NFT mint, bidder, current bid, start price, end time) |
- Initialize — Deployer creates the single
GlobalPoolPDA (seed:global-authority), setssuper_admin. - Create auction — Seller passes NFT mint + metadata; program checks Metaplex metadata and collection/creators, creates auction PDA and auction ATA, escrows 1 NFT from seller to program-owned ATA.
- Place bid — Bidder sends HTO to program-owned
auction_vault; if there was a previous bidder, their HTO is refunded from vault. Bid rules: first bid ≥ start price; later bids ≥ current + 5% or +10 HTO; last 10 minutes extend end time by 10 minutes. - Cancel auction — Only seller, only when
current_bid == 0; NFT is transferred back to seller; auction PDA is closed. - Claim auction — Callable by seller or winning bidder after
end_time. Program: pays creator royalties (from metadata), 2% toVAULT_WALLET, remainder to seller; transfers NFT to winner; closes auction vault and auction PDA.
- anchor-lang / anchor-spl — Framework and token CPI
- mpl-token-metadata — NFT metadata and creators (royalties)
- spl-token, spl-associated-token-account — Token and ATA handling
GLOBAL_AUTHORITY_SEED: PDA seed for global config and escrow authorityDAY,MIN_DURATION_AFTER_BID_SECS: Duration bounds and extension windowFEE_PERCENT: 2% platform feeMIN_INCREMENT_PERCENT/MIN_INCREMENT: 5% or 10 HTO minimum bid increaseVAULT_WALLET,HTO_TOKEN_MINT: Fee recipient and bid token mint
- Rust (for building the Solana program)
- Solana CLI (for cluster and deployment)
- Anchor (v0.27; see Anchor book)
- Node.js and Yarn (for tests and optional CLI)
- Solana: Install Solana CLI
- Rust: rustup
- Anchor: Anchor installation
- Node: install Node.js and Yarn
git clone https://github.com/husreodev/auction_contract.git
cd auction_contract
yarn installanchor buildThis compiles the programs/auction crate and produces the program binary and IDL under target/.
Anchor.toml is set to devnet and a wallet path (e.g. ../keys/user-Shit.json). Point provider.wallet to your keypair or set ANCHOR_WALLET when running commands.
For localnet:
# Terminal 1: run validator
solana-test-validatorThen in Anchor.toml set cluster = "localnet" (or override with anchor run / env).
anchor testThis runs yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts (as in Anchor.toml), which executes the TypeScript tests in tests/auction.ts against the built program.
anchor deploy --provider.cluster devnetEnsure the configured wallet has enough SOL and that the program ID in Anchor.toml matches your keypair-derived program ID (or update declare_id! in lib.rs and Anchor.toml after anchor keys list).
The repo includes wallet-specific scripts in package.json (e.g. ts-node, ts-node-deployer) that use cli/command.ts. These depend on keypair paths (e.g. ../keys/...). Run only if you have set up those keys and adjusted paths:
yarn ts-node-user # example; uses ANCHOR_WALLET from script| Instruction | Who | Description |
|---|---|---|
initialize |
Admin | Creates GlobalPool PDA and sets super admin. |
create_auction |
Seller | Escrows NFT, sets start price and end time (1–14 days). |
cancel_auction |
Seller | Cancels if no bids; returns NFT and closes auction. |
place_bid |
Bidder | Locks HTO in vault; refunds previous bidder; enforces min increment and optional time extension. |
claim_auction |
Seller or winner | Settles: royalties + fee + seller payout in HTO; NFT to winner; closes auction. |
Auction smart contract • Solana • Anchor • NFT auction • Blockchain auction