
Markus_automation
Expert in data parsing and automation
A bot for swapping tokens on decentralized exchanges (DEXs) can work in two ways: it can send transactions directly to smart contracts using ethers.js or viem, or it can control the exchange's website through Puppeteer. The first approach is faster, but it cannot always reproduce the logic that DEXs hide in private APIs and front-end code. The second can handle that logic, but it takes seconds to load a page. This article will help you choose a bot architecture for your needs: determine whether direct contract calls are enough, when a browser is essential, and how to combine the two approaches. We'll also explain how a browser-based bot can pass anti-bot checks.
Contents
Maintain your online anonymity with Octo Browser. Your real digital fingerprint cannot be tracked.
Would you like to try Octo Browser at а discount?
Use the promo code OCTOBLOG to get 30% off any subscription. This offer is valid only for new users.
Approach #1: ethers.js and viem: interacting directly with the protocol's financial core
The protocol-level approach means communicating directly with the blockchain without going through the exchange's website. The ethers.js and viem libraries build requests and send them directly to smart contracts. Web3.js was commonly used for this in the past, but in March 2025, ChainSafe discontinued support for the library and recommended switching to alternatives.
The solution doesn't need to download images or fonts or wait for the interface to load, so it works quickly. However, the developer must have a good understanding of the smart contracts used by the specific exchange.
The most challenging cases are those in which the platform's private API or front-end code generates the calldata and signatures. Reproducing that algorithm using only Web3 libraries is technically possible, but it can take weeks. One exception is aggregators with official APIs, such as 1inch and 0x: they return ready-made calldata for a transaction, but you need an API key to use them.
To execute a trade, the script performs three steps:
ABI encoding. The ABI (Application Binary Interface) describes a contract's functions. The library uses it to convert trade parameters into bytecode that the blockchain can understand. The script calculates fees, the swap route, and slippage limits itself, as this only requires math.
Signing. The script signs the transaction with the wallet's private key.
Sending through an RPC node. The signed transaction is sent to an RPC node, the intermediary between the script and the network. The node forwards it to the mempool, the queue of unconfirmed transactions from which validators retrieve it.
Advantages
Speed. Execution time depends on the connection to the RPC node and block creation time. There's no need to load images, CSS animations, or website scripts.
Lower resource usage. The script doesn't need a browser engine, so you can run hundreds of parallel bots (workers) on a single low-cost VPS.
Independence from the interface. Exchange developers can redesign the website, change classes, and move buttons around. The bot won't notice: smart contract addresses are independent of the front end. You'll only need to change the code if the protocol moves to a new version of its contracts.
Potential drawbacks
Security. The bot needs a private key to sign transactions. The server running the bot must be strictly isolated to prevent the key from leaking.
Dependence on RPC. Public and low-cost RPC endpoints limit request rates on free plans, which can reduce speed. The bottleneck becomes the node, not the script. Arbitrage requires your own node or a dedicated paid endpoint.
MEV bots. Fast transaction submission doesn't protect you from them: MEV bots can see any transaction in the public mempool. Private RPC endpoints, such as Flashbots Protect, reduce the risk by sending transactions to block builders without going through the public mempool.
Approach #2: Puppeteer and Playwright—simulating user actions in a browser
The visual approach uses software to simulate user actions. Puppeteer or Playwright launches a browser, usually in headless mode, navigates to the exchange's website, and waits for the page to load. The bot then finds the necessary fields in the page's code, enters values, and clicks buttons, including confirmation buttons in pop-up windows from wallets such as MetaMask.
This type of bot is slower and requires more RAM. However, it works when direct contract requests are complicated or hidden by the platform's developers. After using ethers.js and viem, running a full browser on a server may seem like a step backward, but an exchange's front end often provides data that can't be obtained directly from the blockchain.
Less obvious advantages of the visual approach
Final amount including fees. Smart contracts work with raw values. An exchange's interface, especially an aggregator's, displays the final amount, taking website fees, gas fees, and the route into account. Puppeteer reads this figure from the page and gets the same data as the user.
Private APIs. If the transaction-generation logic is obfuscated or hidden behind private endpoints, figuring it out takes time. Puppeteer takes a straightforward approach: it clicks a button on the page, and the website generates the route and calldata itself.
Disadvantages of the visual approach
Dependence on page structure. The bot doesn't identify a button by its appearance; it finds it using a selector in the page's code. If the exchange renames the button's CSS class, the script won't find the button to click and will stop with an error. Trading will have to be paused while the code is fixed.
Memory leaks. Headless browsers use a lot of memory. When Chromium instances run 24/7, they accumulate junk and gradually consume all available RAM. The server may freeze at the worst possible moment, such as during a sharp market move.
Key stored on the server. To confirm trades in MetaMask, the wallet containing the private key or seed phrase must also be stored on the server. The isolation requirements are the same as for the protocol-level approach.
How DEX websites detect bots and what to consider
Even flawless code can run into security systems. Exchanges restrict bots because they put a load on servers and can be used to manipulate the market. So the question isn't whether a DEX website has protection, but which system it uses: Cloudflare Turnstile, HUMAN (formerly PerimeterX), DataDome, or something else. The difference between the two approaches is especially clear at this stage.
Protocol-level approach
Ethers.js and viem don't visit the exchange's website. The script communicates with an RPC provider, which is a blockchain node. From the perspective of the DEX website's security systems, this bot doesn't exist: it doesn't request pages or load their scripts.
Low-cost server proxies are suitable here: the blockchain doesn't care about the IP address as long as the transaction is properly signed. There are no website anti-bot systems along this path, but the RPC provider has its own restrictions—request limits and IP blocks.
Visual approach
Puppeteer and similar solutions interact with the exchange's front end, so they are subject to security checks. Server proxies can be counterproductive here: Cloudflare and other anti-bot systems are wary of data center IP addresses. The result can be endless CAPTCHAs or blocked access.
To make a bot look like an ordinary user, you need three components:
Residential or mobile proxies. They make the script look like a user rather than a server in a data center.
Automation masking. Puppeteer reveals by default that a script is controlling the browser, for example through the
navigator.webdriverproperty. Without an anti-detect browser, stealth plugins are used to hide these indicators.A unique digital fingerprint. Security systems check many browser parameters: how it renders fonts, which graphics card it reports, and how it processes audio. If all bots have the same fingerprint, they can be linked as one network and blocked.
An anti-detect browser such as Octo Browser provides a unique fingerprint for each bot. In Octo, each profile is an isolated environment with its own fingerprint, cookies, and proxy. The profile is launched through Octo's local API, which returns the CDP endpoint of the running browser. Puppeteer or Playwright connects to it just as it would to a regular Chrome browser. This way, each bot runs in its own profile, making it harder for security systems to link them by their fingerprints. Stealth plugins aren't needed in this setup.
If you need scalability and low costs, ethers.js or viem are good options: they don't need to pass website security checks. The visual approach requires a budget for proxies and fingerprint management solutions.
Summary of architectural differences
Feature | ethers.js/viem | Puppeteer/Playwright |
Entry point | RPC node (blockchain) | Platform's web server (DOM) |
Transaction submission time | Milliseconds; confirmation depends on block time | Seconds; depends on rendering |
Dependence on the interface | None; interacts with the contract | Critical; relies on selectors |
Website protection (WAF) | Doesn't interact with the DEX website, but is subject to RPC limits | Requires residential IPs, automation masking, and a unique fingerprint |
Implementation complexity | High: contracts must be analyzed | Lower initially, higher to maintain |
Resource usage | Minimal | High (CPU and RAM) |
Hybrid approach
For complex tasks, responsibilities can be divided among system components. If a browser takes so long to load the interface, why use it together with ethers.js or viem?
The idea behind the hybrid approach is to remove Puppeteer from the critical path of trade execution and use it only to collect data. The browser scouts, while the cryptographic module pulls the trigger.
Here's what this can look like in practice:
Reconnaissance module (Puppeteer or Playwright). The browser is used only to parse dynamically changing parameters.
Data transfer. Data extracted from the interface is passed to an isolated Node.js service.
Execution module (ethers.js or viem). The service builds the transaction, signs it locally, and sends it to the network's mempool through a fast RPC channel.
As a result, the system spends a couple of seconds calculating the route in the browser but gets accurate data from the obfuscated front end. It also saves several more seconds by avoiding transaction confirmation through the wallet interface.
This setup has one limitation: front-end calldata is usually tied to the connected wallet address and the quote's expiration time. Therefore, the browser module must use the same address as the execution module, and the data must be used immediately after it's received.
Conclusion
The choice of solution depends on where the transaction is generated. If you can build the calldata yourself or obtain it through an aggregator's official API, ethers.js or viem will provide speed and scalability. If a private front end generates the route and signatures, you need a browser—Puppeteer or Playwright with proxies and unique fingerprints.
A hybrid approach works well for complex aggregators: the browser collects the data, and the library signs and sends the transaction. Knowing when to use a browser for reconnaissance and when to interact directly with a smart contract is what distinguishes a resilient system from an unstable script.
Maintain your online anonymity with Octo Browser. Your real digital fingerprint cannot be tracked.
Would you like to try Octo Browser at а discount?
Use the promo code OCTOBLOG to get 30% off any subscription. This offer is valid only for new users.
Approach #1: ethers.js and viem: interacting directly with the protocol's financial core
The protocol-level approach means communicating directly with the blockchain without going through the exchange's website. The ethers.js and viem libraries build requests and send them directly to smart contracts. Web3.js was commonly used for this in the past, but in March 2025, ChainSafe discontinued support for the library and recommended switching to alternatives.
The solution doesn't need to download images or fonts or wait for the interface to load, so it works quickly. However, the developer must have a good understanding of the smart contracts used by the specific exchange.
The most challenging cases are those in which the platform's private API or front-end code generates the calldata and signatures. Reproducing that algorithm using only Web3 libraries is technically possible, but it can take weeks. One exception is aggregators with official APIs, such as 1inch and 0x: they return ready-made calldata for a transaction, but you need an API key to use them.
To execute a trade, the script performs three steps:
ABI encoding. The ABI (Application Binary Interface) describes a contract's functions. The library uses it to convert trade parameters into bytecode that the blockchain can understand. The script calculates fees, the swap route, and slippage limits itself, as this only requires math.
Signing. The script signs the transaction with the wallet's private key.
Sending through an RPC node. The signed transaction is sent to an RPC node, the intermediary between the script and the network. The node forwards it to the mempool, the queue of unconfirmed transactions from which validators retrieve it.
Advantages
Speed. Execution time depends on the connection to the RPC node and block creation time. There's no need to load images, CSS animations, or website scripts.
Lower resource usage. The script doesn't need a browser engine, so you can run hundreds of parallel bots (workers) on a single low-cost VPS.
Independence from the interface. Exchange developers can redesign the website, change classes, and move buttons around. The bot won't notice: smart contract addresses are independent of the front end. You'll only need to change the code if the protocol moves to a new version of its contracts.
Potential drawbacks
Security. The bot needs a private key to sign transactions. The server running the bot must be strictly isolated to prevent the key from leaking.
Dependence on RPC. Public and low-cost RPC endpoints limit request rates on free plans, which can reduce speed. The bottleneck becomes the node, not the script. Arbitrage requires your own node or a dedicated paid endpoint.
MEV bots. Fast transaction submission doesn't protect you from them: MEV bots can see any transaction in the public mempool. Private RPC endpoints, such as Flashbots Protect, reduce the risk by sending transactions to block builders without going through the public mempool.
Approach #2: Puppeteer and Playwright—simulating user actions in a browser
The visual approach uses software to simulate user actions. Puppeteer or Playwright launches a browser, usually in headless mode, navigates to the exchange's website, and waits for the page to load. The bot then finds the necessary fields in the page's code, enters values, and clicks buttons, including confirmation buttons in pop-up windows from wallets such as MetaMask.
This type of bot is slower and requires more RAM. However, it works when direct contract requests are complicated or hidden by the platform's developers. After using ethers.js and viem, running a full browser on a server may seem like a step backward, but an exchange's front end often provides data that can't be obtained directly from the blockchain.
Less obvious advantages of the visual approach
Final amount including fees. Smart contracts work with raw values. An exchange's interface, especially an aggregator's, displays the final amount, taking website fees, gas fees, and the route into account. Puppeteer reads this figure from the page and gets the same data as the user.
Private APIs. If the transaction-generation logic is obfuscated or hidden behind private endpoints, figuring it out takes time. Puppeteer takes a straightforward approach: it clicks a button on the page, and the website generates the route and calldata itself.
Disadvantages of the visual approach
Dependence on page structure. The bot doesn't identify a button by its appearance; it finds it using a selector in the page's code. If the exchange renames the button's CSS class, the script won't find the button to click and will stop with an error. Trading will have to be paused while the code is fixed.
Memory leaks. Headless browsers use a lot of memory. When Chromium instances run 24/7, they accumulate junk and gradually consume all available RAM. The server may freeze at the worst possible moment, such as during a sharp market move.
Key stored on the server. To confirm trades in MetaMask, the wallet containing the private key or seed phrase must also be stored on the server. The isolation requirements are the same as for the protocol-level approach.
How DEX websites detect bots and what to consider
Even flawless code can run into security systems. Exchanges restrict bots because they put a load on servers and can be used to manipulate the market. So the question isn't whether a DEX website has protection, but which system it uses: Cloudflare Turnstile, HUMAN (formerly PerimeterX), DataDome, or something else. The difference between the two approaches is especially clear at this stage.
Protocol-level approach
Ethers.js and viem don't visit the exchange's website. The script communicates with an RPC provider, which is a blockchain node. From the perspective of the DEX website's security systems, this bot doesn't exist: it doesn't request pages or load their scripts.
Low-cost server proxies are suitable here: the blockchain doesn't care about the IP address as long as the transaction is properly signed. There are no website anti-bot systems along this path, but the RPC provider has its own restrictions—request limits and IP blocks.
Visual approach
Puppeteer and similar solutions interact with the exchange's front end, so they are subject to security checks. Server proxies can be counterproductive here: Cloudflare and other anti-bot systems are wary of data center IP addresses. The result can be endless CAPTCHAs or blocked access.
To make a bot look like an ordinary user, you need three components:
Residential or mobile proxies. They make the script look like a user rather than a server in a data center.
Automation masking. Puppeteer reveals by default that a script is controlling the browser, for example through the
navigator.webdriverproperty. Without an anti-detect browser, stealth plugins are used to hide these indicators.A unique digital fingerprint. Security systems check many browser parameters: how it renders fonts, which graphics card it reports, and how it processes audio. If all bots have the same fingerprint, they can be linked as one network and blocked.
An anti-detect browser such as Octo Browser provides a unique fingerprint for each bot. In Octo, each profile is an isolated environment with its own fingerprint, cookies, and proxy. The profile is launched through Octo's local API, which returns the CDP endpoint of the running browser. Puppeteer or Playwright connects to it just as it would to a regular Chrome browser. This way, each bot runs in its own profile, making it harder for security systems to link them by their fingerprints. Stealth plugins aren't needed in this setup.
If you need scalability and low costs, ethers.js or viem are good options: they don't need to pass website security checks. The visual approach requires a budget for proxies and fingerprint management solutions.
Summary of architectural differences
Feature | ethers.js/viem | Puppeteer/Playwright |
Entry point | RPC node (blockchain) | Platform's web server (DOM) |
Transaction submission time | Milliseconds; confirmation depends on block time | Seconds; depends on rendering |
Dependence on the interface | None; interacts with the contract | Critical; relies on selectors |
Website protection (WAF) | Doesn't interact with the DEX website, but is subject to RPC limits | Requires residential IPs, automation masking, and a unique fingerprint |
Implementation complexity | High: contracts must be analyzed | Lower initially, higher to maintain |
Resource usage | Minimal | High (CPU and RAM) |
Hybrid approach
For complex tasks, responsibilities can be divided among system components. If a browser takes so long to load the interface, why use it together with ethers.js or viem?
The idea behind the hybrid approach is to remove Puppeteer from the critical path of trade execution and use it only to collect data. The browser scouts, while the cryptographic module pulls the trigger.
Here's what this can look like in practice:
Reconnaissance module (Puppeteer or Playwright). The browser is used only to parse dynamically changing parameters.
Data transfer. Data extracted from the interface is passed to an isolated Node.js service.
Execution module (ethers.js or viem). The service builds the transaction, signs it locally, and sends it to the network's mempool through a fast RPC channel.
As a result, the system spends a couple of seconds calculating the route in the browser but gets accurate data from the obfuscated front end. It also saves several more seconds by avoiding transaction confirmation through the wallet interface.
This setup has one limitation: front-end calldata is usually tied to the connected wallet address and the quote's expiration time. Therefore, the browser module must use the same address as the execution module, and the data must be used immediately after it's received.
Conclusion
The choice of solution depends on where the transaction is generated. If you can build the calldata yourself or obtain it through an aggregator's official API, ethers.js or viem will provide speed and scalability. If a private front end generates the route and signatures, you need a browser—Puppeteer or Playwright with proxies and unique fingerprints.
A hybrid approach works well for complex aggregators: the browser collects the data, and the library signs and sends the transaction. Knowing when to use a browser for reconnaissance and when to interact directly with a smart contract is what distinguishes a resilient system from an unstable script.
Stay up to date with the latest Octo Browser news
By clicking the button you agree to our Privacy Policy.
Stay up to date with the latest Octo Browser news
By clicking the button you agree to our Privacy Policy.
Stay up to date with the latest Octo Browser news
By clicking the button you agree to our Privacy Policy.

Join Octo Browser now
Or contact Customer Service at any time with any questions you might have.

Join Octo Browser now
Or contact Customer Service at any time with any questions you might have.
Join Octo Browser now
Or contact Customer Service at any time with any questions you might have.
