AUTONEX

JavaScript SDK

The official JavaScript/TypeScript SDK for AUTONEX. Build autonomous agents with full type safety and modern async/await patterns.

Installation

npm install @autonex/sdk-js
# or
yarn add @autonex/sdk-js
# or
pnpm add @autonex/sdk-js

Quick Start

Initialize Client

import { AutonexClient } from '@autonex/sdk-js'
import { Keypair } from '@solana/web3.js'

// Initialize client
const client = new AutonexClient({
  rpcUrl: process.env.SOLANA_RPC_URL,
  agentKeypair: Keypair.fromSecretKey(/* your keypair */),
  policySet: 'my-agent-policy',
  network: 'mainnet-beta' // or 'devnet'
})

Submit Intent

import { Intent } from '@autonex/sdk-js'

// Create swap intent
const intent = Intent.swap({
  from: { token: 'SOL', amount: 5 },
  to: { token: 'USDC' },
  maxSlippage: 0.02, // 2%
  deadline: Date.now() + 60000 // 1 minute
})

// Execute
const receipt = await client.execute(intent)

console.log('Transaction:', receipt.signature)
console.log('Amount out:', receipt.execution.amountOut)
console.log('Actual slippage:', receipt.execution.actualSlippage)

API Reference

AutonexClient

Main client for interacting with AUTONEX.

Constructor Options

  • rpcUrl: Solana RPC endpoint URL
  • agentKeypair: Agent's Solana keypair
  • policySet: Name of policy set to use
  • network: Network identifier (mainnet-beta, devnet, testnet)

Methods

  • execute(intent): Submit and execute an intent
  • simulate(intent): Simulate intent execution
  • getReceipt(signature): Fetch execution receipt
  • getPolicy(name): Retrieve policy set configuration
  • deployPolicy(policy): Deploy new policy on-chain

Intent Types

All available intent constructors:

Intent.swap(params)

Exchange tokens via DEX aggregators.

  • from: Source token and amount
  • to: Destination token
  • maxSlippage: Maximum acceptable slippage
  • deadline: Execution deadline (Unix timestamp)

Intent.transfer(params)

Transfer tokens to another address.

  • token: Token to transfer
  • amount: Amount to transfer
  • to: Recipient address

Intent.stake(params)

Stake tokens with validators or pools.

  • token: Token to stake
  • amount: Amount to stake
  • validator: Validator or pool address

Advanced Features

Simulation

Test intents before execution:

// Simulate before executing
const simulation = await client.simulate(intent)

if (simulation.success) {
  console.log('Expected output:', simulation.amountOut)
  console.log('Estimated slippage:', simulation.slippage)
  
  // If simulation looks good, execute
  const receipt = await client.execute(intent)
} else {
  console.error('Simulation failed:', simulation.error)
}

Policy Management

Create and deploy policies programmatically:

import { PolicyBuilder } from '@autonex/sdk-js'

// Create policy set
const policy = new PolicyBuilder('trading-agent')
  .addRule('transaction_limit', {
    amount: 10,
    token: 'SOL',
    period: 'daily'
  })
  .addRule('slippage_protection', {
    maxSlippage: 0.02
  })
  .addRule('whitelist_programs', {
    programs: ['JUP4Fb...', 'whirLbMi...']
  })
  .build()

// Deploy policy on-chain
await client.deployPolicy(policy)

Event Streaming

Subscribe to real-time execution events:

// Subscribe to execution events
client.on('intent:submitted', (intent) => {
  console.log('Intent submitted:', intent.id)
})

client.on('policy:evaluated', (result) => {
  console.log('Policy result:', result.passed)
})

client.on('execution:complete', (receipt) => {
  console.log('Execution complete:', receipt.signature)
})

client.on('execution:failed', (error) => {
  console.error('Execution failed:', error)
})

Error Handling

The SDK throws typed errors for different failure modes:

  • IntentValidationError: Invalid intent structure
  • PolicyRejectionError: Intent rejected by policy
  • ExecutionError: Transaction execution failed
  • NetworkError: RPC or network issues

TypeScript Support

Full TypeScript support with type inference:

  • Typed intent parameters
  • Typed receipt structures
  • Typed policy configurations
  • IntelliSense support in IDEs

Examples

Check out complete examples in the GitHub repository:

  • Simple trading agent
  • Multi-agent coordination
  • Custom policy creation
  • Receipt verification