Code Examples
Complete code examples for common TIX Protocol operations.
Full Event Lifecycle
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import { getAssociatedTokenAddress, getOrCreateAssociatedTokenAccount } from '@solana/spl-token';
import {
registerEvent,
issuePermits,
listTicket,
acceptOffer,
markUsed,
getEvent,
getPermit,
} from '@tixprotocol/sdk';
const USDC_MINT = new PublicKey('...');
async function fullEventLifecycle() {
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
// Load your integrator keypair (provided during onboarding)
const integrator = Keypair.fromSecretKey(/* your secret key */);
const artist = Keypair.generate();
const buyer1 = Keypair.generate();
const buyer2 = Keypair.generate();
// 1. Create royalty recipient ATA
const artistAta = await getOrCreateAssociatedTokenAccount(
connection,
integrator,
USDC_MINT,
artist.publicKey
);
// 2. Register event
console.log('1. Registering event...');
const eventId = 1001n;
const { tx: eventTx, event } = await registerEvent({
connection,
payer: integrator.publicKey,
integratorIdentity: integrator.publicKey,
integratorAuthority: integrator.publicKey,
eventId,
totalSupply: 100n,
royaltyBps: 500,
minRoyaltyFloor: 100_000n,
royaltyRecipients: [
{ destination: artistAta.address, bps: 500 },
],
});
eventTx.sign([integrator]);
await connection.sendTransaction(eventTx);
// 3. Issue tickets
console.log('2. Issuing tickets...');
const issueTx = await issuePermits({
connection,
payer: integrator.publicKey,
integratorIdentity: integrator.publicKey,
integratorAuthority: integrator.publicKey,
eventId,
buyers: [buyer1.publicKey, buyer2.publicKey],
});
issueTx.sign([integrator]);
await connection.sendTransaction(issueTx);
// 4. Buyer 1 lists ticket for resale
console.log('3. Listing ticket for resale...');
const buyer1Ata = await getOrCreateAssociatedTokenAccount(
connection,
buyer1,
USDC_MINT,
buyer1.publicKey
);
const listTx = await listTicket({
connection,
payer: buyer1.publicKey,
eventId,
ticketId: 0n,
seller: buyer1.publicKey,
askPriceMinor: 50_000_000n, // $50
payoutAta: buyer1Ata.address,
expiresAt: Math.floor(Date.now() / 1000) + 86400,
buyerAllow: null,
});
listTx.sign([buyer1]);
await connection.sendTransaction(listTx);
// 5. Buyer 2 purchases the listing
console.log('4. Accepting offer...');
const buyer2Ata = await getOrCreateAssociatedTokenAccount(
connection,
buyer2,
USDC_MINT,
buyer2.publicKey
);
const buyTx = await acceptOffer({
connection,
payer: buyer2.publicKey,
eventId,
ticketId: 0n,
buyer: buyer2.publicKey,
buyerUsdcAta: buyer2Ata.address,
integratorIdentity: integrator.publicKey,
});
buyTx.sign([buyer2]);
await connection.sendTransaction(buyTx);
// 6. Mark ticket as used at event
console.log('5. Marking ticket as used...');
const usedTx = await markUsed({
connection,
payer: integrator.publicKey,
eventId,
ticketId: 0n,
integratorIdentity: integrator.publicKey,
integratorAuthority: integrator.publicKey,
});
usedTx.sign([integrator]);
await connection.sendTransaction(usedTx);
// 7. Verify final state
console.log('6. Verifying final state...');
const eventState = await getEvent(connection, event);
const permit = await getPermit(connection, event, 0n);
console.log(`Event minted: ${eventState.minted}/${eventState.totalSupply}`);
console.log(`Ticket 0 owner: ${permit.owner.toBase58()}`);
console.log(`Ticket 0 status: ${permit.status}`);
console.log('Complete!');
}Marketplace Integration
Secondary Market Bot
Venue Check-In System
Last updated