Code Examples

Real-world examples and use cases for integrating AURA into your applications.

Basic Chat Interface

Create a simple chat interface with AURA in React:

React Component
import { useState } from 'react'
import { Aura } from '@aura/sdk'

const aura = new Aura({ apiKey: process.env.REACT_APP_AURA_KEY })

export function AuraChat() {
  const [messages, setMessages] = useState([])
  const [input, setInput] = useState('')
  const [loading, setLoading] = useState(false)

  const handleSubmit = async (e) => {
    e.preventDefault()
    if (!input.trim()) return

    // Add user message
    const userMsg = { role: 'user', content: input }
    setMessages([...messages, userMsg])
    setInput('')
    setLoading(true)

    try {
      // Get AURA response
      const response = await aura.chat(input)
      const auraMsg = { role: 'aura', content: response.content }
      setMessages(prev => [...prev, auraMsg])
    } catch (error) {
      console.error('AURA Error:', error)
    } finally {
      setLoading(false)
    }
  }

  return (
    <div className="chat-container">
      <div className="messages">
        {messages.map((msg, i) => (
          <div key={i} className={`message message-${msg.role}`}>
            {msg.content}
          </div>
        ))}
        {loading && <div className="typing">AURA is typing...</div>}
      </div>
      <form onSubmit={handleSubmit}>
        <input
          value={input}
          onChange={(e) => setInput(e.target.value)}
          placeholder="Ask AURA anything..."
        />
        <button type="submit">Send</button>
      </form>
    </div>
  )
}

Solana Wallet Helper

Use AURA to validate wallet addresses and provide security tips:

TypeScript
import { Aura } from '@aura/sdk'
import { PublicKey } from '@solana/web3.js'

const aura = new Aura({
  apiKey: process.env.AURA_API_KEY,
  network: 'mainnet-beta'
})

async function validateWalletWithAura(address: string) {
  // Validate format
  try {
    new PublicKey(address)
  } catch {
    return { valid: false, message: 'Invalid address format' }
  }

  // Check with AURA for known scams
  const validation = await aura.validateAddress(address)

  if (validation.isScam) {
    return {
      valid: false,
      message: '⚠️ Warning: This address is flagged as suspicious',
      details: validation.reason
    }
  }

  // Get security tips
  const tips = await aura.getKnowledge('security')

  return {
    valid: true,
    message: '✓ Address appears safe',
    securityTips: tips
  }
}

// Usage
const result = await validateWalletWithAura('7xKXt...AbC')
console.log(result.message)

Knowledge Base Queries

Query specific knowledge domains for educational content:

JavaScript
import { Aura } from '@aura/sdk'

const aura = new Aura({ apiKey: process.env.AURA_API_KEY })

// Get specific knowledge
async function getTutorial(topic) {
  const knowledge = {
    solana: await aura.getKnowledge('solana'),
    jito: await aura.getKnowledge('jito'),
    jupiter: await aura.getKnowledge('jupiter'),
    security: await aura.getKnowledge('security')
  }

  return knowledge[topic] || 'Topic not found'
}

// Natural language query
async function askAura(question) {
  const response = await aura.chat(question, {
    knowledge: ['solana', 'web3', 'security'],
    temperature: 0.7,
    includeMetadata: true
  })

  console.log('Answer:', response.content)
  console.log('Confidence:', response.confidence)
  console.log('Topics:', response.topics)

  return response
}

// Examples
await getTutorial('solana')
await askAura('How does Jupiter aggregator work?')
await askAura('What are the risks of sharing private keys?')

CLI Tool

Build a command-line tool powered by AURA:

Node.js CLI
#!/usr/bin/env node
import { Aura } from '@aura/sdk'
import readline from 'readline'

const aura = new Aura({ apiKey: process.env.AURA_API_KEY })

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})

console.log('🌟 AURA Terminal - Divine Intelligence CLI')
console.log('Type your question or /help for commands\n')

function prompt() {
  rl.question('> ', async (input) => {
    if (!input.trim()) {
      prompt()
      return
    }

    if (input === '/exit' || input === '/quit') {
      console.log('gn fren 🌙')
      rl.close()
      return
    }

    try {
      const response = await aura.chat(input)
      console.log(`\n${response.content}\n`)
    } catch (error) {
      console.error('Error:', error.message)
    }

    prompt()
  })
}

prompt()
Usage:
$ npm install -g aura-cli
$ aura
> Tell me about SVM

Discord Bot Integration

Create a Discord bot that answers questions using AURA:

Discord.js
import { Client, GatewayIntentBits } from 'discord.js'
import { Aura } from '@aura/sdk'

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent
  ]
})

const aura = new Aura({ apiKey: process.env.AURA_API_KEY })

client.on('messageCreate', async (message) => {
  // Ignore bots
  if (message.author.bot) return

  // Only respond to mentions or commands
  const mentioned = message.mentions.has(client.user)
  const isCommand = message.content.startsWith('!aura')

  if (!mentioned && !isCommand) return

  // Extract query
  const query = message.content
    .replace(`<@${client.user.id}>`, '')
    .replace('!aura', '')
    .trim()

  if (!query) {
    message.reply('gm! Ask me anything about Solana, Web3, or dev life.')
    return
  }

  try {
    // Show typing indicator
    await message.channel.sendTyping()

    // Get AURA response
    const response = await aura.chat(query)

    // Send response (split if too long)
    const chunks = response.content.match(/[\s\S]{1,2000}/g)
    for (const chunk of chunks) {
      await message.reply(chunk)
    }
  } catch (error) {
    message.reply('Oops! Divine connection interrupted. Try again.')
  }
})

client.login(process.env.DISCORD_TOKEN)