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

# API Examples

> Working examples for the InkyPump V2 contract and REST API.

This page collects working snippets you can copy. All examples target the live V2 hook at `0x4cC8F6d5B7cE150CCC0A9B7664532B1283b96AC4` on Ink mainnet.

## Preview a buy from cast

Previews use the `LaunchViewModule` with local state. Read the launch state first, then call `previewBuyLocal` with the unpacked fields. See [Quotes](/api-reference/contracts/quotes) for the full pattern.

```bash theme={null}
# 1. Read launch state from the hook
cast call 0x4cC8F6d5B7cE150CCC0A9B7664532B1283b96AC4 \
  "getLaunchState(uint256)" $LAUNCH_ID \
  --rpc-url https://rpc-gel.inkonchain.com

# 2. Pass the unpacked state to the view module
cast call 0xce83E3659251116d114Ec1CA729ffB49B99403c3 \
  "previewBuyLocal(uint128,uint96,uint32,uint128,uint128,uint256)(uint256,uint256,uint256,uint256)" \
  $SALE_SUPPLY $TARGET_RAISE $GAIN_BPS $SOLD $REMAINING 100000000000000 \
  --rpc-url https://rpc-gel.inkonchain.com
```

Returns four uint256 values: `tokensOut`, `cost`, `refund`, `tokensRemaining`.

## Read launch state from cast

```bash theme={null}
cast call 0x4cC8F6d5B7cE150CCC0A9B7664532B1283b96AC4 \
  "getLaunchState(uint256)" \
  $LAUNCH_ID \
  --rpc-url https://rpc-gel.inkonchain.com
```

The returned bytes decode to the `LaunchConfig` struct. For a typed decode, use viem or ethers with the ABI.

## Buy with viem

```typescript theme={null}
import { createWalletClient, http, parseEther } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { INKY_PUMP_HOOK_ABI } from "./abi"

const HOOK = "0x4cC8F6d5B7cE150CCC0A9B7664532B1283b96AC4"
const account = privateKeyToAccount(process.env.PRIVATE_KEY)

const client = createWalletClient({
  account,
  chain: { id: 57073, rpcUrls: { default: { http: ["https://rpc-gel.inkonchain.com"] } } },
  transport: http(),
})

const captcha = { deadline: 0n, signature: "0x" }  // empty if past anti-snipe window

const hash = await client.writeContract({
  address: HOOK,
  abi: INKY_PUMP_HOOK_ABI,
  functionName: "buy",
  args: [launchId, minTokensOut, captcha],
  value: parseEther("0.1"),
})
```

## Sell with viem (requires approval first)

```typescript theme={null}
// Approve the hook to pull tokens
await client.writeContract({
  address: tokenAddress,
  abi: ERC20_ABI,
  functionName: "approve",
  args: [HOOK, tokenAmount],
})

// Then sell
await client.writeContract({
  address: HOOK,
  abi: INKY_PUMP_HOOK_ABI,
  functionName: "sell",
  args: [launchId, tokenAmount, minEthOut, captcha],
})
```

## Listen for Trade events

```typescript theme={null}
import { createPublicClient, http, parseAbiItem } from "viem"

const publicClient = createPublicClient({
  chain: { id: 57073, rpcUrls: { default: { http: ["https://rpc-gel.inkonchain.com"] } } },
  transport: http(),
})

const tradeEvent = parseAbiItem(
  "event Trade(uint256 indexed launchId, address indexed trader, uint8 tradeType, (uint256,uint256) priceData, (uint256,uint256,uint256) tradeData, uint256 refund)"
)

publicClient.watchEvent({
  address: "0x4cC8F6d5B7cE150CCC0A9B7664532B1283b96AC4",
  event: tradeEvent,
  onLogs: (logs) => logs.forEach((log) => console.log(log.args)),
})
```

## Fetch recent V2 tokens from REST

```bash theme={null}
curl "https://inkypump.com/api/tokens/recent-v2?limit=10"
```

Returns the most recent V2 launches with address, ticker, image URL, and target raise.

## Fetch a single token

```bash theme={null}
curl "https://inkypump.com/api/token/0x6791df130bd16722516e891f4fd38651ee382ebb"
```

Returns the token's full record. Includes the `launch_id` field if it is a V2 token.

## Use the MCP server

After the [MCP server](/api-reference/mcp) is registered:

In a Claude Code chat:

```
> wallet_info
> recent_launches { "limit": 5 }
> preview_launch { "name": "Test", "ticker": "TEST", "targetRaiseEth": 2 }
```

The agent calls the MCP tools and returns the JSON responses.

## End to end: launch from cast

```bash theme={null}
# Encode CreateLaunchParams calldata. Easier to do this through cast send with --abi-file.
cast send 0x4cC8F6d5B7cE150CCC0A9B7664532B1283b96AC4 \
  "createLaunch((string,string,string,string,string,string,string,uint96,uint32,uint16,uint32,uint96,uint64))" \
  "(My Token,MINE,Description,https://example.com/image.png,,,,3000000000000000000,50000,7000,40,0,0)" \
  --rpc-url https://rpc-gel.inkonchain.com \
  --private-key $PRIVATE_KEY \
  --value 0
```

Easier through the UI or the MCP for one off launches. Direct contract calls are for automation.
