NEAR Protocol AI Agents: What Builders Need to Know in 2026
NEAR Protocol has emerged as the leading chain for on-chain AI agents with its Chain Signatures, NEAR AI framework, and sub-cent transaction fees. Everything you need to build AI agents on NEAR.
Builder of AI agents, crypto trading bots, and open-source automation tools. Sharing practical guides on how to build, deploy, and profit from AI and DeFi technology.
Why NEAR for AI Agents?
NEAR Protocol made a bold pivot in 2025: becoming the default blockchain for AI. The strategy worked. NEAR is now home to:
- NEAR AI: An open-source AI model and agent framework
- Chain Signatures: Native multi-chain signing (your NEAR agent can sign Ethereum, Bitcoin, Solana transactions)
- Intents: High-level transaction specification that lets AI agents abstract away cross-chain complexity
- Social.near: On-chain social graph for AI agent interactions
- $0.001 transactions: Cheap enough for AI to make dozens of calls per interaction
Chain Signatures: The Killer Feature for AI Agents
Chain Signatures let a NEAR account sign and execute transactions on ANY blockchain โ no bridges, no wrapped assets.
A NEAR AI agent can:
- Hold funds natively on Bitcoin, Ethereum, Solana, and 30+ chains
- Execute trades on all chains from a single NEAR account
- Sign transactions on behalf of users across any blockchain
// NEAR Chain Signatures example
import { connect, keyStores } from 'near-api-js'
const MULTICHAIN_CONTRACT = 'v1.signer'
async function signEthereumTransaction(
nearAccountId: string,
ethTxData: object,
derivationPath: string = 'ethereum-1'
): Promise<string> {
const near = await connect({
networkId: 'mainnet',
keyStore: new keyStores.InMemoryKeyStore(),
nodeUrl: 'https://rpc.mainnet.near.org',
})
const account = await near.account(nearAccountId)
// Request signature from NEAR's MPC network
const result = await account.functionCall({
contractId: MULTICHAIN_CONTRACT,
methodName: 'sign',
args: {
payload: ethTxData, // The Ethereum tx to sign
path: derivationPath,
key_version: 0,
},
gas: '300000000000000', // 300 TGas
attachedDeposit: '1', // 1 yoctoNEAR
})
return result.transaction.hash
}
Building an AI Trading Agent on NEAR
import { connect, keyStores, utils } from 'near-api-js'
import OpenAI from 'openai'
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
class NearAITradingAgent {
private account: any
async initialize(accountId: string, privateKey: string) {
const keyStore = new keyStores.InMemoryKeyStore()
await keyStore.setKey('mainnet', accountId, utils.KeyPair.fromString(privateKey))
const near = await connect({
networkId: 'mainnet',
keyStore,
nodeUrl: 'https://rpc.mainnet.near.org',
})
this.account = await near.account(accountId)
console.log(`Agent initialized: ${accountId}`)
}
async getPortfolioContext(): Promise<string> {
// Get NEAR balance
const state = await this.account.state()
const nearBalance = utils.format.formatNearAmount(state.amount, 5)
// Get token balances via NEAR FT standard
const usdc = await this.getTokenBalance('usdc.tether-token.near', 6)
return `Portfolio: ${nearBalance} NEAR, ${usdc} USDC`
}
async getTokenBalance(contractId: string, decimals: number): Promise<string> {
try {
const result = await this.account.viewFunction({
contractId,
methodName: 'ft_balance_of',
args: { account_id: this.account.accountId },
})
return (parseInt(result) / Math.pow(10, decimals)).toFixed(2)
} catch {
return '0'
}
}
async analyzeAndTrade(): Promise<void> {
const portfolio = await this.getPortfolioContext()
const marketData = await this.getMarketData()
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{
role: 'system',
content: `You are an AI trading agent operating on NEAR Protocol.
You make trading decisions on the Ref Finance DEX.
Be conservative. Protect capital. Max 2% of portfolio per trade.
Respond with JSON: { action: "buy"|"sell"|"hold", asset: string, amount_usdc: number, reasoning: string }`
},
{
role: 'user',
content: `${portfolio}\n\nMarket data: ${marketData}\n\nWhat should I do?`
}
],
response_format: { type: 'json_object' }
})
const decision = JSON.parse(response.choices[0].message.content!)
console.log(`AI Decision: ${JSON.stringify(decision)}`)
if (decision.action !== 'hold') {
await this.executeTrade(decision)
}
}
async executeTrade(decision: { action: string, asset: string, amount_usdc: number }): Promise<void> {
// Execute on Ref Finance (NEAR's main DEX)
const REF_FINANCE = 'v2.ref-finance.near'
const tokenMaps: Record<string, string> = {
'NEAR': 'wrap.near',
'ETH': 'aurora',
'BTC': 'bitcoin.factory.bridge.near',
}
const tokenOut = tokenMaps[decision.asset]
if (!tokenOut) {
console.log(`Unknown asset: ${decision.asset}`)
return
}
// Get swap route from Ref Finance
// ... actual DEX interaction code ...
console.log(`Executing ${decision.action} ${decision.amount_usdc} USDC โ ${decision.asset}`)
}
async getMarketData(): Promise<string> {
const response = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=near,bitcoin,ethereum&vs_currencies=usd&include_24hr_change=true')
const data = await response.json()
return JSON.stringify(data)
}
}
// Run the agent
const agent = new NearAITradingAgent()
await agent.initialize(process.env.NEAR_ACCOUNT_ID!, process.env.NEAR_PRIVATE_KEY!)
await agent.analyzeAndTrade()
NEAR Intents: AI-Native Transactions
NEAR Intents let you specify what you want (outcome-focused) rather than how to do it (step-by-step). This is perfect for AI agents:
// Intent: "Buy $1000 of BTC at the best available price across all chains"
const intent = {
intent_type: 'swap',
token_in: 'usdc.tether-token.near',
amount_in: '1000000000', // 1000 USDC (6 decimals)
token_out: 'bitcoin.factory.bridge.near', // Wrapped BTC on NEAR
min_amount_out: null, // Let solver find best route
deadline: Date.now() + 30000, // 30 second deadline
}
// Solvers (professional market makers) compete to fill your intent
// at the best price across any chain
await account.functionCall({
contractId: 'intents.near',
methodName: 'create_intent',
args: { intent },
gas: '100000000000000',
})
NEAR AI: Open Source AI Models
NEAR launched an open-source AI model and agent framework that integrates natively with the blockchain:
# Install NEAR AI CLI
pip install nearai
# Run NEAR's open-source agent framework
nearai agent interactive near/ai-trading-agent/latest
Why NEAR AI Agents Are Different
- On-chain state: Agent memory persisted on blockchain, not a centralized server
- Verifiable actions: Every action the agent takes is recorded on-chain and auditable
- Multi-chain native: One agent, every blockchain
- Social integration: Agents can interact via Social.near (decentralized social graph)
NEAR is making the boldest bet in crypto: that AI agents will be the primary users of blockchain. For developers, this means the tools, documentation, and community are all focused on making AI agent development as easy as possible.
Tagged in
Related Articles
Virtuals Protocol and AI Agent Tokens: The On-Chain AI Economy Explained
5 min read
AI AgentsGrok AI for Crypto Trading: How Elon's AI Gives an Edge in 2026
4 min read
AI AgentsHow to Build a Crypto Twitter (X) Bot That Goes Viral in 2026
5 min read
AI AgentsAgentic AI Frameworks Compared: LangGraph vs CrewAI vs AutoGen in 2026
6 min read