This tutorial will guide you through creating a Marketplace ID for OpenBook (formerly Serum) on the Solana blockchain.
Prerequisites

Solana CLI installed (
solanacommand)Node.js (version 14 or higher)
Basic understanding of Solana and OpenBook
Some SOL for transaction fees
Step 1: Install Required Tools
npm install -g @project-serum/serum npm install @project-serum/anchor @solana/web3.js
Step 2: Set Up Your Environment
# Set your Solana network (devnet for testing) solana config set --url https://api.devnet.solana.com # Verify your configuration solana config get # Fund your wallet if needed (for devnet) solana airdrop 1
Step 3: Create Marketplace ID
Create a new JavaScript file createMarketplace.js with the following content:
const { Connection, Keypair, PublicKey, clusterApiUrl } = require('@solana/web3.js');
const { Market } = require('@project-serum/serum');
const { Token, TOKEN_PROGRAM_ID } = require('@solana/spl-token');
(async () => {
// Connect to cluster
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
// Your wallet keypair
const payer = Keypair.fromSecretKey(Uint8Array.from([/* Your private key bytes here */]));
// Base and quote token mints
const baseMint = new PublicKey('BASE_TOKEN_MINT_ADDRESS');
const quoteMint = new PublicKey('QUOTE_TOKEN_MINT_ADDRESS');
// Create the OpenBook market
try {
const market = await Market.create(
connection,
payer,
baseMint,
quoteMint,
null, // Optional: base vault owner
null, // Optional: quote vault owner
10, // Base decimals
6, // Quote decimals (typically USDC has 6)
{
init: {
eventQueueLength: 128,
requestQueueLength: 64,
orderbookLength: 128
},
// Optional: specify existing SPL token program
tokenProgramId: TOKEN_PROGRAM_ID
}
);
console.log('Market created successfully!');
console.log('Market ID:', market.address.toString());
console.log('Base Vault:', market.baseVaultAddress.toString());
console.log('Quote Vault:', market.quoteVaultAddress.toString());
} catch (error) {
console.error('Error creating market:', error);
}
})();Step 4: Run the Script
node createMarketplace.js
Step 5: Verify the Marketplace
After creation, you can verify your marketplace by:
Checking on a Solana explorer like Solscan
Querying the market ID programmatically:
const market = await Market.load(
connection,
new PublicKey('YOUR_MARKET_ID'),
{}, // Optional: custom options
TOKEN_PROGRAM_ID
);
console.log('Market details:', market);Important Notes
Mainnet vs Devnet: For production, replace
devnetwithmainnet-betaFees: Creating a market requires SOL for account creation and rent
Permissions: Ensure your wallet has sufficient permissions
Security: Never hardcode private keys in production code
Troubleshooting
Insufficient Funds: Airdrop more SOL if on devnet
Program Errors: Ensure you're using the correct OpenBook program ID
Connection Issues: Check your internet connection and RPC endpoint
If you don't understand the code, you can also use GTokenTool to generate OpenBook IDs
