DEX
Open app

Spending limits vs private keys vs exchange API keys for trading bots

There are three common ways to let a bot or an AI agent trade for you. They differ in who holds your funds, how much the bot can lose and how quickly you can stop it.

The comparison

Private key in the botExchange API keyOn-chain spending limit
Who holds the fundsYou, but the bot can take everythingThe exchangeYou
Maximum lossThe whole walletEverything on the exchange account, unless withdrawals are disabledThe daily cap per allowed token
ScopeNoneTrading on / withdrawals off, sometimes per marketPer token, per day, until a date
RevocationMove all funds to a new walletDelete the key in the exchange's settingsOne transaction
Where the output goesAnywhere the bot decidesThe exchange accountOnly your wallet
Counterparty riskNoneThe exchange itselfNone beyond the exchanges the contract already uses
Works withAny botBots written for that exchangeAny bot that can call a contract or use the Hopivia API

When each makes sense

A private key is acceptable only for a throwaway wallet that holds exactly the amount you are willing to lose. That is in effect a manual spending limit, with the inconvenience of topping it up.

An exchange API key is the norm for centralized trading. It is well understood, but it keeps your funds on the exchange, and the exchange can freeze, limit or lose them.

An on-chain spending limit keeps the funds in your own wallet and lets a contract enforce the rules. The agent trades at the best available price across decentralized exchanges, the output always returns to you, and revocation is a single transaction. The cost is that the agent pays gas for every trade and the strategy is limited to the tokens and networks where the contract is deployed.

How Hopivia implements limits

The wallet owner allows an agent's address for specific tokens with a daily cap and an expiry. The agent calls the contract's swap function with its own wallet; the contract pulls the input from the owner's wallet, swaps on one of the exchanges in its fixed list and sends the output to the owner. The contract has no owner or admin functions. Details are in the guide on limited access for AI agents and in the API documentation.

FAQ

Is an on-chain limit safer than an exchange API key with withdrawals disabled?

They protect against different things. The exchange key protects against withdrawals but not against the exchange itself. The on-chain limit protects against the bot and keeps the funds in your wallet, but a careless bot can still lose up to the cap through bad trades.

Can I combine approaches?

Yes. Many people keep a small on-chain budget for an AI agent to experiment with and leave the main holdings untouched.

Does a spending limit cost anything to set up?

Two transactions on the network: a token allowance and the limit itself. Afterwards the agent pays the gas of each trade.

Updated: