Sol.College

AI agents on Solana

Agent projects give an LLM a set of tools (functions) that read chain state or build and sign transactions, usually with a dedicated, limited-balance keypair or a delegated session. The important design choices are which tools exist, how signing is gated, and how outputs are validated before anything reaches mainnet.

Reference: Solana docs: AI · Solana Agent Kit

Real code, line by line

1 excerpts from different projects. Each caption links the exact lines at the fork's pinned commit. The notes below each excerpt explain the lines that matter.

solana-foundation/pay · rust/example/server.ts L150–175 @ e22d0af · MIT · original
    res.writeHead(response.status, Object.fromEntries(response.headers))    res.end(await response.text())  })   // ── x402 endpoints ──  const facilitatorPort = PORT + 1  await startLocalFacilitator(facilitatorPort, feePayerSigner.address, RPC_URL)   const x402App = express.Router()   // x402 response logger  x402App.use((req, res, next) => {    const origEnd = res.end.bind(res)    res.end = function (...args: any[]) {      if (res.statusCode === 402) {        const hasPayment = !!req.header('X-PAYMENT')        if (hasPayment) {          console.log(`  ${c.gray}${timestamp()}${c.reset} ${c.red}402${c.reset} payment rejected ${c.dim}(x402)${c.reset}`)        } else {          console.log(`  ${c.gray}${timestamp()}${c.reset} ${c.yellow}402${c.reset} challenge sent ${c.dim}(x402)${c.reset}`)        }      } else if (res.statusCode === 200) {        const txHeader = res.getHeader('x-payment-response') as string | undefined        const sig = txHeader ? extractX402TxSig(txHeader) : undefined        const link = sig ? `${c.dim}${surfpoolLink(sig)}${c.reset}` : ''        console.log(`  ${c.gray}${timestamp()}${c.reset} ${c.green}200${c.reset} payment accepted ${c.dim}(x402)${c.reset} ${link}`)
  1. Line 154 // ── x402 endpoints ──: Uses x402, an HTTP 402 pattern where an agent pays per request with an on-chain payment.

Go further

Related lessons

Topics: AI agents · Learning path · Glossary