Mint from a Drop Programmatically
Build a custom mint experience using the OpenSea Drops API.
The OpenSea Drops API lets you discover active drops, check eligibility, and mint NFTs programmatically. This is the buyer/minter side — if you want to create and manage a drop as a creator, see Create a Primary Drop.
Prerequisites
- Node.js >= 20.0.0
- OpenSea API key (get one here, or use the instant API key endpoint)
- ethers.js (v6+)
- A funded wallet on the drop's chain
Security Warning: Do not use the SDK in client-side code — your API key would be exposed. Use it on a backend server and return transaction data to your frontend.
Setup
npm install @opensea/sdk ethersimport { ethers } from "ethers";
import { OpenSeaSDK, Chain } from "@opensea/sdk";
const provider = new ethers.JsonRpcProvider("https://your-rpc-url");
const sdk = new OpenSeaSDK(provider, {
chain: Chain.Base,
apiKey: "YOUR_API_KEY",
});The examples below use ethers.js. For viem setup, see Buy and Sell NFTs — With viem. All SDK methods work the same with either library.
Step 1: Discover Available Drops
Browse drops by type: featured, upcoming, or recently_minted.
SDK
// Featured drops
const featured = await sdk.api.getDrops({ type: "featured" });
// Upcoming drops
const upcoming = await sdk.api.getDrops({ type: "upcoming" });
// Recently minted
const recent = await sdk.api.getDrops({ type: "recently_minted" });
for (const drop of featured.drops) {
console.log(drop.collection_slug, drop.name);
}curl
# Featured drops
curl -X GET "https://api.opensea.io/api/v2/drops?type=featured&limit=20" \
-H "X-API-KEY: YOUR_API_KEY"
# Upcoming drops
curl -X GET "https://api.opensea.io/api/v2/drops?type=upcoming&limit=20" \
-H "X-API-KEY: YOUR_API_KEY"You can filter by chain:
curl -X GET "https://api.opensea.io/api/v2/drops?type=featured&chains=base&limit=20" \
-H "X-API-KEY: YOUR_API_KEY"Step 2: Get Drop Details
Fetch full details for a specific drop including mint stages, pricing, supply, and allowlists.
SDK
const drop = await sdk.api.getDrop("my-collection-slug");
console.log("Name:", drop.name);
console.log("Total supply:", drop.total_supply);
console.log("Minted:", drop.total_minted);
console.log("Stages:", drop.stages);
// Each stage includes:
// - name (e.g., "Allowlist", "Public")
// - price
// - start_time / end_time
// - max_per_wallet
// - remaining supplycurl
curl -X GET "https://api.opensea.io/api/v2/drops/my-collection-slug" \
-H "X-API-KEY: YOUR_API_KEY"Step 3: Check Eligibility
The drop details response includes stage information with allowlists and per-wallet limits. Check whether a wallet is eligible for the current stage:
const drop = await sdk.api.getDrop("my-collection-slug");
for (const stage of drop.stages) {
console.log(`Stage: ${stage.name}`);
console.log(` Price: ${stage.price}`);
console.log(` Max per wallet: ${stage.max_per_wallet}`);
console.log(` Start: ${stage.start_time}`);
console.log(` End: ${stage.end_time}`);
}
// Check remaining supply
const remaining = drop.total_supply - drop.total_minted;
console.log("Remaining supply:", remaining);Step 4: Build the Mint Transaction
Generate the transaction data to mint NFTs from the drop.
SDK
const mintTx = await sdk.api.buildDropMintTransaction("my-collection-slug", {
minter: "0xYOUR_WALLET_ADDRESS",
quantity: 2,
});
console.log("Target contract:", mintTx.target);
console.log("Calldata:", mintTx.calldata);
console.log("Value (wei):", mintTx.value);curl
curl -X POST "https://api.opensea.io/api/v2/drops/my-collection-slug/mint" \
-H "X-API-KEY: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"minter": "0xYOUR_WALLET_ADDRESS",
"quantity": 2
}'The response contains:
| Field | Description |
|---|---|
target | The contract address to call |
calldata | Hex-encoded transaction data |
value | Native token value to send (mint price in wei) |
Step 5: Execute the Mint
Submit the transaction onchain using the data from the previous step.
const signer = await provider.getSigner();
const transaction = await signer.sendTransaction({
to: mintTx.target,
data: mintTx.calldata,
value: BigInt(mintTx.value),
});
console.log("Transaction hash:", transaction.hash);
const receipt = await transaction.wait();
console.log("Minted! Block:", receipt.blockNumber);Full Example
Putting it all together — discover a drop, check supply, and mint:
import { ethers } from "ethers";
import { OpenSeaSDK, Chain } from "@opensea/sdk";
const provider = new ethers.JsonRpcProvider("https://your-rpc-url");
const sdk = new OpenSeaSDK(provider, {
chain: Chain.Base,
apiKey: "YOUR_API_KEY",
});
const COLLECTION_SLUG = "my-collection-slug";
const WALLET = "0xYOUR_WALLET_ADDRESS";
const QUANTITY = 1;
// Check drop details
const drop = await sdk.api.getDrop(COLLECTION_SLUG);
const remaining = drop.total_supply - drop.total_minted;
console.log(`${drop.name}: ${remaining} remaining`);
if (remaining < QUANTITY) {
console.log("Not enough supply remaining");
process.exit(1);
}
// Build and execute mint transaction
const mintTx = await sdk.api.buildDropMintTransaction(COLLECTION_SLUG, {
minter: WALLET,
quantity: QUANTITY,
});
const signer = await provider.getSigner();
const transaction = await signer.sendTransaction({
to: mintTx.target,
data: mintTx.calldata,
value: BigInt(mintTx.value),
});
const receipt = await transaction.wait();
console.log("Minted! Tx:", receipt.hash);Next Steps
- Create a Primary Drop — set up a drop as a creator
- Display an NFT — show minted NFTs on a website
- Query Analytics and Events — track minting activity
- Drops API reference
- @opensea/sdk on GitHub
Updated 2 minutes ago
