> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orica.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Examples

> Common SDK operations at a glance.

Quick reference for the most common SDK operations in both TypeScript and Python.

***

## Initialize SDK

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> import { OricaSDK } from "@neko/orica-sdk";
> import { Connection } from "@solana/web3.js";
>
> const connection = new Connection("https://api.mainnet-beta.solana.com");
> const sdk = await OricaSDK.createFromChain(connection);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> from orica_sdk import OricaSDK
> from solana.rpc.async_api import AsyncClient
>
> connection = AsyncClient("https://api.mainnet-beta.solana.com")
> sdk = await OricaSDK.create(connection)
> ```

***

## Fetch All Markets

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const markets = await sdk.orica.fetchAllMarkets();
>
> for (const { publicKey, account } of markets) {
>   console.log(account.question);
>   console.log("Close time:", new Date(account.closeTime.toNumber() * 1000));
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> markets = await sdk.orica.fetch_all_markets()
>
> for address, market in markets:
>     print(market.question)
>     print(f"Close time: {market.close_time}")
> ```

***

## Fetch Single Market

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const marketAddress = new PublicKey("ABC123...");
> const market = await sdk.orica.fetchMarket(marketAddress);
>
> console.log("Question:", market.question);
> console.log("Options:", market.optionNames);
> console.log("Status:", market.status);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> market_address = Pubkey.from_string("ABC123...")
> market = await sdk.orica.fetch_market(market_address)
>
> print(f"Question: {market.question}")
> print(f"Options: {market.option_names}")
> print(f"Status: {market.status.value}")
> ```

***

## Get Market Prices

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const prices = sdk.orica.calculatePrices(market);
> console.log("Prices:", prices); // [0.65, 0.35] for binary market
> ```

> [tab] Python
>
> ```python theme={"dark"}
> prices = sdk.orica.calculate_prices(market)
> print(f"Prices: {prices}")  # [0.65, 0.35] for binary market
> ```

***

## Buy Shares

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> import { BN } from "@coral-xyz/anchor";
> import { Transaction } from "@solana/web3.js";
>
> const amount = new BN(1_000_000); // 1 USDC
> const outcomeIndex = 0; // Buy first outcome
>
> const instructions = await sdk.orica.buildBuy(
>   wallet.publicKey,
>   userUsdcAccount,
>   marketAddress,
>   amount,
>   outcomeIndex
> );
>
> const tx = new Transaction().add(...instructions);
> const sig = await connection.sendTransaction(tx, [wallet]);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> from solana.transaction import Transaction
>
> amount = 1_000_000  # 1 USDC
> outcome_index = 0  # Buy first outcome
>
> instructions = await sdk.orica.build_buy(
>     user=wallet.pubkey(),
>     user_usdc=user_usdc_account,
>     market_address=market_pubkey,
>     amount=amount,
>     outcome_index=outcome_index,
> )
>
> tx = Transaction()
> tx.add(*instructions)
> sig = await connection.send_transaction(tx, wallet)
> ```

***

## Sell Shares

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const sharesToSell = new BN(5000);
> const outcomeIndex = 0;
>
> const instructions = await sdk.orica.buildSell(
>   wallet.publicKey,
>   userUsdcAccount,
>   marketAddress,
>   sharesToSell,
>   outcomeIndex
> );
>
> const tx = new Transaction().add(...instructions);
> await connection.sendTransaction(tx, [wallet]);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> shares_to_sell = 5000
> outcome_index = 0
>
> instructions = await sdk.orica.build_sell(
>     user=wallet.pubkey(),
>     user_usdc=user_usdc_account,
>     market_address=market_pubkey,
>     shares=shares_to_sell,
>     outcome_index=outcome_index,
> )
>
> tx = Transaction()
> tx.add(*instructions)
> await connection.send_transaction(tx, wallet)
> ```

***

## Check Position

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const position = await sdk.orica.fetchPosition(marketAddress, wallet.publicKey);
>
> if (position) {
>   console.log("Yes shares:", position.outcomeAmounts[0].toString());
>   console.log("No shares:", position.outcomeAmounts[1].toString());
> } else {
>   console.log("No position in this market");
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> position = await sdk.orica.fetch_position(market_address, wallet.pubkey())
>
> if position:
>     print(f"Yes shares: {position.outcome_amounts[0]}")
>     print(f"No shares: {position.outcome_amounts[1]}")
> else:
>     print("No position in this market")
> ```

***

## Redeem Winnings

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const instruction = await sdk.orica.buildRedeem(
>   wallet.publicKey,
>   userUsdcAccount,
>   marketAddress
> );
>
> const tx = new Transaction().add(instruction);
> await connection.sendTransaction(tx, [wallet]);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> instruction = await sdk.orica.build_redeem(
>     user=wallet.pubkey(),
>     user_usdc=user_usdc_account,
>     market_address=market_pubkey,
> )
>
> tx = Transaction()
> tx.add(instruction)
> await connection.send_transaction(tx, wallet)
> ```

***

## Vote on Dispute

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [globalState] = sdk.orica.pda.globalState();
> const [position] = sdk.orica.pda.position(marketAddress, wallet.publicKey);
>
> const instruction = await sdk.disputes.buildVoteForDispute(
>   wallet.publicKey,
>   marketAddress,
>   position,
>   globalState
> );
>
> const tx = new Transaction().add(instruction);
> await connection.sendTransaction(tx, [wallet]);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> global_state, _ = sdk.orica.pda.global_state()
> position, _ = sdk.orica.pda.position(market_address, wallet.pubkey())
>
> instruction = await sdk.disputes.build_vote_for_dispute(
>     user=wallet.pubkey(),
>     market=market_address,
>     position=position,
>     global_state=global_state,
> )
>
> tx = Transaction()
> tx.add(instruction)
> await connection.send_transaction(tx, wallet)
> ```

***

## Post Dispute Message

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const content = "The resolution is incorrect because...";
> const encoder = new TextEncoder();
> const hashBuffer = await crypto.subtle.digest('SHA-256', encoder.encode(content));
> const messageHash = Array.from(new Uint8Array(hashBuffer));
>
> const [globalState] = sdk.orica.pda.globalState();
> const [position] = sdk.orica.pda.position(marketAddress, wallet.publicKey);
>
> const instruction = await sdk.disputes.buildPostMessage(
>   wallet.publicKey,
>   marketAddress,
>   position,
>   globalState,
>   messageHash,
>   content,
>   null // No parent message
> );
>
> const tx = new Transaction().add(instruction);
> await connection.sendTransaction(tx, [wallet]);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> import hashlib
>
> content = "The resolution is incorrect because..."
> message_hash = hashlib.sha256(content.encode()).digest()
>
> global_state, _ = sdk.orica.pda.global_state()
> position, _ = sdk.orica.pda.position(market_address, wallet.pubkey())
>
> instruction = await sdk.disputes.build_post_message(
>     author=wallet.pubkey(),
>     market=market_address,
>     position=position,
>     global_state=global_state,
>     message_hash=message_hash,
>     ipfs_uri="ipfs://...",
>     parent_message=None,
> )
>
> tx = Transaction()
> tx.add(instruction)
> await connection.send_transaction(tx, wallet)
> ```

***

## Fetch Disputes

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const disputes = await sdk.disputes.fetchAllDisputes();
>
> for (const { publicKey, account } of disputes) {
>   console.log(`Market: ${account.market.toBase58()}`);
>   console.log(`Status: ${account.status}`);
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> disputes = await sdk.disputes.fetch_all_disputes()
>
> for address, dispute in disputes:
>     print(f"Market: {dispute.market}")
>     print(f"Status: {dispute.status.value}")
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.