# Quickstart

Make your first on-chain agent payment in under five minutes.

***

## Prerequisites

* Node.js 18+ or Python 3.10+
* A RailProtocol account at [app.railprotocol.org](https://app.railprotocol.org)

***

## Step 1: Install the CLI

```bash
npm install -g @railprotocol/cli
```

Verify the installation:

```bash
rail --version
# railprotocol/cli v1.0.0 darwin-arm64
```

***

## Step 2: Authenticate

```bash
rail auth login
```

This opens a browser window to complete authentication. Your credentials are stored in `~/.railprotocol/credentials`.

For non-interactive environments (CI, scripts):

```bash
rail auth login --token $RAIL_API_KEY
```

***

## Step 3: Create an agent wallet

Every agent that makes payments needs a wallet. Wallets are non-custodial Solana program-derived addresses owned by the agent's keypair.

```bash
rail wallet create --agent my-agent
```

Output:

```
Agent wallet created.

  Agent:    my-agent
  Address:  7xKXtg2xpAGMq8KLwpSodE9LFKq8Z1EscezSShpump
  Balance:  0.00 USDC
  Network:  Solana Mainnet
```

***

## Step 4: Fund the wallet

Top up via the dashboard at [app.railprotocol.org](https://app.railprotocol.org), or transfer USDC directly to the wallet address shown above.

To check balance at any time:

```bash
rail wallet balance --agent my-agent
# Balance: 50.00 USDC
```

***

## Step 5: Set spend policies

Policies are enforced at the gateway before any payment is submitted. Set them once.

```bash
rail policies set my-agent \
  --daily-budget 10 \
  --per-call-limit 0.50 \
  --allowed-domains "api.dune.com,api.browserbase.com"
```

***

## Step 6: Make your first payment

Install the SDK:

```bash
npm install @railprotocol/sdk
```

```typescript
import { RailProtocol } from "@railprotocol/sdk";

const rail = new RailProtocol({
  agentId: "my-agent",
  apiKey: process.env.RAIL_API_KEY,
});

const result = await rail.pay({
  endpoint: "https://api.dune.com/v1/query/1234/results",
  method: "GET",
});

console.log(result.status);       // 200
console.log(result.protocol);     // "x402"
console.log(result.amountPaid);   // { usdc: 0.002 }
console.log(result.txHash);       // Solana transaction hash
console.log(result.data);         // The actual API response
```

RailProtocol detects the payment protocol automatically and handles the full handshake. You do not need to know whether the service uses x402 or MPP.

***

## Step 7: View the on-chain record

Every payment is recorded on Solana. View your transaction history:

```bash
rail transactions list --agent my-agent
```

Output:

```
TX HASH                      PROTOCOL  AMOUNT     ENDPOINT                           TIME
5yJ8kX...mQ9pL              x402      0.002 USDC  api.dune.com/v1/query/...          just now
```

Click the transaction hash in the dashboard to open the Solana Explorer entry directly.

***

## Next steps

* [How the payment router works](/features/payment-router.md)
* [Agent wallet reference](/features/agent-wallets.md)
* [Full spend policy options](/features/spend-policies.md)
* [TypeScript SDK reference](/sdk/typescript.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.railprotocol.org/getting-started/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
