Back to recipesAPI Docs
Beginner · 10 min
Token Presales
Launch and manage token presales. List available presales, display details, and enable users to purchase tokens.
Prerequisites
- Podium SDK installed and configured
- Understanding of token economics basics
Token presales allow you to distribute tokens to early supporters before a public launch. The Podium API handles allocation tracking, purchase validation, and token distribution.
1
List available presales
Fetch all active presales to display to users:
presales.ts
// List all presales
const presales = await client.tokenPresales.list()
console.log(presales)
// [
// {
// id: 'presale_...',
// name: 'ACME Token Presale',
// tokenSymbol: '$ACME',
// price: 0.10,
// totalAllocation: 1000000,
// soldAmount: 250000,
// startsAt: '2025-01-01T00:00:00Z',
// endsAt: '2025-02-01T00:00:00Z',
// },
// ...
// ]2
Get presale details
Fetch detailed information about a specific presale:
presales.ts
// Get presale details
const presale = await client.tokenPresales.get({
id: 'presale_xyz',
})
console.log(presale)
// {
// id: 'presale_xyz',
// name: 'ACME Token Presale',
// description: 'Early access to $ACME tokens...',
// tokenSymbol: '$ACME',
// price: 0.10,
// minPurchase: 100,
// maxPurchase: 10000,
// totalAllocation: 1000000,
// soldAmount: 250000,
// remainingAllocation: 750000,
// ...
// }3
Purchase tokens
Execute a token purchase for a user:
presales.ts
// Buy tokens from presale
const purchase = await client.tokenPresales.buy({
id: 'presale_xyz',
requestBody: {
amount: 1000, // Number of tokens
},
})
console.log(purchase)
// {
// id: 'purchase_...',
// presaleId: 'presale_xyz',
// amount: 1000,
// totalCost: 100.00,
// status: 'completed',
// txHash: '0x...',
// }Complete Example
Here's a complete working example combining all the steps:
complete-example.ts
import { createPodiumClient } from '@podiumcommerce/node-sdk'
const client = createPodiumClient({
apiKey: process.env.PODIUM_API_KEY,
})
async function displayPresales() {
const presales = await client.tokenPresales.list()
return presales.map(presale => ({
id: presale.id,
name: presale.name,
token: presale.tokenSymbol,
price: presale.price,
progress: (presale.soldAmount / presale.totalAllocation) * 100,
remaining: presale.totalAllocation - presale.soldAmount,
}))
}
async function buyTokens(presaleId: string, amount: number) {
// Validate amount first
const presale = await client.tokenPresales.get({ id: presaleId })
if (amount < presale.minPurchase) {
throw new Error(`Minimum purchase is ${presale.minPurchase} tokens`)
}
if (amount > presale.maxPurchase) {
throw new Error(`Maximum purchase is ${presale.maxPurchase} tokens`)
}
// Execute purchase
return await client.tokenPresales.buy({
id: presaleId,
requestBody: { amount },
})
}Explore the full API
See all available endpoints and parameters in the API reference.
