How Agents Interact With Smart Contracts
Last updated 2026-06-24
Agents interact with smart contracts in two modes: reading state (balances, prices, governance proposals, events) and writing state (swaps, transfers, votes, deployments). Reading is low-risk; writing is where guardrails matter.
Key takeaways
- ▸Contract interaction has two modes: reading state (no keys, low-risk) and writing transactions (spends funds, irreversible). Treat them differently.
- ▸Every call needs the contract's **ABI** — the schema that says which functions exist and how to encode arguments — plus an **RPC** endpoint to reach the chain.
- ▸Simulate before signing. A dry run via `eth_call` or a tool like Tenderly predicts the outcome and catches reverts before real funds move.
- ▸The dangerous failure modes are economic, not just technical: slippage, MEV, stale data, and lingering token approvals — not only transactions that revert.
- ▸SDKs like [GOAT](/resources/goat-sdk) and [Solana Agent Kit](/resources/solana-agent-kit) wrap ABIs, encoding, and RPC into typed actions an agent can call.
Smart contract agents are AI agents that read from and write to smart contracts directly — querying a lending pool's rate, then supplying to it; checking a DAO proposal, then voting. The interaction splits into two modes with very different stakes. Reading state (balances, prices, events) needs no keys and moves no money, so it's cheap to get wrong. Writing state — a swap, a transfer, a vote, a deployment — spends real funds and is irreversible once mined.
That asymmetry shapes every design decision. This page walks the full path an agent takes to touch a contract: how it finds the function (the ABI), how it talks to the chain (RPC), how it checks an action before committing (simulation), what gas and the mempool do to it, and the failure modes that turn a clean demo into a drained wallet. The wallet itself is covered in how agents use wallets — here we focus on the contract on the other side of the signature.
Why It Matters
Smart contracts are the API of the onchain economy. An agent that can read and write contract state can participate in DeFi, governance, and commerce as a first-class economic actor. The patterns for doing this safely define which agent use cases are viable.
How It Works
- ▸Read path: the agent queries chain state through RPC nodes, indexers, or data MCPs, no keys required.
- ▸Write path: the agent constructs a transaction (often via a skill library that wraps the protocol's SDK), simulates it, then submits it through its wallet for signing.
- ▸Simulation and dry runs catch reverts and unexpected outcomes before real funds move.
- ▸Monitoring: agents watch events and mempool activity to react to onchain conditions.
Key Components
- •RPC / node access
- •Indexers and data layers
- •Protocol SDKs and skill libraries
- •Transaction simulation
- •Wallet and policy layer
- •Event monitoring
Reading vs. writing: two different risk profiles
Every contract interaction is either a read or a write, and the gap between them is the whole game.
Reads call view or pure functions — balanceOf, getReserves, the state of a governance proposal. They execute against a node's local copy of the chain, cost no gas, need no private key, and change nothing. An agent can read as often as it wants. The only real risks are *stale* or *wrong* data: a lagging indexer, a reorged block, or a manipulated price feed.
Writes send a signed transaction that mutates state — a swap on a DEX, a transfer, a vote, a deployment. They cost gas, require the agent's wallet to sign, and are irreversible once mined. This is where spend limits, permission scoping, and human-approval steps earn their keep. A useful rule for onchain agents: reads can run autonomously; writes above a threshold should pass a guardrail first.
The mechanics: ABIs, RPC, and encoding a call
To touch a contract, an agent needs two things.
- ▸The ABI (Application Binary Interface) — a JSON schema listing the contract's functions, their inputs, and outputs. It's how the agent knows
swapExactTokensForTokensexists and what arguments it takes. Without the right ABI, a call is just undecodable bytes. - ▸An RPC endpoint — the connection to a node that relays reads and broadcasts transactions. Providers like Alchemy or a self-hosted node expose the standard JSON-RPC API:
eth_callfor reads,eth_sendRawTransactionfor writes,eth_estimateGasfor sizing.
The flow: the agent takes a function name plus arguments, ABI-encodes them into calldata, and sends that to the RPC. For a read it uses eth_call and decodes the result; for a write it builds a full transaction object, signs it, and broadcasts. Libraries such as viem handle the encode/decode automatically from the ABI — readContract({ address, abi, functionName }) is the entire read path.
Simulate before you sign
The single most important habit for a write-capable agent is simulation — running the transaction against current chain state without broadcasting it, to see exactly what it would do.
A basic simulation is just eth_call against the same calldata you'd submit: it executes in the node's EVM and returns the result or the revert reason, for free. Richer tooling like Tenderly Simulations predicts the full state changes, token deltas, and emitted events before anything is signed.
For an agent this is non-negotiable, because the model's reasoning can be confidently wrong. Simulation answers questions a write should never skip: *Will this revert? How many tokens come back? Is the price within tolerance?* Catching a bad outcome in simulation costs nothing; catching it on-chain costs the trade. The same logic underpins risk limits on a trading agent — simulate, check against policy, then sign.
Gas, nonces, and the failure modes that bite
Even a correct call meets the messy reality of a live chain. The recurring failure modes:
- ▸Gas estimation and spikes.
eth_estimateGasgives a baseline, but estimates can be wrong for state-dependent calls, and fees move before inclusion. Underpriced transactions stall; over-tight gas limits revert mid-execution. - ▸Nonce management. Transactions are ordered by nonce. An agent firing several writes in quick succession can collide nonces, stranding later ones until the gap is filled.
- ▸Slippage and MEV. Between simulation and inclusion, the price can move or a searcher can sandwich the trade. Without slippage bounds, a swap can execute at a far worse rate than simulated.
- ▸Reverts and partial state. A transaction can revert after spending gas, returning nothing but a fee bill.
- ▸Approval risk. An unlimited token allowance that's never revoked leaves funds exposed if that contract is later compromised. Scope approvals to the amount needed.
None of these are exotic. They're the standard tax of writing to a public chain, and an agent that ignores them will eventually pay it.
The SDKs that wrap all this
Few teams hand-roll ABI encoding and nonce logic. Agent skill libraries wrap the contract layer into typed actions the model can call as tools.
- ▸[GOAT SDK](/resources/goat-sdk) exposes onchain actions across EVM chains and Solana as agent tools, bundling wallet signing with protocol integrations so the model calls
swaportransferinstead of building calldata (repo). - ▸[Solana Agent Kit](/resources/solana-agent-kit) does the same for Solana, wrapping dozens of program interactions behind agent-callable functions (repo).
- ▸Read-heavy agents often add an MCP server or indexer that serves chain state in one interface, so the model queries data without managing raw RPC.
These abstractions are conveniences, not magic. The agent still signs real transactions against real contracts, and the ABI, simulation, and gas concerns above don't disappear — the SDK just stops you re-implementing them. Whether a given library is open and active, rather than self-reported, is the kind of thing the Sato Score tracks.
Examples
- ▸A DeFi agent reading pool states across venues and executing a rebalance when yields diverge.
- ▸A governance agent that reads new proposals and casts votes per a delegated policy.
- ▸A security agent monitoring contract events for anomalies and pausing positions when triggered.
Risks & Limitations
- ⚠Unsimulated transactions can revert or execute at terrible prices (slippage, MEV).
- ⚠Malicious contracts can drain approvals, approval hygiene is critical.
- ⚠Stale data leads to bad decisions; chain reorgs and indexer lag are real.
- ⚠Complex DeFi interactions compound smart-contract risk with agent-reasoning risk.
Frequently Asked Questions
- What's the difference between an agent reading and writing to a smart contract?
Reading calls a
view/purefunction — likebalanceOfor a pool's price — against a node's local state. It needs no private key, costs no gas, and changes nothing. Writing sends a signed transaction that mutates state (a swap, transfer, or vote); it costs gas, needs the agent's wallet to sign, and is irreversible once mined. Reads are low-risk and can run autonomously; writes are where guardrails belong.- What does an AI agent need to call a smart contract?
Two things: the contract's ABI (a JSON schema of its functions and arguments, so the agent can encode the call) and an RPC endpoint to reach a node. The agent ABI-encodes the function and arguments into calldata, then uses
eth_callfor a read or signs and broadcasts a transaction for a write. SDKs like GOAT handle the encoding from the ABI automatically.- Why should an agent simulate a transaction before sending it?
Because an LLM's reasoning can be confidently wrong, and on-chain mistakes are irreversible. Simulation runs the transaction against current state without broadcasting it — via
eth_callor a tool like Tenderly — and returns the outcome, revert reason, and token deltas. It answers 'will this revert and what do I get back?' for free, before any funds move.- What are the most common failure modes for smart contract agents?
They're mostly economic, not just code bugs: slippage and MEV moving the price between simulation and inclusion, gas mis-estimation, nonce collisions when firing transactions quickly, reverts that still burn gas, and stale token approvals that leave funds exposed. Slippage bounds, simulation, and scoped approvals address most of them.
- Do agents write smart contract calls from scratch?
Rarely. Skill libraries such as GOAT SDK and Solana Agent Kit wrap ABI encoding, signing, and RPC into typed actions the model calls as tools, so it invokes
swaportransferrather than building raw calldata. The underlying transaction is still real — the SDK just removes the boilerplate, not the risk.
Sources
Related Resources
Solana Agent Kit
ActiveSendAI's open-source toolkit connecting AI agents to Solana protocol actions.
GOAT SDK
ActiveCrossmint's open-source library of onchain actions (tools) for AI agents across chains.
Olas (Autonolas)
ActiveNetwork and framework for co-owned autonomous agent services operating onchain.
Bankless Onchain MCP
UnknownMCP server providing AI assistants read access to onchain data via the Bankless API.
Related Wiki Pages
Join the Sato Hub Briefing
One email a week — the agents, tools, and infrastructure that actually shipped, and why they matter.