Skip to main content
Get up and running with Alpha SDK and place your first trade on a prediction market in just a few minutes.

Prerequisites

Before you begin, make sure you have:
  • Node.js 18 or higher installed
  • An Algorand wallet with some ALGO and USDC on mainnet
  • Your wallet’s mnemonic phrase (25-word recovery phrase)
Never share your mnemonic phrase or commit it to version control. Use environment variables in production.

Installation

1

Install the SDK

Install Alpha SDK and its peer dependencies:
npm install @alpha-arcade/sdk algosdk @algorandfoundation/algokit-utils
2

Setup Algorand Clients

Create clients to connect to the Algorand blockchain:
import { AlphaClient } from '@alpha-arcade/sdk';
import algosdk from 'algosdk';

// Connect to Algorand mainnet (using public nodes)
const algodClient = new algosdk.Algodv2(
  '',
  'https://mainnet-api.algonode.cloud',
  443
);

const indexerClient = new algosdk.Indexer(
  '',
  'https://mainnet-idx.algonode.cloud',
  443
);
These are free public nodes. For production apps with high traffic, consider using a dedicated node provider like AlgoNode or Nodely.
3

Setup Your Wallet Signer

Create a transaction signer from your mnemonic:
// Get your mnemonic from environment variable
const mnemonic = process.env.ALGORAND_MNEMONIC || 'your twenty five word mnemonic here...';

// Convert mnemonic to account
const account = algosdk.mnemonicToSecretKey(mnemonic);

// Create a transaction signer
const signer = algosdk.makeBasicAccountTransactionSigner(account);

console.log('Wallet address:', account.addr);
For production applications, use secure wallet integrations like Pera Wallet or Defly Wallet instead of managing mnemonics directly.
4

Initialize Alpha Client

Create an instance of AlphaClient with your configuration:
const client = new AlphaClient({
  algodClient,
  indexerClient,
  signer,
  activeAddress: account.addr.toString(),
  matcherAppId: 3078581851,  // Alpha matcher contract on mainnet
  usdcAssetId: 31566704,     // USDC on Algorand mainnet
});

console.log('Alpha client initialized!');
The matcherAppId and usdcAssetId values shown here are for Algorand mainnet. See Configuration for testnet values.
5

Fetch Live Markets

Get all active prediction markets:
// Fetch all live markets from the blockchain
const markets = await client.getLiveMarkets();

console.log(`Found ${markets.length} live markets`);

// Display the first market
if (markets.length > 0) {
  const market = markets[0];
  console.log('Market:', market.title);
  console.log('Market App ID:', market.marketAppId);
  console.log('YES Asset:', market.yesAssetId);
  console.log('NO Asset:', market.noAssetId);
}
Without an API key, getLiveMarkets() discovers markets directly from the blockchain. To get richer market data (images, categories, volume), add an API key to your client config. See Installation.
6

Place Your First Order

Create a limit order on a market:
// Select the first market
const market = markets[0];

// Place a limit buy order for YES at $0.50
const result = await client.createLimitOrder({
  marketAppId: market.marketAppId,
  position: 1,          // 1 = Yes, 0 = No
  price: 500_000,       // $0.50 in microunits
  quantity: 1_000_000,  // 1 share in microunits
  isBuying: true,
});

console.log('Order created successfully!');
console.log('Escrow App ID:', result.escrowAppId);
console.log('Transaction IDs:', result.txIds);
console.log('Confirmed in round:', result.confirmedRound);

if (result.matchedQuantity && result.matchedQuantity > 0) {
  console.log(`Matched ${result.matchedQuantity / 1_000_000} shares at $${result.matchedPrice! / 1_000_000}`);
}
Limit orders execute at your exact price (zero slippage). If there’s a matching order on the book, your order may fill immediately. Otherwise, it sits on the orderbook until matched.

Complete Example

Here’s the full code in one file:
complete-example.ts
import { AlphaClient } from '@alpha-arcade/sdk';
import algosdk from 'algosdk';

async function main() {
  // 1. Setup Algorand clients
  const algodClient = new algosdk.Algodv2('', 'https://mainnet-api.algonode.cloud', 443);
  const indexerClient = new algosdk.Indexer('', 'https://mainnet-idx.algonode.cloud', 443);

  // 2. Setup wallet signer
  const account = algosdk.mnemonicToSecretKey(process.env.ALGORAND_MNEMONIC!);
  const signer = algosdk.makeBasicAccountTransactionSigner(account);

  // 3. Initialize Alpha client
  const client = new AlphaClient({
    algodClient,
    indexerClient,
    signer,
    activeAddress: account.addr.toString(),
    matcherAppId: 3078581851,
    usdcAssetId: 31566704,
  });

  // 4. Fetch live markets
  const markets = await client.getLiveMarkets();
  console.log(`Found ${markets.length} live markets`);

  // 5. Place a limit order
  const market = markets[0];
  const result = await client.createLimitOrder({
    marketAppId: market.marketAppId,
    position: 1,
    price: 500_000,
    quantity: 1_000_000,
    isBuying: true,
  });

  console.log(`Order created! Escrow app ID: ${result.escrowAppId}`);
}

main().catch(console.error);
Save this as trade.ts and run it with:
ALGORAND_MNEMONIC="your mnemonic here" npx tsx trade.ts

What’s Next?

Now that you’ve placed your first order, explore more features:

Read the Orderbook

Fetch live orderbook data to see all bids and asks

Place Market Orders

Execute trades immediately at the best available price

Manage Positions

Split, merge, and claim your YES/NO tokens

Build Trading Bots

Create automated trading strategies

Understanding Microunits

Alpha SDK uses microunits for all prices and quantities:
  • Prices: 1_000_000 = 1.00,so500000=1.00, so `500_000` = 0.50
  • Quantities: 1_000_000 = 1 share, so 2_000_000 = 2 shares
  • Position: 1 = YES, 0 = NO
See Fees and Units for more details.

Troubleshooting

Make sure your wallet has enough USDC to cover the order value plus fees. For a buy order, you need quantity * price / 1_000_000 USDC. Also ensure you have at least 0.5 ALGO for transaction fees.
Before trading, your wallet must opt in to the YES and NO token assets for the market. The SDK handles this automatically, but you need enough ALGO for the minimum balance requirement (0.1 ALGO per asset).
Limit orders only execute at your exact price. If there’s no matching order on the opposite side of the book, your order will sit on the orderbook until someone matches it. Use createMarketOrder() for immediate execution.
If you’re getting timeout errors, the public nodes may be experiencing high traffic. Try again or consider using a dedicated node provider for more reliable performance.

Mainnet vs Testnet

const algodClient = new algosdk.Algodv2('', 'https://mainnet-api.algonode.cloud', 443);
const indexerClient = new algosdk.Indexer('', 'https://mainnet-idx.algonode.cloud', 443);

const client = new AlphaClient({
  algodClient,
  indexerClient,
  signer,
  activeAddress: account.addr.toString(),
  matcherAppId: 3078581851,
  usdcAssetId: 31566704,
});

Build docs developers (and LLMs) love