Excellent presentation, everything is told in an accessible and understandable way. The tutorial was useful to me for using the bot. Thank you very much.
I am glad to find your channel, so grateful for the free code which helps me a lot with my solidity skills, please update more content like this. Thanks again.
Yeah so many people have run it now too, it might be harder to find profitable trades. Definitely won't make a fortune but a good introduction to arbitrage and systems trading I hope.
Awesome james nice concise explanation of the code and what it does in the scheme of things no fluff -perfect in its simplicity and showing more than some who leave you stranded with how and where to get hash numbers and where to put them in a tidy orderly manner. Thanks
Hello James and thank you for this great job 🙏 it was a good complete example to enter the solidity world, I'm testing the bot on a watch mode (without triggering trades) and I just want to share with you some points: to solve the gas problem I've recalculated the correct routes as I will test it on usdt only, to do this I've created a new script that builds all possible routes then test each one by applying the function estimateDualDexTrade if it doesn't catch an error I parse the good route in temp file then copy the result to configuration. I will try to init a score property on each route and always select the first one, if the route gives an arbitrage opportunity I'll increase the score by 1 else I'll decrease it by 1 then sort the routes by the score property, when you've talked about scaling I think It's hard to say as you have tested the result on different conditions.
Sounds like a good idea to score different routes and check more profitable routes more frequently. To scale it I think you would probably want to run your own node and monitor the mempool for incoming trades
Had the same issue and took me a good while to fix it. It was pretty simple for me. Cant read address of undefined means your [owner] isn't hooked up properly. For me I had stupidly changed the .env file name manually and accidentally left .txt on the end meaning the hardhat config file couldn't find the correct file. I removed that .txt and hey presto, I'm onto my next bug ha! Hope this helps
@@charlie.scot. and @James Bachini Hey guys, I've come across this same issue, and I've saved my file correctly as .env But I'm still getting the same error message when I try to run the deploy.js script Do you have any other suggestions with regards to getting the [owner] hooked up properly as you say in your message above? Would appreciate some guidance in getting over this obstacle, thank you!
I tried the code in remix, I always use estimate dual trade function to estimate the profit before I will execute the trade and it works, but if I put a higher amount I will be getting “no arbitrage available" error message, if I use small amount it will work, what could be the course?
Such a nice video, can I change the network to other evm like bsc, arbitrum or base, inside the config file and deploy it... 2. Does the bot determine direction in the two dex, if the price is lower than the other one it will determine which dex it will buy first?
Thanks, the bot is performing trades using mostly the funds inside the base assets, not the tokens; it will perform trades between those assets, right? The more base assets, the more trades it can perform
@@Johnson-d8n depends on the network. If you were doing something on eth mainnet you'd probably want to use the flashbots fast rpc URL. Having said that it wouldn't be anywhere near competitive on eth mainnet
Honestly this video has been extremely helpful and I love the way you have kept it interactive. However I have a question; pls with the current transaction fees on aurora and and other expenses. Do you still think this code will be profitable. That is excluding the competition? I need to know it really does help. Thanks
You can just set a minimum profit variable to cover the transaction fee. In practice though a lot of people have forked this code so probably any network other than Aurora would be a better place to run it
Thank you very much for the great content, please how can I change the dex? I should change the router address of the preferred dex I want right? Or is there any additional steps
If it's based on uni v2 then yes just change the contract address. If it's something else then it might have a different swap function so you'll need to dig into their docs to see how it works programmatically
Thanks for your response, like how much would be the minimum for trade, because the bot has been watching for opportunity yet it did want to execute trade, I also changed tokens and dexes, it didn't work, any advice on this?
@@rolandonwa2369hard to say without much info to go on. You should be able to do tiny $0.01 trades. There is no minimum as such. Maybe try adjusting the profit requirement setting. Also if it's running on a chain or dex with low trading volume it won't find many trades as prices aren't moving much
Thanks for this great tutorial; I learned a lot. It felt great to see "# weth: 52bps" pop up on the log for the 1st time. In the video you mentioned that the dualDexTrade function isn't very gas efficient; would you explain why it's not, or how I could make it more gas efficient?
It was written for a network with zero gas fees at the time. In production you would likely want to monitor the mempool and trade against incoming transactions
What are the benefits of doing route search and dual Dex swap from the arb contract address compare to doing it directly from your personal contract address?
It's pretty old now and was only minimally profitable when aurora first launched in the middle of a bull market. The code has been forked hundreds of times since then so I'd assume it's pretty saturated. You might find a few dollar trades but it certainly won't make you rich overnight. Beware of any code that promises you will get rich quick
Flash loans would create more slippage and fees so less profits. Not enough trading volume and liquidity on Aurora to make it viable. You are capped by how much capital you can push through without moving price any way so flash loans would only add more capital and fees which wouldn't work.
I don't think it would be profitable for this use case as the fees for the loan would eat into profits and there wasn't much liquidity to scale it anyway. Flash loan > more volume > more slippage > lower margins > plus flashloan fees Some example code here if you still want to give it a try www.quicknode.com/guides/defi/how-to-make-a-flash-loan-using-aave
i try the aurora one but got gas estimation fail, so tridexes need to amend your code I assume? also how will this work with some other dexes fork like balancer or solidly? thanks
Gas estimation error just means the tx is failing so check your config file and router/token addresses. Other dexes you will need to change the functions you are calling for swaps because they all work slightly differently
@@cheesebeef890114 sure here is a video about Uniswap v3 flashloans with links to tutorial and code in the description ua-cam.com/video/rte5Rk-XQ24/v-deo.html
@@thedivinepatrick follow the users, if there are degens clicking buttons there will be opportunity for arbitrage. More users and trading volume the bigger the opportunity to find trades
Hello, first thank's for this great tutorial, i would like to add another blockchain but i don't see how to get the "routes" can you help me for this part ?
Think there some info in the blog post linked in the description. It was a while ago but seem to remember brute forcing the routes using different combos of token addresses
Thanks for this helpful tutorial, My question is what if we put some large amount like $20k or $70k in base assets, it will be profitable or slippage will destroy the benefits?
slippage will destroy it because the pools aren't liquid enough. There's code on github to work out optimal sizing for each transaction I believe as it will vary.
Yes you will need to update some of the contract addresses and perhaps swap functions for any dexes which aren't based on Uniswap V2 but BSC is EVM so it's compatible
I'm not really into programming a lot, I only know few things here and there. Can you please explain how to execute the code you provided? Like what language, program, or system you used?
If I want to do stuff like this and get into MEV bots, should I learn JS before Solidity? I know Python and I know some C, C++, so I'm thinking I'd be better off not being lazy and learning JS before Solidity...
You could actually just use python and solidity or even python and vyper. Use python for the controller script and then solidity or vyper for the contract. JavaScript is useful to learn anyway as it's used a lot in testing (hardhat) and for connecting up web3 frameworks. But it's not essential for this type of thing. Bit of a wishy washy answer. Maybe start with CryptoZombies to get a feel for how it all works together and see where you end up and what bits interest you.
@@JamesBachini Ok, thanks for the advice! I'll start with Crypto Zombies since it always looked interesting anyways, just didn't know whether it had value or not as a hobby programmer.
Go through the list of ethereum dexes on DeFillama, anything based on Uni v2 should work. Can normally Google "nameOfDex router etherscan" and it'll come up with the address and source code which you can check to see if the function names for swaps are the same
Pls james i need your help. I have tried to deploy the contract using the deploy script in the repo and i have put my private key in dotenv but then it keeps showing me this; * Invalid account: #0 for network: aurora - Expected string, received undefined * Invalid account: #0 for network: fantom - Expected string, received undefined. PLS what could be the problem? Any help would be greatly appreciated😭
Sounds strange. What network are you trying to deploy it on? Maybe double check the .env file, did you put a alchemy API key in there? Also check hardhat.config.js and remove any networks you don't need. Add --network aurora or whatever chain you are deploying on using the key from hardhat.config.js
Learning to code unfortunately. I think it would be hard to make a living from arbitrage trading without knowing how to code up trading bots etc. If you want to work in DeFi then solidity is the programming language of choice, for quants its python and for everything else its Javascript. If you have no preference I'd recommend learning Javascript first because it's used everywhere
Hi James, first of all, thank you so much for the content. It helps a LOT for a newbie like me. I have a query here. Is there a benefit of doing all the "scans" of opportunity through smart contract ("estimateDualDexTrade") vs. interacting with the individual DEX's routers directly (calling router's getAmountsOut from Node JS)? Thanks again!! Looking forward to more of your contents!
There is in that you could potentially trade the same block and it would speed up execution and make it more competitive. On public RPC nodes you'll hit a lot of rate limits doing this so worth running your own version of geth.
@@JamesBachini I got this error when I try to call a function from the IERC20 interface for exemple : call to IERC20.totalSupply errored: Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" } The fact that I don't understand is, this error doesn't appear when I interact with the contract in the Aurora Blockchain (the only differences is the Blockchain where I deploy the contract) Can you tell me how to use it without non Uniswap clones ? (sorry it's a lot of questions)
@@akrfinance8379 you would need to change the function names that carry out the trades. Different dexes may use different functions and parameters so if you are dealing with something unusual you will need to customise the script for it
@@JamesBachini For me the rooter address it's the only parameter I have to change to trade on a different dexes (the addresses token too). Why do I have to change function names ? And what functions are you talking about ? I adapt of course the script but I keep the functions, I only adapt the addresses. Thank you
@@akrfinance8379 the code uses uniswap v2 and its various clones which all use the same functions/code to do swaps. If you are using Uni v3 or another dex which isn't a fork of Uniswap v2 then you'll need to adapt it to suit that code.
Fascinating content. Have you tried integrating the use of Flash Loans into these bots? I understand these are used quite often in these arbitrage transactions.
There's wasn't enough trading volume on Aurora to make it worth a flashloan. You'd be paying a fee on the loan and higher slippage on the dex so would cut into margins. On something like Eth mainnet where millions are traded daily there's a lot more room for volume but then it becomes more competitive too.
Great piece James, to begin with, I'm a newbie in programming, but I've been wondering 🤔 is it possible to create a crypto token that never falls by removing/burning sold supplies instantly from the total supply? And is it possible to create a token contract that would auto run an arbitrage contract on its own to generate yields. Will really appreciate a kind and complete answer please 😁!
It's not possible to create a token that never falls unfortunately. Safemoon did something similar to what you are talking about where transaction fees went to liquidity pools to boost price but it was still highly volatile. With regards to a token contract with an underlying arbitrage strategy in theory this would be possible but in practice it's difficult for it to be competitive. Not sure if the incentives are there too. I.e. if someone has a profitable arb strategy why would they want to share the profits with token holders rather than just running it themselves. I think we will see more tokens in the future that have yield farming type strategies backing up the collateral which makes more sense to me as execution is less time critical.
It's quite complex to calculate the optimal sizing. You would need to get the pool sizes at a given state and then figure out a formula to calculate slippage and how that affects profits. There's some more info about calculating slippage for v3 pools here: x3finance.medium.com/how-to-calculate-swap-slippage-of-uniswap-v3-d433ed6d74b0
InstaArb.sol was just an experiment to take much of the computation into a contract. Didn't work well but might have potential if you were running an internal node.
Hi ! Awesome video. I'm getting errors with the solidity compiler, don't exactly know how to change that. Then also, I'm trying to do the "cd Dex-Arbitrage", but it doesn't find the route to the folder. And last question, how can I use this code in a testnet ? Thank you in advance
Should be able to use it on a testnet but bare in mind there's not much trading volume so it won't find many trades. Check token and router addresses if you are getting errors
Thanks for the tutorial! quick question, what do you mean by "no transaction fee on Aurora"? I followed your tutorial and located some arb on the Aurora Dexes. But when I try to manual swap then, I got charged by a small fee ETH (enough to wipe out the arb profits)?
When I made the video there were no transaction or gas fees on Aurora. They later introduced them a month or so ago unfortunately. There's some info about it on their twitter account
There's a function in the trade.js file which just brute forces them using the token list and router addresses. I logged any that didn't pop an error to a JSON file and then used that. Think it's called data/goodRoutes.json in the repo. The logging line is commented out I believe in trade.js
@@JamesBachini Definitely agree, you can find positive trades but i havent been able to beat the transaction fee. I tried it on 5 dexes, pancake, cafe, bakery, cheese and ape. With the 100 tokens with the largest market caps.
Really helpful video, but im still a novice and i have a question that how can i set baseasset’s input amount for each trade ? Is this random or have any function for this ? Tks James
Trade size is just set as the contracts balance of that token but you could set it manually here: github.com/jamesbachini/DEX-Arbitrage/blob/a1f23b3e3fe6d64350befef98713af5efbd2ff3f/scripts/trade.js#L52
@@JamesBachini hey James, great video and thank you for sharing this code! Can you recommend any resources that would help us make this change to this code? I can see it's line 52 in the link you have shared above in this thread But I'm not sure how to code this yet, would appreciate if you can point me in the direction of where I can find that info to implement it myself Thank you
@@JamesBachini would you be willing to shed more light on what that means? If it's not too much of a bother. I'm pretty new to the web3 space so I'm not quite familiar with those terms yet.
@@olayinkaadebisi7907 same code will work on avalanche. However tokens will often have different addresses on each chain. Also different chains have different DeXs (decentralized exchanges)
The bot isn't going to be profitable or at least isn't going to make a significant amount of money. Set up a fresh test wallet to use and put the private key from that into the .env file
Not sure why always got Error: call revert exception (method="estimateDualDexTrade(address,address,address,address,uint256)", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0) when running trade.js is it realted to the version?
Thanks so much for the bot and video, so great to see the layout, I just have no real idea as to what’s going on exactly. How did you put together the list of all those different routes? Just taking a chance here but if you can pls can you make an in-depth video on this bot for the brand new coders like myself, would be excellent but thanks regardless great video
So the routes are just Token in > Dex > token out You can find dexes by looking on defillama. You can find router address for the Dex by doing a transaction and checking which contract you interacted with in a block explorer. And tokens can be found via the dexes analytics sites or by analysing transactions on the router
@@JamesBachini Hey thanks for the quick reply, I should've specified but the routes I was thinking about is the routes in the config files. At first I was confused as to how you made it to begin with, but reading the code now I see it first gets made under "const lookForDualTrade" and then info is appended to txt file in data folder. Now I'm trying to figure out from, for example ./data/fantomRouteLog.txt ... how does that info get copied to ./config/fantom.json .. how did you get the routes from the fantomRouteLog.txt to fantom.json file ... do you do it manually?
@@22-Zar yeah I think I just used vscode to add the formatting You can search for something like a newline and then hit alt enter and it'll highlight all and you can add the '],[' bits. I can't remember exactly but expect I did it something like that. A better alternative would just be to format it correctly in the script and use JSON.stringify before writing out to the file.
@@JamesBachini thanks James, I'm very new to coding but I've taken time to read the code as best I can and your video does explain it very well, so no real need for that "in-depth video" this is really great ... last question, if I want to use the BSC network can I just create a file like the aurora.json file in config folder, basically copy that but with BSC info and then run the controller to get the list of routes - then copy those routes to the config .json file again under "routes": [ ] and then run off that? Now I just want to figure out how can I use flash loans instead of my personal funds
@@22-Zar yes copy it but change the router addresses to the contract addresses for Pancakeswap and/or other bsc exchanges. The token addresses will be different too. Bscscan is the equivalent of etherscan and useful for this
I don't think so because of the scaling issue. Flash loans are great when you need a lot of capital but here it would just cause more slippage and you'd have to pay the loan fee. The liquidity pools that I was trading on just weren't big enough to justify it. On ethereum mainnet trading into large liquidity pools there might be a case for it but then you are looking at MEV and flashbots. Uni v2 forks generally have a flash swap feature/function at 0.3% which is interesting for certain situations and fun to play with.
Hello james, thanks for the indepth tutorial. However, i am stuck as I am trying to use the arb bot on different chains. Do I have to create the aurora.json file myself and create the routes manually or am I doing something wrong when executing the code. I was under the assumption that once I changed the tokenList.json and execute the code, the aurora.json file would get repopulated with the correct new tokens and routes. correct me if i am wrong. Esentially my question is how did you create the aurora.json file and the routes written below it.
No the router addresses for the Dex's and token contract addresses will all change between networks. You'll need to find out what they are for your specific chain and create a new file
@@JamesBachini I understand that the token addresses for a different chain will be different, as well as the router addresses. However, is there a script already in the repo that creates the routes from looking at tokenList.json or do I have to write it basically. That's my question. Thanks again for this tutorial
@@CommonVista100 you have to write it. There's a function to build out the routes by brute forcing the token/router combinations but you probably wouldn't want to use that on a chain with gas fees
@@JamesBachini I have managed to do all the changes as outlined and fund the contract with the base assets, however when i run the trade.js I am getting the following error : TypeError: Cannot read property 'balance' of undefined at lookForDualTrade (C:\Users\DELL\Documents\arb_bot\DEX-Arbitrage\scripts\trade.js:52:50) Some help would be appreciated
@@CommonVista100 sounds like an issue with one of the token contract addresses for the base assets. Try double checking them and your contract balance in a block explorer.
@@mattis46 the wallet that you use to sign transactions is stored in the .env file. You need some funds in here to pay gas fees. This is normally the native token for that blockchain. i.e. BnB for BSC, ETH for Ethereum, Aurora also introduced transaction fees since I made the video which are payable in Eth
@@JamesBachini Thanks for your reply. I do have ETH in the Metamask Wallet (Aurora Network), but I do get this error anyways. Shall I add the ETH to the base assets in aurora.json file?
Hi James, thank you for this wonderful tutorial. I have a question here: is it necessary to send some FTM to the fantom arbitrage contract (or ETH to the aurora arbitrage contract, since aurora now requires transaction fees)for gas fee? But I always failed to send FTM to the contract. Is it because the contract doesn't have a fallback() or receive() function?
No you only need the base asset that you are trading in the contract. You'll need some FTM in the wallet address in the .env file This fires off the transactions and pays the gas fee.
@@JamesBachini thanks for answering my question! I have another question: I put 500 wftm in the contract and run the trade script, but got "wftm: 0bps" all the time. Is it because 500wftm is too much that causing big slippage?
@@traceurlou2118 I wouldn't have thought so. Fantom is pretty competitive. I found every time I found a good trade the network RPC would go down for 30 seconds like someone ddos'ing it to take out competition. Probably need to run a private node to avoid that. You have the routes set up across a few dexes I assume? Maybe look at gas prices other bots are using to make sure you are competitive.
@@JamesBachini make sense. What is `minBasisPointsPerTrade` in the config file? You mentioned that in the video, but I still don't get it. Why aurora's minBasisPointsPerTrade is 0 while fantom is 50?
Hey. Great tutorial. I got this error on hardhat console: > arb = await IArb.attach(arbContract); Uncaught ReferenceError: arbContract is not defined at REPL10:1:48 I put the arbContract in the .env file. Pls help. Tks u.
Hi James, I found many arbitrage bots in some ecosystems. I am trying to find a way to get pair's information without a hardcode, like Uniswap Subgraph. Do u have any idea about this? thank you
You could pass the pair in via a contract function. Finding the pairs, you could maybe look at the contract events if you want to trade newly setup liquidity pools or something like that
Such a nice video, please can you give me a suggestion on what I will with this error message, after I changed the chains, also I have funds in those assets. It will load the assets and start displaying this error message Error: cannot estimate gas; transaction may fail or may require manual gas limit reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT' error: ProviderError: execution reverted Please any advice to handle this issue
@@JamesBachini thanks for your response, do you mean if I redeploy the contract it will resolve the issue? Because I recently deployed the contract on a polygon, also when I was using the aurora network it was not showing me the error message
@@williamj2063 some of the tokens and routers might have different addresses on different chains. So you'll need to update the config files accordingly with the correct token addresses and dexes you want to trade on
@@JamesBachini all the tokens are correct with the chains I'm using and dexs, I always make sure I'm in the chain inside dex screener then select the tokens based on that dex and chain
There's a link to a full tutorial in the video or if you search dex arbitrage it should come up. You basically need to find the router address of the Dex using a block explorer. Check the function name matches etc.
This is awesome thank you very much I am running it on ftm just to get a feel for how a bot run before i deploy my own but I am curious about how i can add more routes to the json because i added more dexes to the bot? I saw a reply you had saying that that function is in trade.js but is commented out but i am not seeing it. I would like to add it as a separate script that i can run and have write to the uniqueRoutes.json. Also i believe there is an error in the read me instruction because it says to run the bot you just use the deploy script again? I found that not to be the case also the slashes in the .\scripts\deploy.js were backwards for me because i am running on linux, I believe that could be good to specify in the readme
Hi Duncan, thanks for that I'll get the readme updated. To find the routes I just grabbed token addresses and tried every combination of them against popular base assets like usdt/usdc/ftm on every router. If there wasn't a pool for that combo then an error would be thrown and you can catch it and move on to the next. If there was a pool you wouldn't get an error and can write out thpse tokens and router addresses to a goodRoutes.json file
Hi James, I'm running the "deploy.js" script and I keep getting the error message: "TypeError: Cannot read property 'address' of undefined" I've read through all of the comments below to try to find the answer but I can't seem to get over this particular hurdle Can you make any reccomendations of where I should be looking, in which file and which lines I should be looking at? Thank you
@@JamesBachini hey James, I managed to resolve this issue :) I had not "cd"'d into the "DEX-Arbitrage" folder But when I did and made edits to those json files it all worked out I'm now able to deposit/withdraw and will begin testing with a real balance soon I do however now sometimes find this error: "replacement fee too low" and "replacement transaction underpriced" (even when there appears to be no pending transactions on either my wallet or contract on polygonscan..) I'm going to keep trying more tomorrow If you've encountered this "fee too low" error before and could recommend the right direction for me to explore to resolve it that would be very helpful Thank you!
@@eharrison it sounds like there's a transaction still in pending because of a low gas fee and the miners not picking it up. Then you are trying to overwrite it with another transaction with the same nonce (perhaps after restarting the programme) and that's too low too. Try upping the gas fee to a competitive amount and you should be good to go.
@@JamesBachini yeh I found a couple other sources/articles that said the same thing So I managed to pull the $1 ish of test WETH out of the contract by going to Remix and manually altering the Gas fee in metamask I'm wondering however, for using "fund.js" to add some base assets to run the Bot for a bit longer to more routes Do you know of any fixes, if the "fee too low" eeors show up again, even whilst there are no current transactions pending either by my wallet or the contract? That's where I'm struggling to understand where this particular "fee too low" error is coming from (when there doesn't appear to be an existing transaction to replace) Thank you for your responses bro, I appreciate it!
@@JamesBachini Also wondering if there is a way for me to alter the gas fees, for the script functions like "Fund.js" - "Recover.js" and "Trade.js" Is there anywhere in the code where we can make some changes to the gas fees, in case of running into these errors again in future?
Hey James, I don't understand how to find out Routes I have Assets and Dex Router Addresses but have not clue how to find these Routes Addresses Could you please give me a hint?
Yeah just brute force them so try every asset pair on every router. Any routes that don't exist will revert with an error. Log the ones that do exist to a file and use that to loop through in future.
@@equaliserTV just try to look for profitable swaps by looping through an array of token address for each Dex. Many will fail because there isnt a liquidity pool for that pair setup. To save wasting time and RPC bandwidth remove those and continue on with the ones where there are pools and you are finding trades
@@equaliserTV to be fair this is a bit hacky and probably not the most elegant way of doing it. But say you want to find all the routes for trading across Dex1 to Dex2 so you start with base assets i.e. Eth usdt usdc. Then you try to swap them for any token you can find on Dex1 then you try to swap back to the base asset on Dex2 and see if it's profitable. You can make it more complex and find various routes i.e. baseAsset to token1 to token2 to baseAsset. The more complex the route the more variations you have to test to see if token1 and token2 are trading on the dexes. So looping through the token addresses and router addresses and logging what works will give you a more condensed list of potentially profitable routes to query regularly.
Hi, James. I'm trying to adapt your contract for mainnet(uniswpv2, sushi), experimenting with golang instead of nodejs though. So the question is I'm stuck at `Fail with error 'TransferHelper: TRANSFER_FROM_FAILED'` no clue how to solve it, because I clearly see approve() call at the start of swap() function. Any suggestions would be highly appreciated. And thank you for the content of course.
It does sound like a token isn't approved or there isn't enough balance. Are you storing the tokens on the contract address? And approving them from the address where they are?
@@JamesBachini Sorry, but since you're quite involved in conversation I'd like to ask one more question.. What's the granularity of arbitrage contract/bot? I mean we only see new token prices after block update? Is it possible to go to sub block values?
@@Idontreallycareatall Yeah at the highest level people are modifying geth to monitor the mempool for incoming transactions and then executing arbs via flashbots to close any price discrepancies in the same block.
i'm very new to this so I was wondering I keep getting * Invalid account: #0 for network: aurora - Expected string, received undefined. Do you know what this means? Also is it an aurora wallet I need to connect or can I use me metamask as I want to use it with a test network?
You can use any address, it doesn't need to be your metamask wallet. There's a handy little too/repol in my GitHub called ethers-vanity-address which I use to make test wallets. Put the wallet credentials in a .env file and put some funds on there. Aurora you don't need anything to pay transaction fees but most other networks you do. Even testnets you need some free testnet play tokens from a faucet. You'll also need some of the base asset that you want to trade to send to the contract. There's a couple of scripts to help with this called scripts/fund.js and scripts/recover.js Check it all works with tiny amounts including recover.js so you can get any funds back out of the contract when finished.
Just to be clear and from what I understand, I need to transfer funds to a main wallet the baseAsset tokens (will just be using usdt) (does the wallet need to be on the aurora mainnet or will having funds in Binance Smart Chain be ok? if not how do I get funds into the aurora mainnet) and then deploy.js to get the contract key that goes into arbContract. Then, use fund.js to transfer funds from the wallet to arbcontract and then trade.js, then recover.js to get the funds back from the contract?
@@mitchhammy3612 the wallet needs to be on the same network you plan on running the bot. There was someone who left a comment about running it on Binance smart chain. I'd suggest setting up a separate wallet either in metamask or somewhere else and try it first with like less than $1 in USDT so you can make sure you can recover funds and everything works. You'll need to add the bsc network details to hardhat.config.js If you want to run it on Aurora you can bridge assets across from Binance smart chain to the aurora network using a tool like multichain or synapse
Hi James, I've been looking for some time for an arbitrage bot allowing me to invest in it even with low relative profitability despite everything... I'm not a developer and I'm therefore looking to rely on a basic bot with which I can be confident, do you think it could be wise for me to deploy this bot that you present to us in this video, without having to modify it given the fact that I would be truly unable to do so, I looking to earn a small passive income using cryptocurrency arbitrage. Thank you for your video, your advice and your kindness... thank you very much
Hi, no the bot is really provided as a learning tool rather than something that will make consistent and reliable profits. The truth is no one will publish or sell a MeV or arbitrage trading bot that makes consistent profits. Something like yield farming would be a better option in my opinion. Be really careful not to fall for scams with people selling trading bots.
@@JamesBachini Just trying to learn Solidity in general. I’m not coming from any type of coding background. I’m watching tutorials that say “if I watch this I’ll be a solidity coding master in 4 hours!” and after 3 days straight watching tutorials I’m left scratching my head lol. But I will keep trying.
@@dannyellis971 have you tried cryptozombies? That's a great tutorial/game to get up to speed. It's going to be a lot to take in if you've never coded before. If you hit a particular bug or problem don't forget you can normally Google an error code and figure it out from the stackoverflow post as someone will have been there before too.
I gave up after 2 days and just ended up paying a dev to code me one and to teach me how to deploy it all. It’s working great now and is very profitable
How did you get scammed? I don't think it can be from the bot in this video as the code is all open source and I wrote it myself. If you purchased a 3rd party bot then that was something else as all the code here is free and on GitHub. If someone promises you riches for $19.99/month it's probably a scam. Arbitrage is hard and you need to code your own solutions and tools to be competitive.
@@JamesBachini this video was presented as elementary with other info. I put some money into my wallet, and joined project through wallet's browser. Details on pm if you are interested.
This bot not a scam ...just make sure u have basic coding understanding to begin with. Don't use third party coded bot .instead use the original from GitHub repository and scale the bot urself.
Hi James, is there anywhere in the code we can alter the Gas price? I'm trying on Polygon and I keep coming across the error "fee too low" and "replacement transaction underpriced" I've played around with it a bit and managed to withdraw from the contract using remix/metamask and manually increasing the gas fees in MM But I often come across this "underpriced" error when trying to deposit into the contract (so I can't even test it with real $ atm lol!) Is it possible that this error will be less likely to happen when the networks gas fees come down (as they are significantly higher than usual as I'm typing this) Let me know if there is anywhere in the code that I can play withthe gas fee amount when you get a chance please Thank you again for providing this code for us to test/modify and learn from! Great learning experience making changes to this thing :)
Example of setting a manual gas price on line 80 github.com/jamesbachini/DEX-Arbitrage/blob/a1f23b3e3fe6d64350befef98713af5efbd2ff3f/scripts/trade.js#L80
@@eharrison is there any line number or reference for this error: "TypeError: Cannot read property 'balance' of undefined" it sounds like the contract isn't defined or it's trying to check the balance of something that hasn't been created in the code yet. That could be having knock on effects so I'd start with trying to find out what is going wrong here
@@JamesBachini it also says "at lookForDualTrade" Lines 59 and 75 Line 59 is: let tradeSize = balances[targetRoute.token1].balance; And then line 75 is: await lookForDualTrade(); I'm guessing that I need to make changes so that "balance" can be read properly I'm not quite sure what "Cannot read property 'balance' of undefined" means yet I'm not sure what is undefined, or how to define it lol!
@@JamesBachini When you say the contract isn't defined, is there an additional process I need to do to define the contract? Should I verify the on Polygonscan using the bytecode (which I've not done yet)?
So Uniswap v3 has some licensing issues to stop people copying it. All the clones like Pancakeswap, Trisolaris, Sushi etc. Are based in v2. It's possible to set this up with v3 as well you just need to change the function and parameters. Example code here for ve swaps github.com/JohnRSim/0xtr.ee-Contracts/blob/main/contracts/SwapExample.sol Contract addresses in the code are for the polygon Mumbai testnet
Is this a scam, cause people on twitter PM about this ? I'll watch the video, and watch more videos, etc. I hate scammers, so if anyone has any way to show me a government website, or something that helps me find answers to these concerns.
Don't buy trading systems from 3rd parties. If someone has something that makes money there is no reason to sell it. Write your own code, learn and continue to be sceptical
First of all, thank you for such an informative video. It’s really valuable for me. I deployed and tried the contract at Aurora. Then it worked exactly how you showed us here. After all I tried to deploy same contract to BSC testnet with particular changes like routes, tokens, swap addresses, dotenv, file names etc… I mean I just changed Auorora things with BSC testnet things. I successfully deployed it on BSC testnet and also mainnet too(with necessarry changes again). The issue I confronted is that when I started to trade.js, I’m getting an error code: ‘UNPREDICTABLE_GAS_LIMIT’ reason: cannot estimate gas: transaction may fail or may require manual gas limit. I have been reserching for complete 18 hours and I couldn’t solve the issue. And I’m really tired :( What could i miss? My wallets have necessary tokens. Routers and token addresses are all of them are correct. If you have a solution of it, could you please share? Thanks and sorry for long question.
I think in the code there's a commented out line to set the gas limit manually on the transaction. Check bscscan and see what other bots are paying in terms of gas and set it to that.
@@JamesBachini I tried to de-commrate but it obviously gives me syntax error, how should you insert it? Const TX = Await Arb.Connect (Owner) .Dualdextrade (Router1, Router2, Basetoken, Token2, Amount); {Gasprice: 1000000000003, Gaslimit: 500000};
1)Contrarily to what deploy.js tells you, DO NOT ADD a line for arbContract in .env (set it only in configuration>fantom.json or aurora.json) otherwise some scripts will crash! 2)Just use deploy.js > fund.js > trade.js > recover.js (I've ignored instadeploy.js and instatrade.js which may be redundant with deploy.js > fund.js > trade.js )
@@bertyguilbo8536 absolutely correct. The insta...js scripts were just experiments I left in for anyone interested. deploy.js > fund.js > trade.js > recover.js are the only ones needed
i finally deployed the contract using fantom. i configured it to include three routers and token addresses but when i run it, i get ; 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT', error: ProviderError: execution reverted
Awesome Tutorial James!. However I have a question. I used the bot as it is, on the Fantom network and as you said, results were not good. So I simply changed one of the router addresses to the router address of another Fantom dex. I also replaced the router dex address on the listed routes in fantom.json file. Here is where I have hit a roadblock. I get the following error "reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT'". I have manually put the gas limit in the hardhat.config file with no success, passed the gas price into the function in trade.js like so: const tx = await arb.connect(owner).dualDexTrade(router1, router2, baseToken, token2, amount, { gasPrice: 50000000000, gasLimit: 500000 }); yet same error. I have tinkered with this, using various gas prices well above what I see on the Fantom block explorer to no avail. But anytime I roll back changes and bring back the original script as you made it with spiritswap and spookyswap it works. Can you solve this with a simple example using another dex, maybe jetswap? Thanks in advance!
The gas price error message just means the transaction is expected to fail. It will likely be because of one of the router addresses is incorrect or not compatible with Uniswap be type DEX functions. Check the address is not all lowercase as that can cause a checksum error.
@@JamesBachini So I double checked, replaced the router addresses with the dual case contract address. I used SpiritSwap with router address : 0x16327E3FbDaCA3bcF7E38F5Af2599D2DDc33aE52 as against Wigoswap with contract address: 0x5023882f4D1EC10544FCB2066abE9C1645E95AA0 . Wigoswap has verified contract on ftmscan . Its still the same error.
@@JamesBachini Its is. Its stated as a uniswap fork on defilama. Anyway I tried it this time on Bsc between pancakeswap and bakeryswap with the same error. Surely bakeryswap is a uniswap v2 fork. maybe the full error log will be helpful. here it is: Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="call", transaction={"from":"0x5d78Eec03d7bBCcfF78bFf012CccfA423343B2fF","to":"0xDD9e3DEb5eD590fBb5E710731AA5D2e7d0f244b2","data":"0x068e7ca1000000000000000000000000cde540d7eafe93ac5fe6233bee57e1270d3e330f00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000001fa4a73a3f0133f0025378af00236f3abdee5d6300000000000000000000000000000000000000000000000000f8b0a10e470000","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.5.2) at Logger.makeError (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\logger\src.ts\index.ts:225:28) at Logger.throwError (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\logger\src.ts\index.ts:237:20) at checkError (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:80:16) at EthersProviderWrapper. (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:562:20) at step (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:48:23) at Object.throw (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:29:53) at rejected (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:21:65) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) { reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT', error: ProviderError: execution reverted at HttpProvider.request (C:\Users\myasu\DEX-Arbitrage ode_modules\hardhat\src\internal\core\providers\http.ts:49:19) at LocalAccountsProvider.request (C:\Users\myasu\DEX-Arbitrage ode_modules\hardhat\src\internal\core\providers\accounts.ts:187:34) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at EthersProviderWrapper.send (C:\Users\myasu\DEX-Arbitrage ode_modules\@nomiclabs\hardhat-ethers\src\internal\ethers-provider-wrapper.ts:13:20), method: 'call', transaction: { from: '0x5d78Eec03d7bBCcfF78bFf012CccfA423343B2fF', to: '0xDD9e3DEb5eD590fBb5E710731AA5D2e7d0f244b2', data: '0x068e7ca1000000000000000000000000cde540d7eafe93ac5fe6233bee57e1270d3e330f00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000001fa4a73a3f0133f0025378af00236f3abdee5d6300000000000000000000000000000000000000000000000000f8b0a10e470000', accessList: null } }
@@softassets7370 I think it's just showing that the transaction will fail. Not much else to go off. Likely an issue with a token or router address as that is all that's really changed
Hi i, thank you for sharing this, i tried it all of the router and token addresses are correct but i am getting a 'cannot estimate gas: transaction may fail or may require manual gas limit' code: unpredictable gas_limit. Tried to looked at the comments and included decommented it out and included at the end of the function (..gasPrice ,gasLimit) but i had yo change the syntax from gasLimit : 1000000001 to gasLimit =1000000 same with the gas price as i am getting a "unexpected token :" . Method: estimateGas
Hey double check the contract and router addresses including checksums. If you look at the GitHub closed issues there are 3-4 threads from people with similar problems. I think the error message is a bit misleading but it basically means the transaction will fail. The other thing is it won't work as standard with Uniswap v3 only v2 and the million v2 clones out there.
@@JamesBachini I figured out how to save and edit. I noticed there is a lot of WETH9 in the code. If i am using this on another EVM that doesnt have ETH/WETH for gas but instead another coin do I need to edit all those WETH9 to whatever the gas coin is on that network?
@@harrisonfang Uniswap always uses weth rather than the native Eth. So on Polygon for example they use wMatic rather than mastic. There is a list in the Uniswap docs I think of all the correct addresses
@@JamesBachini Right. My question is for my case I am trying to test this on the SMR evm network which uses SMR for gas fees. In my case would I need to edit your code and replace everything that says WETH9 with SMR?
Of all explanations for arb bots I've seen this is definitely the obvious winner for easiest to understand nice one
great content! one of the most underrated channels, please keep up the good work!
Thanks 👍
Excellent presentation, everything is told in an accessible and understandable way. The tutorial was useful to me for using the bot. Thank you very much.
I am glad to find your channel, so grateful for the free code which helps me a lot with my solidity skills, please update more content like this. Thanks again.
This video is so beautiful. Lots of knowledge and transparency from you… like the fact you pointed out that it’d not make so much profit
Yeah so many people have run it now too, it might be harder to find profitable trades. Definitely won't make a fortune but a good introduction to arbitrage and systems trading I hope.
yeah its a good entry point to start implementing more advances strategies
Thankyou, Thankyou, Thankyou. May God bless you my friend.
Awesome james nice concise explanation of the code and what it does in the scheme of things no fluff -perfect in its simplicity and showing more than some who leave you stranded with how and where to get hash numbers and where to put them in a tidy orderly manner. Thanks
Dear your code always work or not? thanks for all good video!
Nice. Good dex project can bring good profit
I am really happy that i found your channel , can you please do more script based videos that would be helpful to learn more about blockchain
im really sad i didnt find you channel earlier.
Hello James and thank you for this great job 🙏 it was a good complete example to enter the solidity world, I'm testing the bot on a watch mode (without triggering trades) and I just want to share with you some points: to solve the gas problem I've recalculated the correct routes as I will test it on usdt only, to do this I've created a new script that builds all possible routes then test each one by applying the function estimateDualDexTrade if it doesn't catch an error I parse the good route in temp file then copy the result to configuration. I will try to init a score property on each route and always select the first one, if the route gives an arbitrage opportunity I'll increase the score by 1 else I'll decrease it by 1 then sort the routes by the score property, when you've talked about scaling I think It's hard to say as you have tested the result on different conditions.
Sounds like a good idea to score different routes and check more profitable routes more frequently. To scale it I think you would probably want to run your own node and monitor the mempool for incoming trades
What language did you code it in?
@@Daniel-pc2ov the original contract was solidity with a NodeJS deployer/controller
deploying the contract on aurora didn't work for me, but it was fine on fantom
why is it bringing this error TypeError: Cannot read property 'address' of undefined
Maybe a field missing in the credentials or config files?
Had the same issue and took me a good while to fix it. It was pretty simple for me. Cant read address of undefined means your [owner] isn't hooked up properly. For me I had stupidly changed the .env file name manually and accidentally left .txt on the end meaning the hardhat config file couldn't find the correct file. I removed that .txt and hey presto, I'm onto my next bug ha! Hope this helps
@@charlie.scot. and @James Bachini Hey guys, I've come across this same issue, and I've saved my file correctly as .env
But I'm still getting the same error message when I try to run the deploy.js script
Do you have any other suggestions with regards to getting the [owner] hooked up properly as you say in your message above?
Would appreciate some guidance in getting over this obstacle, thank you!
Amazing video
Beautiful code
Thank you 🙏 so much
That's an amazing video, when will you make another video like this, that can work best for uniswap, pancakeswap, sushi swap. Etc
I'll try and get some more recorded, thank you
Thanks for your reply, we are waiting for it 🙏
I tried the code in remix, I always use estimate dual trade function to estimate the profit before I will execute the trade and it works, but if I put a higher amount I will be getting “no arbitrage available" error message, if I use small amount it will work, what could be the course?
@@homeskills2708 this is because there are no easy high profitability arbs found on that network currently
Hi James, could you talk about sandwich and front running and MEV, that's also interesting topics. thx.
I'll do a flashbots tutorial at some point 👍
@@JamesBachini wow, can't wait for that
@@JamesBachiniwe are still waiting for it sir
Such a nice video, can I change the network to other evm like bsc, arbitrum or base, inside the config file and deploy it...
2. Does the bot determine direction in the two dex, if the price is lower than the other one it will determine which dex it will buy first?
Yes you'll need to change the contract addresses too. You can code it to search for any routes between dexes
Thanks, the bot is performing trades using mostly the funds inside the base assets, not the tokens; it will perform trades between those assets, right? The more base assets, the more trades it can perform
@@Johnson-d8nYes it should perform base asset > token > base asset
@@JamesBachini alright, can they frontrun me by using this bot?
@@Johnson-d8n depends on the network. If you were doing something on eth mainnet you'd probably want to use the flashbots fast rpc URL. Having said that it wouldn't be anywhere near competitive on eth mainnet
Honestly this video has been extremely helpful and I love the way you have kept it interactive. However I have a question; pls with the current transaction fees on aurora and and other expenses. Do you still think this code will be profitable. That is excluding the competition? I need to know it really does help. Thanks
You can just set a minimum profit variable to cover the transaction fee. In practice though a lot of people have forked this code so probably any network other than Aurora would be a better place to run it
Thank you very much for the great content, please how can I change the dex? I should change the router address of the preferred dex I want right? Or is there any additional steps
If it's based on uni v2 then yes just change the contract address. If it's something else then it might have a different swap function so you'll need to dig into their docs to see how it works programmatically
Thanks for your response, like how much would be the minimum for trade, because the bot has been watching for opportunity yet it did want to execute trade, I also changed tokens and dexes, it didn't work, any advice on this?
@@rolandonwa2369hard to say without much info to go on. You should be able to do tiny $0.01 trades. There is no minimum as such. Maybe try adjusting the profit requirement setting. Also if it's running on a chain or dex with low trading volume it won't find many trades as prices aren't moving much
Thanks for this great tutorial; I learned a lot. It felt great to see "# weth: 52bps" pop up on the log for the 1st time.
In the video you mentioned that the dualDexTrade function isn't very gas efficient;
would you explain why it's not, or how I could make it more gas efficient?
It was written for a network with zero gas fees at the time. In production you would likely want to monitor the mempool and trade against incoming transactions
What are the benefits of doing route search and dual Dex swap from the arb contract address compare to doing it directly from your personal contract address?
You can have logic on the contract to revert the transaction if it loses money
@@JamesBachini That's a huge benefit indeed. I thought it was something like the beauty of the code or skill show off ;-)
牛逼克拉斯,niubility in chinese meas amazing, I gave this word to you ,YYDS(永远的神) another chinese word means "forever god",I also give it to you .RESPECT
Great content men, new subscriber
good channel keep updating~
Is it possible to profit from this bot with a small amount?
It's pretty old now and was only minimally profitable when aurora first launched in the middle of a bull market. The code has been forked hundreds of times since then so I'd assume it's pretty saturated. You might find a few dollar trades but it certainly won't make you rich overnight. Beware of any code that promises you will get rich quick
@@JamesBachini I can't get it to run, I'm getting an error message on cloning, what libraries do I need to install and configure before starting
@@BinanceMashal NodeJS and the dependencies in package.json
In your opinion, could you combine this with flash loans and would that make more profit or be riskier?
Flash loans would create more slippage and fees so less profits. Not enough trading volume and liquidity on Aurora to make it viable. You are capped by how much capital you can push through without moving price any way so flash loans would only add more capital and fees which wouldn't work.
@@JamesBachiniThanks. Maybe another chain. Trying to figure out if it's worth the time to go down the rabbit hole. 😬
this is good, thank you!
can we have a version with flashloan that would be perfect for people who need a capital ?
I don't think it would be profitable for this use case as the fees for the loan would eat into profits and there wasn't much liquidity to scale it anyway.
Flash loan > more volume > more slippage > lower margins > plus flashloan fees
Some example code here if you still want to give it a try
www.quicknode.com/guides/defi/how-to-make-a-flash-loan-using-aave
i try the aurora one but got gas estimation fail, so tridexes need to amend your code I assume? also how will this work with some other dexes fork like balancer or solidly? thanks
Gas estimation error just means the tx is failing so check your config file and router/token addresses. Other dexes you will need to change the functions you are calling for swaps because they all work slightly differently
@@JamesBachini thanks James! wonder you could make a video about Uniswap flash swap
@@cheesebeef890114 sure here is a video about Uniswap v3 flashloans with links to tutorial and code in the description ua-cam.com/video/rte5Rk-XQ24/v-deo.html
Pls James, what are the chances of successful trades say i configure the code for pentagular trade?
I think trading volumes on Aurora are quite low so you might be better looking at other chains
@@JamesBachini how about fantom?
@@thedivinepatrick follow the users, if there are degens clicking buttons there will be opportunity for arbitrage. More users and trading volume the bigger the opportunity to find trades
Hello, first thank's for this great tutorial, i would like to add another blockchain but i don't see how to get the "routes" can you help me for this part ?
Think there some info in the blog post linked in the description. It was a while ago but seem to remember brute forcing the routes using different combos of token addresses
Thanks for this helpful tutorial, My question is what if we put some large amount like $20k or $70k in base assets, it will be profitable or slippage will destroy the benefits?
slippage will destroy it because the pools aren't liquid enough. There's code on github to work out optimal sizing for each transaction I believe as it will vary.
@@JamesBachini do you have that address for github?
@@shapourh6516 I don't sorry. It was a while ago I was looking at it.
Is it feasible to deploy this on BSC?
Yes you will need to update some of the contract addresses and perhaps swap functions for any dexes which aren't based on Uniswap V2 but BSC is EVM so it's compatible
I'm not really into programming a lot, I only know few things here and there. Can you please explain how to execute the code you provided? Like what language, program, or system you used?
It's a solidity smart contract executed via nodejs which runs JavaScript
how it can be profitable if others networks spent a gas?
Trade profits need to outweigh gas costs. At time of making the video there were no gas costs on Aurora so this wasn't a challenge
If I want to do stuff like this and get into MEV bots, should I learn JS before Solidity? I know Python and I know some C, C++, so I'm thinking I'd be better off not being lazy and learning JS before Solidity...
You could actually just use python and solidity or even python and vyper. Use python for the controller script and then solidity or vyper for the contract.
JavaScript is useful to learn anyway as it's used a lot in testing (hardhat) and for connecting up web3 frameworks. But it's not essential for this type of thing.
Bit of a wishy washy answer. Maybe start with CryptoZombies to get a feel for how it all works together and see where you end up and what bits interest you.
@@JamesBachini Ok, thanks for the advice! I'll start with Crypto Zombies since it always looked interesting anyways, just didn't know whether it had value or not as a hobby programmer.
Hi, except for uniswap and sushiswap how to get a list of router addresses ( compatible with this code ) on the ethereum mainet ? Many thanks.
Go through the list of ethereum dexes on DeFillama, anything based on Uni v2 should work. Can normally Google "nameOfDex router etherscan" and it'll come up with the address and source code which you can check to see if the function names for swaps are the same
Is it still possible to make money on dex arbitrage with such competition?
Yes but this code is very over simplified and won't compete on mainnet where it becomes more of an MEV game
Pls james i need your help. I have tried to deploy the contract using the deploy script in the repo and i have put my private key in dotenv but then it keeps showing me this;
* Invalid account: #0 for network: aurora - Expected string, received undefined
* Invalid account: #0 for network: fantom - Expected string, received undefined.
PLS what could be the problem? Any help would be greatly appreciated😭
Sounds strange. What network are you trying to deploy it on? Maybe double check the .env file, did you put a alchemy API key in there?
Also check hardhat.config.js and remove any networks you don't need. Add --network aurora or whatever chain you are deploying on using the key from hardhat.config.js
ok i know nothing about coding or having a controller, where should i start?
Learning to code unfortunately. I think it would be hard to make a living from arbitrage trading without knowing how to code up trading bots etc.
If you want to work in DeFi then solidity is the programming language of choice, for quants its python and for everything else its Javascript. If you have no preference I'd recommend learning Javascript first because it's used everywhere
I know nothing about coding either so I just paid a dev to code me one and to help me set it up. It’s working great
@@JamesBachini Thank you very much for your responce. Is solidity primarily used for Ethereum Blockchain?
@@CenterinChrist ethereum and EVM blockchains such as polygon, BnB chain, avalanche, layer 2s like Arbitrum/optimism etc.
@@JamesBachini right on, thats where ill be then, whats better, python or solidity?
Hi James, first of all, thank you so much for the content. It helps a LOT for a newbie like me. I have a query here.
Is there a benefit of doing all the "scans" of opportunity through smart contract ("estimateDualDexTrade") vs. interacting with the individual DEX's routers directly (calling router's getAmountsOut from Node JS)?
Thanks again!! Looking forward to more of your contents!
There is in that you could potentially trade the same block and it would speed up execution and make it more competitive. On public RPC nodes you'll hit a lot of rate limits doing this so worth running your own version of geth.
Thank you for answering my question, James. That made a lot of sense!
Wow great content
Thanks for sharing! This exactly what I needed - an example to get started and play around with. Looking forward to tinkering :)
Good luck with the arbs 👍
James pls how do I deploy this code to a cloud? Pls
Just setup a cloud instance ssh in and run it from there
@@JamesBachini thanks allot James...pls I have not done this before.
How do I go about the ssh instance? Pls
how do you build the trading route?
Find the token contract addresses. In the code there's a bit to brute force the routes once you have addresses for the tokens and routers
Why I can't use this code for Arbitrum ? Even if I adapt the INFURA ENDPOINT and the addresses of tokens and rooters
Should work. Its an old video that uses univ2. If you want to use it with non Uniswap clones then you'll need to adapt it a bit
@@JamesBachini I got this error when I try to call a function from the IERC20 interface for exemple :
call to IERC20.totalSupply errored: Internal JSON-RPC error.
{
"code": -32000,
"message": "execution reverted"
}
The fact that I don't understand is, this error doesn't appear when I interact with the contract in the Aurora Blockchain (the only differences is the Blockchain where I deploy the contract)
Can you tell me how to use it without non Uniswap clones ? (sorry it's a lot of questions)
@@akrfinance8379 you would need to change the function names that carry out the trades. Different dexes may use different functions and parameters so if you are dealing with something unusual you will need to customise the script for it
@@JamesBachini For me the rooter address it's the only parameter I have to change to trade on a different dexes (the addresses token too). Why do I have to change function names ? And what functions are you talking about ?
I adapt of course the script but I keep the functions, I only adapt the addresses.
Thank you
@@akrfinance8379 the code uses uniswap v2 and its various clones which all use the same functions/code to do swaps. If you are using Uni v3 or another dex which isn't a fork of Uniswap v2 then you'll need to adapt it to suit that code.
Fascinating content. Have you tried integrating the use of Flash Loans into these bots? I understand these are used quite often in these arbitrage transactions.
There's wasn't enough trading volume on Aurora to make it worth a flashloan. You'd be paying a fee on the loan and higher slippage on the dex so would cut into margins.
On something like Eth mainnet where millions are traded daily there's a lot more room for volume but then it becomes more competitive too.
Great piece James, to begin with, I'm a newbie in programming, but I've been wondering 🤔 is it possible to create a crypto token that never falls by removing/burning sold supplies instantly from the total supply?
And is it possible to create a token contract that would auto run an arbitrage contract on its own to generate yields.
Will really appreciate a kind and complete answer please 😁!
It's not possible to create a token that never falls unfortunately. Safemoon did something similar to what you are talking about where transaction fees went to liquidity pools to boost price but it was still highly volatile.
With regards to a token contract with an underlying arbitrage strategy in theory this would be possible but in practice it's difficult for it to be competitive. Not sure if the incentives are there too. I.e. if someone has a profitable arb strategy why would they want to share the profits with token holders rather than just running it themselves.
I think we will see more tokens in the future that have yield farming type strategies backing up the collateral which makes more sense to me as execution is less time critical.
How do I set the gas limit? I do get this error: "cannot estimate gas; transaction may fail or may require manual gas limit"
That error normally just means the transaction will fail. Likely due to an incorrect router or token address
Hi James, when you find one router has profit,how to calculation the _amount parameter that get max profit. thx.
It's quite complex to calculate the optimal sizing. You would need to get the pool sizes at a given state and then figure out a formula to calculate slippage and how that affects profits.
There's some more info about calculating slippage for v3 pools here:
x3finance.medium.com/how-to-calculate-swap-slippage-of-uniswap-v3-d433ed6d74b0
Hello, awesome video! Whats the difference between Arb.sol and InstaArb.sol?
InstaArb.sol was just an experiment to take much of the computation into a contract. Didn't work well but might have potential if you were running an internal node.
Hi ! Awesome video.
I'm getting errors with the solidity compiler, don't exactly know how to change that. Then also, I'm trying to do the "cd Dex-Arbitrage", but it doesn't find the route to the folder. And last question, how can I use this code in a testnet ?
Thank you in advance
Should be able to use it on a testnet but bare in mind there's not much trading volume so it won't find many trades. Check token and router addresses if you are getting errors
Thanks for the tutorial! quick question, what do you mean by "no transaction fee on Aurora"? I followed your tutorial and located some arb on the Aurora Dexes. But when I try to manual swap then, I got charged by a small fee ETH (enough to wipe out the arb profits)?
When I made the video there were no transaction or gas fees on Aurora. They later introduced them a month or so ago unfortunately. There's some info about it on their twitter account
@@JamesBachini i see, thank you!
Loved this one! How did you generate the routes section in the config?
There's a function in the trade.js file which just brute forces them using the token list and router addresses. I logged any that didn't pop an error to a JSON file and then used that. Think it's called data/goodRoutes.json in the repo. The logging line is commented out I believe in trade.js
@@JamesBachini Thanks a lot James! The code works great. Currently running it on BSC.
@@stellanskoog bsc is pretty competitive on Pancakeswap and some of the established forks but hope it's getting a few trades in for you 👍
@@JamesBachini Definitely agree, you can find positive trades but i havent been able to beat the transaction fee. I tried it on 5 dexes, pancake, cafe, bakery, cheese and ape. With the 100 tokens with the largest market caps.
Really helpful video, but im still a novice and i have a question that how can i set baseasset’s input amount for each trade ? Is this random or have any function for this ? Tks James
Trade size is just set as the contracts balance of that token but you could set it manually here:
github.com/jamesbachini/DEX-Arbitrage/blob/a1f23b3e3fe6d64350befef98713af5efbd2ff3f/scripts/trade.js#L52
@@JamesBachini is there any function that help optimal trade size to avoid losses because of slippage or low liquidity pool ?
@@duyhoatran2076 not in this code although it would be better to calculate a tradesize based on the liquidity available
@@JamesBachini yeah, thank u so much James
@@JamesBachini hey James, great video and thank you for sharing this code!
Can you recommend any resources that would help us make this change to this code?
I can see it's line 52 in the link you have shared above in this thread
But I'm not sure how to code this yet, would appreciate if you can point me in the direction of where I can find that info to implement it myself
Thank you
Hello, can this code be modeled to work with a chain like avalanche?
Yes avalanche c chain is EVM compatible so the code is exactly the same. Just need to change the token and router addresses
@@JamesBachini would you be willing to shed more light on what that means? If it's not too much of a bother. I'm pretty new to the web3 space so I'm not quite familiar with those terms yet.
@@olayinkaadebisi7907 same code will work on avalanche. However tokens will often have different addresses on each chain. Also different chains have different DeXs (decentralized exchanges)
very very cool
used the fund.js script to load wFTM to the contract but it does not load FTM. Does the contract need FTM for gas to be able to work?
The contract doesn't, the account in the .env file needs some FTM to pay gas fees because that is where the transactions will be executed from
hello its a newbie, can anyone tell which private key i'm to supply to the in the .env file and is the bot still profitable thanks
The bot isn't going to be profitable or at least isn't going to make a significant amount of money. Set up a fresh test wallet to use and put the private key from that into the .env file
Not sure why always got Error: call revert exception (method="estimateDualDexTrade(address,address,address,address,uint256)", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0) when running trade.js is it realted to the version?
Could be a token contract address or router issue maybe? I've never heard of the abi version causing an issue.
Thanks so much for the bot and video, so great to see the layout, I just have no real idea as to what’s going on exactly. How did you put together the list of all those different routes?
Just taking a chance here but if you can pls can you make an in-depth video on this bot for the brand new coders like myself, would be excellent but thanks regardless great video
So the routes are just
Token in > Dex > token out
You can find dexes by looking on defillama. You can find router address for the Dex by doing a transaction and checking which contract you interacted with in a block explorer. And tokens can be found via the dexes analytics sites or by analysing transactions on the router
@@JamesBachini Hey thanks for the quick reply, I should've specified but the routes I was thinking about is the routes in the config files. At first I was confused as to how you made it to begin with, but reading the code now I see it first gets made under "const lookForDualTrade" and then info is appended to txt file in data folder. Now I'm trying to figure out from, for example ./data/fantomRouteLog.txt ... how does that info get copied to ./config/fantom.json .. how did you get the routes from the fantomRouteLog.txt to fantom.json file ... do you do it manually?
@@22-Zar yeah I think I just used vscode to add the formatting
You can search for something like a newline
and then hit alt enter and it'll highlight all and you can add the '],[' bits.
I can't remember exactly but expect I did it something like that.
A better alternative would just be to format it correctly in the script and use JSON.stringify before writing out to the file.
@@JamesBachini thanks James, I'm very new to coding but I've taken time to read the code as best I can and your video does explain it very well, so no real need for that "in-depth video" this is really great ... last question, if I want to use the BSC network can I just create a file like the aurora.json file in config folder, basically copy that but with BSC info and then run the controller to get the list of routes - then copy those routes to the config .json file again under "routes": [ ] and then run off that?
Now I just want to figure out how can I use flash loans instead of my personal funds
@@22-Zar yes copy it but change the router addresses to the contract addresses for Pancakeswap and/or other bsc exchanges. The token addresses will be different too. Bscscan is the equivalent of etherscan and useful for this
wouldn't it be better if flashLoans tech is applied in the smart contract?
I don't think so because of the scaling issue. Flash loans are great when you need a lot of capital but here it would just cause more slippage and you'd have to pay the loan fee.
The liquidity pools that I was trading on just weren't big enough to justify it.
On ethereum mainnet trading into large liquidity pools there might be a case for it but then you are looking at MEV and flashbots.
Uni v2 forks generally have a flash swap feature/function at 0.3% which is interesting for certain situations and fun to play with.
Hello james, thanks for the indepth tutorial. However, i am stuck as I am trying to use the arb bot on different chains. Do I have to create the aurora.json file myself and create the routes manually or am I doing something wrong when executing the code. I was under the assumption that once I changed the tokenList.json and execute the code, the aurora.json file would get
repopulated with the correct new tokens and routes. correct me if i am wrong.
Esentially my question is how did you create the aurora.json file and the routes written below it.
No the router addresses for the Dex's and token contract addresses will all change between networks. You'll need to find out what they are for your specific chain and create a new file
@@JamesBachini I understand that the token addresses for a different chain will be different, as well as the router addresses. However, is there a script already in the repo that creates the routes from looking at tokenList.json or do I have to write it basically. That's my question. Thanks again for this tutorial
@@CommonVista100 you have to write it. There's a function to build out the routes by brute forcing the token/router combinations but you probably wouldn't want to use that on a chain with gas fees
@@JamesBachini I have managed to do all the changes as outlined and fund the contract with the base assets, however when i run the trade.js I am getting the following error :
TypeError: Cannot read property 'balance' of undefined
at lookForDualTrade (C:\Users\DELL\Documents\arb_bot\DEX-Arbitrage\scripts\trade.js:52:50)
Some help would be appreciated
@@CommonVista100 sounds like an issue with one of the token contract addresses for the base assets. Try double checking them and your contract balance in a block explorer.
Do you know any reason for this TypeError: Cannot read properties of undefined (reading 'balance') ?
Do you have funds in the .env wallet to pay gas fees and have you moved the baseAssets to the contract?
@@JamesBachini You are so kind, it seems that I made a small mistake, I will test it again, thanks for the reply.😊
@@JamesBachini wht do you mean with: "Do you have funds in the .env wallet to pay gas fees"?
@@mattis46 the wallet that you use to sign transactions is stored in the .env file. You need some funds in here to pay gas fees. This is normally the native token for that blockchain. i.e. BnB for BSC, ETH for Ethereum, Aurora also introduced transaction fees since I made the video which are payable in Eth
@@JamesBachini Thanks for your reply. I do have ETH in the Metamask Wallet (Aurora Network), but I do get this error anyways. Shall I add the ETH to the base assets in aurora.json file?
Hi James, thank you for this wonderful tutorial. I have a question here: is it necessary to send some FTM to the fantom arbitrage contract (or ETH to the aurora arbitrage contract, since aurora now requires transaction fees)for gas fee? But I always failed to send FTM to the contract. Is it because the contract doesn't have a fallback() or receive() function?
No you only need the base asset that you are trading in the contract. You'll need some FTM in the wallet address in the .env file
This fires off the transactions and pays the gas fee.
@@JamesBachini thanks for answering my question! I have another question: I put 500 wftm in the contract and run the trade script, but got "wftm: 0bps" all the time. Is it because 500wftm is too much that causing big slippage?
@@traceurlou2118 I wouldn't have thought so. Fantom is pretty competitive. I found every time I found a good trade the network RPC would go down for 30 seconds like someone ddos'ing it to take out competition. Probably need to run a private node to avoid that. You have the routes set up across a few dexes I assume? Maybe look at gas prices other bots are using to make sure you are competitive.
@@JamesBachini make sense. What is `minBasisPointsPerTrade` in the config file? You mentioned that in the video, but I still don't get it. Why aurora's minBasisPointsPerTrade is 0 while fantom is 50?
Aurora did not have fee (=0) but not anymore
Hi James, i want to create a controller in python, do u have any source code or github link ? Thank u
I coded it in NodeJS but no reason you couldn't use python with an equivalent web3 library. There won't be anything premade unfortunately
Can i do this with flashloan
In theory yes but fees and slippage on larger orders will erode margins
@@JamesBachini Oh I See It Now Thanks
Hey. Great tutorial. I got this error on hardhat console:
> arb = await IArb.attach(arbContract);
Uncaught ReferenceError: arbContract is not defined
at REPL10:1:48
I put the arbContract in the .env file.
Pls help. Tks u.
Did you update the config/whatever.json file?
Hi James, I found many arbitrage bots in some ecosystems. I am trying to find a way to get pair's information without a hardcode, like Uniswap Subgraph. Do u have any idea about this? thank you
You could pass the pair in via a contract function. Finding the pairs, you could maybe look at the contract events if you want to trade newly setup liquidity pools or something like that
Such a nice video, please can you give me a suggestion on what I will with this error message, after I changed the chains, also I have funds in those assets. It will load the assets and start displaying this error message
Error: cannot estimate gas; transaction may fail or may require manual gas limit
reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT'
error: ProviderError: execution reverted
Please any advice to handle this issue
The error just means the tx is failing. Perhaps contract addresses need changing?
@@JamesBachini thanks for your response, do you mean if I redeploy the contract it will resolve the issue? Because I recently deployed the contract on a polygon, also when I was using the aurora network it was not showing me the error message
@@williamj2063 some of the tokens and routers might have different addresses on different chains. So you'll need to update the config files accordingly with the correct token addresses and dexes you want to trade on
@@JamesBachini all the tokens are correct with the chains I'm using and dexs, I always make sure I'm in the chain inside dex screener then select the tokens based on that dex and chain
@@JamesBachini I was thinking that the tokens only works for erc20 only with 18 decimals right?
hello sir. i am new to solidity coding. how to add new DEX to this contract ??? if any reference video, plez share the link. thanks !!!
There's a link to a full tutorial in the video or if you search dex arbitrage it should come up.
You basically need to find the router address of the Dex using a block explorer. Check the function name matches etc.
This is awesome thank you very much I am running it on ftm just to get a feel for how a bot run before i deploy my own but I am curious about how i can add more routes to the json because i added more dexes to the bot? I saw a reply you had saying that that function is in trade.js but is commented out but i am not seeing it. I would like to add it as a separate script that i can run and have write to the uniqueRoutes.json.
Also i believe there is an error in the read me instruction because it says to run the bot you just use the deploy script again? I found that not to be the case also the slashes in the .\scripts\deploy.js were backwards for me because i am running on linux, I believe that could be good to specify in the readme
Hi Duncan, thanks for that I'll get the readme updated. To find the routes I just grabbed token addresses and tried every combination of them against popular base assets like usdt/usdc/ftm on every router. If there wasn't a pool for that combo then an error would be thrown and you can catch it and move on to the next. If there was a pool you wouldn't get an error and can write out thpse tokens and router addresses to a goodRoutes.json file
Hi James, I'm running the "deploy.js" script and I keep getting the error message:
"TypeError: Cannot read property 'address' of undefined"
I've read through all of the comments below to try to find the answer but I can't seem to get over this particular hurdle
Can you make any reccomendations of where I should be looking, in which file and which lines I should be looking at?
Thank you
Do you have an address in the .env file?
More details here jamesbachini.com/dex-arbitrage/
@@JamesBachini hey James, I managed to resolve this issue :)
I had not "cd"'d into the "DEX-Arbitrage" folder
But when I did and made edits to those json files it all worked out
I'm now able to deposit/withdraw and will begin testing with a real balance soon
I do however now sometimes find this error:
"replacement fee too low" and "replacement transaction underpriced" (even when there appears to be no pending transactions on either my wallet or contract on polygonscan..)
I'm going to keep trying more tomorrow
If you've encountered this "fee too low" error before and could recommend the right direction for me to explore to resolve it that would be very helpful
Thank you!
@@eharrison it sounds like there's a transaction still in pending because of a low gas fee and the miners not picking it up. Then you are trying to overwrite it with another transaction with the same nonce (perhaps after restarting the programme) and that's too low too. Try upping the gas fee to a competitive amount and you should be good to go.
@@JamesBachini yeh I found a couple other sources/articles that said the same thing
So I managed to pull the $1 ish of test WETH out of the contract by going to Remix and manually altering the Gas fee in metamask
I'm wondering however, for using "fund.js" to add some base assets to run the Bot for a bit longer to more routes
Do you know of any fixes, if the "fee too low" eeors show up again, even whilst there are no current transactions pending either by my wallet or the contract?
That's where I'm struggling to understand where this particular "fee too low" error is coming from (when there doesn't appear to be an existing transaction to replace)
Thank you for your responses bro, I appreciate it!
@@JamesBachini Also wondering if there is a way for me to alter the gas fees, for the script functions like "Fund.js" - "Recover.js" and "Trade.js"
Is there anywhere in the code where we can make some changes to the gas fees, in case of running into these errors again in future?
Hey James,
I don't understand how to find out Routes
I have Assets and Dex Router Addresses but have not clue how to find these Routes Addresses
Could you please give me a hint?
Yeah just brute force them so try every asset pair on every router. Any routes that don't exist will revert with an error. Log the ones that do exist to a file and use that to loop through in future.
@@JamesBachini you mean brute force with transactions?
@@equaliserTV just try to look for profitable swaps by looping through an array of token address for each Dex. Many will fail because there isnt a liquidity pool for that pair setup. To save wasting time and RPC bandwidth remove those and continue on with the ones where there are pools and you are finding trades
@@equaliserTV to be fair this is a bit hacky and probably not the most elegant way of doing it. But say you want to find all the routes for trading across Dex1 to Dex2 so you start with base assets i.e. Eth usdt usdc. Then you try to swap them for any token you can find on Dex1 then you try to swap back to the base asset on Dex2 and see if it's profitable. You can make it more complex and find various routes i.e. baseAsset to token1 to token2 to baseAsset. The more complex the route the more variations you have to test to see if token1 and token2 are trading on the dexes.
So looping through the token addresses and router addresses and logging what works will give you a more condensed list of potentially profitable routes to query regularly.
@@JamesBachini aight, get it thanks! 🙌
Have you considered taking courses at udemy?
Lol I could definitely do with taking a few courses and learning more to improve this hacky solidity code 🤣
Hi, James. I'm trying to adapt your contract for mainnet(uniswpv2, sushi), experimenting with golang instead of nodejs though.
So the question is I'm stuck at `Fail with error 'TransferHelper: TRANSFER_FROM_FAILED'` no clue how to solve it, because I clearly see approve() call at the start of swap() function.
Any suggestions would be highly appreciated. And thank you for the content of course.
It does sound like a token isn't approved or there isn't enough balance. Are you storing the tokens on the contract address? And approving them from the address where they are?
@@JamesBachini Sorry, but since you're quite involved in conversation I'd like to ask one more question.. What's the granularity of arbitrage contract/bot? I mean we only see new token prices after block update? Is it possible to go to sub block values?
@@Idontreallycareatall Yeah at the highest level people are modifying geth to monitor the mempool for incoming transactions and then executing arbs via flashbots to close any price discrepancies in the same block.
@@JamesBachini thank you so much (: have a nice weekend
thanks
Im conflicted, i like the tutorial, but the contracts are full of reentrency possibilities
The external functions are ownerOnly
Can you please make a tutorial for mev bot?? And please also teach how to modify it.
(I have seen alot of videos but all of these are scams.)
No one will release profitable code unfortunately 🤷🏼♂️
@@JamesBachini but any guidance about it?? Or if i send you a github code link can you please check it to find out if there's any hidden scam in it??
i'm very new to this so I was wondering I keep getting * Invalid account: #0 for network: aurora - Expected string, received undefined. Do you know what this means? Also is it an aurora wallet I need to connect or can I use me metamask as I want to use it with a test network?
Ok, I kinda figured it outever when I deposited to the arb address it shows no money when i run the script
So do I need to connect my metamask to the aurora network
You can use any address, it doesn't need to be your metamask wallet. There's a handy little too/repol in my GitHub called ethers-vanity-address which I use to make test wallets.
Put the wallet credentials in a .env file and put some funds on there. Aurora you don't need anything to pay transaction fees but most other networks you do. Even testnets you need some free testnet play tokens from a faucet. You'll also need some of the base asset that you want to trade to send to the contract. There's a couple of scripts to help with this called scripts/fund.js and scripts/recover.js
Check it all works with tiny amounts including recover.js so you can get any funds back out of the contract when finished.
Just to be clear and from what I understand, I need to transfer funds to a main wallet the baseAsset tokens (will just be using usdt) (does the wallet need to be on the aurora mainnet or will having funds in Binance Smart Chain be ok? if not how do I get funds into the aurora mainnet) and then deploy.js to get the contract key that goes into arbContract. Then, use fund.js to transfer funds from the wallet to arbcontract and then trade.js, then recover.js to get the funds back from the contract?
@@mitchhammy3612 the wallet needs to be on the same network you plan on running the bot. There was someone who left a comment about running it on Binance smart chain.
I'd suggest setting up a separate wallet either in metamask or somewhere else and try it first with like less than $1 in USDT so you can make sure you can recover funds and everything works. You'll need to add the bsc network details to hardhat.config.js
If you want to run it on Aurora you can bridge assets across from Binance smart chain to the aurora network using a tool like multichain or synapse
Hi James, I've been looking for some time for an arbitrage bot allowing me to invest in it even with low relative profitability despite everything... I'm not a developer and I'm therefore looking to rely on a basic bot with which I can be confident, do you think it could be wise for me to deploy this bot that you present to us in this video, without having to modify it given the fact that I would be truly unable to do so, I looking to earn a small passive income using cryptocurrency arbitrage. Thank you for your video, your advice and your kindness... thank you very much
Hi, no the bot is really provided as a learning tool rather than something that will make consistent and reliable profits. The truth is no one will publish or sell a MeV or arbitrage trading bot that makes consistent profits. Something like yield farming would be a better option in my opinion. Be really careful not to fall for scams with people selling trading bots.
@@JamesBachini ok thanks
Oof I'm a beginner and have spent 3 days straight trying to figure out how to make a Arbitrage bot and still struggling.
You running into any particular errors in the code or just general?
@@JamesBachini Just trying to learn Solidity in general. I’m not coming from any type of coding background. I’m watching tutorials that say “if I watch this I’ll be a solidity coding master in 4 hours!” and after 3 days straight watching tutorials I’m left scratching my head lol. But I will keep trying.
@@dannyellis971 have you tried cryptozombies? That's a great tutorial/game to get up to speed. It's going to be a lot to take in if you've never coded before. If you hit a particular bug or problem don't forget you can normally Google an error code and figure it out from the stackoverflow post as someone will have been there before too.
I gave up after 2 days and just ended up paying a dev to code me one and to teach me how to deploy it all. It’s working great now and is very profitable
I just got scammed on this bot. If you say to not use third party, what to use then instead?
How did you get scammed? I don't think it can be from the bot in this video as the code is all open source and I wrote it myself.
If you purchased a 3rd party bot then that was something else as all the code here is free and on GitHub.
If someone promises you riches for $19.99/month it's probably a scam. Arbitrage is hard and you need to code your own solutions and tools to be competitive.
@@JamesBachini this video was presented as elementary with other info. I put some money into my wallet, and joined project through wallet's browser. Details on pm if you are interested.
Why my last comment dissappeared?
@@chrisdrake7893 I can still see it and you replied to it with this comment
This bot not a scam ...just make sure u have basic coding understanding to begin with. Don't use third party coded bot .instead use the original from GitHub repository and scale the bot urself.
Hi James, is there anywhere in the code we can alter the Gas price?
I'm trying on Polygon and I keep coming across the error "fee too low" and "replacement transaction underpriced"
I've played around with it a bit and managed to withdraw from the contract using remix/metamask and manually increasing the gas fees in MM
But I often come across this "underpriced" error when trying to deposit into the contract (so I can't even test it with real $ atm lol!)
Is it possible that this error will be less likely to happen when the networks gas fees come down (as they are significantly higher than usual as I'm typing this)
Let me know if there is anywhere in the code that I can play withthe gas fee amount when you get a chance please
Thank you again for providing this code for us to test/modify and learn from!
Great learning experience making changes to this thing :)
Example of setting a manual gas price on line 80
github.com/jamesbachini/DEX-Arbitrage/blob/a1f23b3e3fe6d64350befef98713af5efbd2ff3f/scripts/trade.js#L80
@@eharrison is there any line number or reference for this error:
"TypeError: Cannot read property 'balance' of undefined"
it sounds like the contract isn't defined or it's trying to check the balance of something that hasn't been created in the code yet.
That could be having knock on effects so I'd start with trying to find out what is going wrong here
@@JamesBachini it also says
"at lookForDualTrade"
Lines 59 and 75
Line 59 is: let tradeSize = balances[targetRoute.token1].balance;
And then line 75 is: await lookForDualTrade();
I'm guessing that I need to make changes so that "balance" can be read properly
I'm not quite sure what "Cannot read property 'balance' of undefined" means yet
I'm not sure what is undefined, or how to define it lol!
@@JamesBachini There's also one greyed out line in the error message:
"at processTicksAndRejections (internal/process/task_queues.js:93:5)"
@@JamesBachini When you say the contract isn't defined, is there an additional process I need to do to define the contract?
Should I verify the on Polygonscan using the bytecode (which I've not done yet)?
Hi James
Hi
Het James great video! But I do have 1 question. Is it ok to use the v2 router when uniswap runs on version 3? Thanks
Also how do you not have more subs. EatTheBlock charges 150$ for this exact although outdated info.
So Uniswap v3 has some licensing issues to stop people copying it. All the clones like Pancakeswap, Trisolaris, Sushi etc. Are based in v2.
It's possible to set this up with v3 as well you just need to change the function and parameters.
Example code here for ve swaps
github.com/JohnRSim/0xtr.ee-Contracts/blob/main/contracts/SwapExample.sol
Contract addresses in the code are for the polygon Mumbai testnet
Did I not mention in the terms I charge at least one beer if you make money from it and we meet at a conference in the future 😉
@@JamesBachini wow okay thanks a lot!
@@davidkulman2291 RIGHT
James should really leave an 0x address, i'd send him some nice gratuity for this channel.
Is this a scam, cause people on twitter PM about this ? I'll watch the video, and watch more videos, etc. I hate scammers, so if anyone has any way to show me a government website, or something that helps me find answers to these concerns.
Don't buy trading systems from 3rd parties. If someone has something that makes money there is no reason to sell it. Write your own code, learn and continue to be sceptical
Cool
First of all, thank you for such an informative video. It’s really valuable for me. I deployed and tried the contract at Aurora. Then it worked exactly how you showed us here. After all I tried to deploy same contract to BSC testnet with particular changes like routes, tokens, swap addresses, dotenv, file names etc… I mean I just changed Auorora things with BSC testnet things. I successfully deployed it on BSC testnet and also mainnet too(with necessarry changes again). The issue I confronted is that when I started to trade.js, I’m getting an error code: ‘UNPREDICTABLE_GAS_LIMIT’ reason: cannot estimate gas: transaction may fail or may require manual gas limit. I have been reserching for complete 18 hours and I couldn’t solve the issue. And I’m really tired :( What could i miss? My wallets have necessary tokens. Routers and token addresses are all of them are correct. If you have a solution of it, could you please share? Thanks and sorry for long question.
I think in the code there's a commented out line to set the gas limit manually on the transaction. Check bscscan and see what other bots are paying in terms of gas and set it to that.
@@JamesBachini I tried to de-commrate but it obviously gives me syntax error, how should you insert it?
Const TX = Await Arb.Connect (Owner) .Dualdextrade (Router1, Router2, Basetoken, Token2, Amount);
{Gasprice: 1000000000003, Gaslimit: 500000};
@@4theen7even22 try putting the gas price object as the last variable passed through to the function
1)Contrarily to what deploy.js tells you, DO NOT ADD a line for arbContract in .env (set it only in configuration>fantom.json or aurora.json) otherwise some scripts will crash!
2)Just use deploy.js > fund.js > trade.js > recover.js (I've ignored instadeploy.js and instatrade.js which may be redundant with deploy.js > fund.js > trade.js )
@@bertyguilbo8536 absolutely correct. The insta...js scripts were just experiments I left in for anyone interested. deploy.js > fund.js > trade.js > recover.js are the only ones needed
ah... the times when UST was a stable coin (: ahhaha
so hard to understand esp the english pronunciation
i finally deployed the contract using fantom. i configured it to include three routers and token addresses but when i run it, i get ; 'cannot estimate gas; transaction may fail or may require manual gas limit',
code: 'UNPREDICTABLE_GAS_LIMIT',
error: ProviderError: execution reverted
It just means the transaction is failing. Check token contract and router addresses and make sure they are v2 forks
i have encountered this problem
reason: 'network does not support ENS',
code: 'UNSUPPORTED_OPERATION',
operation: 'ENS',
network: 'unknown'
There is an incorrect address somewhere or you are using quotes around an address so it thinks the address is an ens domain
@@JamesBachini Where can I check for the wrong address?
@@gregthomas7812 put it into a block explorer
@@JamesBachini thank you
Awesome Tutorial James!. However I have a question. I used the bot as it is, on the Fantom network and as you said, results were not good. So I simply changed one of the router addresses to the router address of another Fantom dex. I also replaced the router dex address on the listed routes in fantom.json file. Here is where I have hit a roadblock. I get the following error "reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT'". I have manually put the gas limit in the hardhat.config file with no success, passed the gas price into the function in trade.js like so: const tx = await arb.connect(owner).dualDexTrade(router1, router2, baseToken, token2, amount, { gasPrice: 50000000000, gasLimit: 500000 }); yet same error. I have tinkered with this, using various gas prices well above what I see on the Fantom block explorer to no avail. But anytime I roll back changes and bring back the original script as you made it with spiritswap and spookyswap it works. Can you solve this with a simple example using another dex, maybe jetswap? Thanks in advance!
The gas price error message just means the transaction is expected to fail. It will likely be because of one of the router addresses is incorrect or not compatible with Uniswap be type DEX functions. Check the address is not all lowercase as that can cause a checksum error.
@@JamesBachini So I double checked, replaced the router addresses with the dual case contract address. I used SpiritSwap with router address : 0x16327E3FbDaCA3bcF7E38F5Af2599D2DDc33aE52 as against Wigoswap with contract address: 0x5023882f4D1EC10544FCB2066abE9C1645E95AA0 . Wigoswap has verified contract on ftmscan . Its still the same error.
@@softassets7370 is wigoswap a uni v2 fork? I'm not familiar with it. If that's the only thing you changed it has to be where the problem is
@@JamesBachini Its is. Its stated as a uniswap fork on defilama. Anyway I tried it this time on Bsc between pancakeswap and bakeryswap with the same error. Surely bakeryswap is a uniswap v2 fork. maybe the full error log will be helpful. here it is:
Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="call", transaction={"from":"0x5d78Eec03d7bBCcfF78bFf012CccfA423343B2fF","to":"0xDD9e3DEb5eD590fBb5E710731AA5D2e7d0f244b2","data":"0x068e7ca1000000000000000000000000cde540d7eafe93ac5fe6233bee57e1270d3e330f00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000001fa4a73a3f0133f0025378af00236f3abdee5d6300000000000000000000000000000000000000000000000000f8b0a10e470000","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.5.2)
at Logger.makeError (C:\Users\myasu\DEX-Arbitrage
ode_modules\@ethersproject\logger\src.ts\index.ts:225:28)
at Logger.throwError (C:\Users\myasu\DEX-Arbitrage
ode_modules\@ethersproject\logger\src.ts\index.ts:237:20)
at checkError (C:\Users\myasu\DEX-Arbitrage
ode_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:80:16)
at EthersProviderWrapper. (C:\Users\myasu\DEX-Arbitrage
ode_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:562:20)
at step (C:\Users\myasu\DEX-Arbitrage
ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:48:23)
at Object.throw (C:\Users\myasu\DEX-Arbitrage
ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:29:53)
at rejected (C:\Users\myasu\DEX-Arbitrage
ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:21:65)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
reason: 'cannot estimate gas; transaction may fail or may require manual gas limit',
code: 'UNPREDICTABLE_GAS_LIMIT',
error: ProviderError: execution reverted
at HttpProvider.request (C:\Users\myasu\DEX-Arbitrage
ode_modules\hardhat\src\internal\core\providers\http.ts:49:19)
at LocalAccountsProvider.request (C:\Users\myasu\DEX-Arbitrage
ode_modules\hardhat\src\internal\core\providers\accounts.ts:187:34)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at EthersProviderWrapper.send (C:\Users\myasu\DEX-Arbitrage
ode_modules\@nomiclabs\hardhat-ethers\src\internal\ethers-provider-wrapper.ts:13:20),
method: 'call',
transaction: {
from: '0x5d78Eec03d7bBCcfF78bFf012CccfA423343B2fF',
to: '0xDD9e3DEb5eD590fBb5E710731AA5D2e7d0f244b2',
data: '0x068e7ca1000000000000000000000000cde540d7eafe93ac5fe6233bee57e1270d3e330f00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000001fa4a73a3f0133f0025378af00236f3abdee5d6300000000000000000000000000000000000000000000000000f8b0a10e470000',
accessList: null
}
}
@@softassets7370 I think it's just showing that the transaction will fail. Not much else to go off. Likely an issue with a token or router address as that is all that's really changed
Hi i, thank you for sharing this, i tried it all of the router and token addresses are correct but i am getting a 'cannot estimate gas: transaction may fail or may require manual gas limit' code: unpredictable gas_limit. Tried to looked at the comments and included decommented it out and included at the end of the function (..gasPrice ,gasLimit) but i had yo change the syntax from gasLimit : 1000000001 to gasLimit =1000000 same with the gas price as i am getting a "unexpected token :" .
Method: estimateGas
Hey double check the contract and router addresses including checksums. If you look at the GitHub closed issues there are 3-4 threads from people with similar problems. I think the error message is a bit misleading but it basically means the transaction will fail. The other thing is it won't work as standard with Uniswap v3 only v2 and the million v2 clones out there.
I have been trying to edit and save this file but for some reason my edits will not go through. How do I save changes??
Are you saving it locally? Should be able to save files fine unless there is some kind of write protection on your drive
@@JamesBachini Yes trying to save locally I will try again this weekend
@@JamesBachini I figured out how to save and edit. I noticed there is a lot of WETH9 in the code. If i am using this on another EVM that doesnt have ETH/WETH for gas but instead another coin do I need to edit all those WETH9 to whatever the gas coin is on that network?
@@harrisonfang Uniswap always uses weth rather than the native Eth. So on Polygon for example they use wMatic rather than mastic. There is a list in the Uniswap docs I think of all the correct addresses
@@JamesBachini Right. My question is for my case I am trying to test this on the SMR evm network which uses SMR for gas fees. In my case would I need to edit your code and replace everything that says WETH9 with SMR?