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

# SDK Overview

> pnp-core is a lean, type-safe TypeScript SDK for the PnP prediction-market protocol on Solana. Install it, construct a client, and create or trade markets in a few lines.

`pnp-core` is the official TypeScript SDK for the [PnP protocol](https://www.pnp.exchange/) on
Solana. It wraps the on-chain program in one clean, type-safe client so you can create markets,
take positions, settle, and redeem without hand-rolling instructions or account resolution.

> [card] Create markets
>
> Parimutuel (P2P) and Pythagorean (AMM) markets — general, coin, or YouTube.

> [card] Trade & redeem
>
> Buy into a side, read live odds, and redeem winning positions.

> [card] Type-safe
>
> One `@coral-xyz/anchor` Program is the source of truth for every account and discriminator.

> [card] Node & browser
>
> Works with a Node `Keypair` or any browser wallet adapter. Ships ESM + CJS + `.d.ts`.

## How it fits together

Everything hangs off a single **`PnpClient`**, which exposes three namespaces:

| Namespace | What it does | Model |
| - | - | - |
| `client.p2p` | Parimutuel markets — create, buy, settle, redeem, refund, criteria | V3 |
| `client.amm` | Pythagorean markets — create + read prices/multipliers | V2 |
| `client.oracle` | Read the AI oracle's resolvable-status and settlement criteria | — |

PnP markets vary along **two independent axes** — pick one from each:

| Axis | Options |
| - | - |
| **Liquidity model** | `p2p` (parimutuel / creator seeds a side) · `amm` (Pythagorean / seeded liquidity) |
| **Resolution kind** | general question · coin/token price · YouTube stats |

> [!NOTE]
>
> `pnp-core` is a from-scratch rewrite of the older `pnp-sdk`. The client is now `PnpClient`
> (constructed from an options object) and methods are grouped under `p2p` / `amm` / `oracle`
> instead of living flat on the client.

## Installation

```bash npm theme={null}
npm install pnp-core @solana/web3.js @coral-xyz/anchor
```

```bash pnpm theme={null}
pnpm add pnp-core @solana/web3.js @coral-xyz/anchor
```

```bash yarn theme={null}
yarn add pnp-core @solana/web3.js @coral-xyz/anchor
```

```bash bun theme={null}
bun add pnp-core @solana/web3.js @coral-xyz/anchor
```

> [!NOTE]
>
> `@solana/web3.js` and `@coral-xyz/anchor` are peer dependencies — install them alongside
> `pnp-core`. Node 18+ is required.

## Construct a client

Use the `mainnet()` / `devnet()` presets, or the full constructor for custom RPC and commitment.

> [tab] Node (Keypair)
>
> ```ts theme={null}
> import { PnpClient } from "pnp-core";
> import { Keypair } from "@solana/web3.js";
> import { readFileSync } from "node:fs";
>
> const wallet = Keypair.fromSecretKey(
>   Uint8Array.from(JSON.parse(readFileSync("/path/to/id.json", "utf8"))),
> );
>
> // Preset (uses the network default RPC)
> const client = PnpClient.mainnet({ wallet });
>
> // …or the full constructor
> // const client = new PnpClient({
> //   cluster: "mainnet",
> //   wallet,
> //   rpcUrl: "https://your-rpc.example.com",
> //   commitment: "confirmed",
> // });
> ```

> [tab] Browser (wallet adapter)
>
> ```ts theme={null}
> import { PnpClient } from "pnp-core";
> import { useWallet } from "@solana/wallet-adapter-react";
>
> // `wallet` is any adapter exposing publicKey + signTransaction(s).
> const { wallet } = useWallet();
>
> const client = PnpClient.devnet({
>   wallet,
>   rpcUrl: "https://your-rpc.example.com",
> });
> ```

> [tab] Read-only (no signer)
>
> ```ts theme={null}
> import { PnpClient } from "pnp-core";
>
> // Omit `wallet` for reads/derivations only. Write methods throw.
> const client = PnpClient.mainnet();
>
> const market = await client.p2p.getMarket(42n);
> console.log(market.impliedYesProbability);
> ```

## Your first calls

Reads need no wallet; writes need a signer.

```ts theme={null}
import { PnpClient, uiToBaseUnits } from "pnp-core";

const client = PnpClient.mainnet({ wallet });

// READ — decode a market by numeric id or PDA
const market = await client.p2p.getMarket(42n);
console.log(market.question, market.impliedYesProbability);

// WRITE — create a parimutuel market seeded with 100 USDC on YES
const res = await client.p2p.createMarket({
  question: "Will BTC close above $100k on Dec 31, 2026?",
  initialAmount: uiToBaseUnits(100, 6), // amounts are in BASE units
  side: "yes",
  endTime: new Date(Date.now() + 30 * 864e5),
});
console.log("market id:", res.marketId.toString());
```

> [!WARNING]
>
> **Amounts are always in base units, not UI units.** For 6-decimal USDC, 100 USDC is
> `100_000000n`. Use `uiToBaseUnits(100, 6)` / `baseUnitsToUi(amount, 6)` to convert.

## Where to next

> [card] [Create a Market](https://pnpprotocol.mintlify.site/sdk/create-market.md)
>
> Every create path: P2P, AMM, coin, and YouTube markets.

> [card] [Trading & Redemption](https://pnpprotocol.mintlify.site/sdk/trading.md)
>
> Buy into a side, read odds, and redeem winnings.

> [card] [Custom Oracles](https://pnpprotocol.mintlify.site/sdk/custom-oracles.md)
>
> Designate your own settler and attach settlement criteria.

> [card] [API Reference](https://pnpprotocol.mintlify.site/sdk/api-reference.md)
>
> Every export, method, and type.


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