Skip to main content
This guide explains the full Agent V2 authentication flow and how the Bags skill uses your credentials to run fee claiming, trading, and token launch workflows.

Prerequisites

Before starting, make sure you have:
  • Node.js 18+ and npm
  • curl and jq
  • A local Solana keypair file for your agent
  • Dependencies for signing:

Endpoints Used in This Guide

1. Create or Load an Agent Wallet

Create a local keypair (once), then print your wallet address.
Save the address as BAGS_WALLET:

2. Initialize Authentication Challenge

Request a challenge message and nonce:
Expected shape:

3. Sign the Challenge Message

The message returned by init is base58-encoded. Decode it to bytes, sign using your Ed25519 key, then base58-encode the signature.

4. Complete Signature Callback

Send the signature payload:
Two outcomes are possible:
  1. API key returned immediately
  2. MFA required (mfaRequired: true) and authCode returned

5. Handle MFA Callback (If Required)

If callback returns mfaRequired: true, call the same endpoint again with your MFA code:

6. Store Credentials Securely

Save returned credentials in a local file:

How the Skill Works After Authentication

Once api_key is stored, the skill follows a consistent pattern:
  1. Read ~/.config/bags/credentials.json
  2. Call a domain endpoint with x-api-key
  3. If a transaction is returned, sign with local keypair
  4. Submit through POST /solana/send-transaction

Skill Modules and Their Endpoints

Alternative: Using the Bags CLI

This section requires the Bags CLI. See Install and Set Up the Bags CLI to get started.
The CLI handles authentication in two modes:
  • wallet (default): init/sign/callback (+ MFA when required)
  • manual: validate a provided API key via sdk.auth.me()
Instead of writing scripts with curl and jq, you can authenticate in a single command: Quick setup (wallet + auth in one step):
Quick setup (manual API key mode):
Or step by step:
Manual step-by-step variant:
Manage credentials:
The CLI stores credentials in ~/.config/bags/credentials.json with 0600 permissions and includes authMode metadata (wallet or manual). Existing credentials without authMode are treated as wallet.

Security and Reliability Notes

  • Nonces are single-use and expire quickly (re-run init if expired).
  • Never expose secret key bytes in logs.
  • Keep keypair and credentials files at chmod 600.
  • API key is shown once on successful callback; store it immediately.
  • For retries, regenerate a fresh nonce and signature rather than replaying old payloads.

Common Errors

  • Nonce not found or expired: run init again, sign the new message, retry callback.
  • Invalid signature: ensure you sign decoded message bytes, not the plain base58 string.
  • Invalid or expired auth code: rerun signature callback to get a fresh authCode.
  • Too many requests: wait and retry (auth endpoints are rate-limited).