📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

The Trading Bot Masterclass V3 - January 16, 2024

Dapp University1:59:36

Transcription

All right, we are live for the master class. So, we've got some people jumping in the chat here. Uh, let me know in the chat if you can hear me okay, and let me know where you are calling in from tonight, so we can see, uh, you know, number one, confirmation you can hear me, but two, uh, just to get an idea of where everybody's coming in from around the world.

Awesome! We've got Pittsburgh, Montreal, Phoenix, New York, Dallas, Texas, Ottawa, Houston, Michigan, Guam, Auckland, Williamsburg, Medina, Stuart, Florida, Columbia, Maryland, Fort Lauderdale, Austin, Sydney, Charlotte, UK, Gladstone, Oregon, Budapest, Miami, Chicago, Albania. Awesome, awesome!

All right, everybody, we'll go ahead and get started here. Let me just pull up my outline. We'll get rocking and rolling. All right, buddy, so welcome to the Trading Bot Master Class. So, I'm super excited to show you how to create a blockchain-based trading bot tonight. You know, uh, there's a lot in store for crypto in 2025, and so I'm super excited to show you how this works.

So, let's talk about what we're going to cover tonight, just in brief, okay? We're going to talk about what you need to know to create a blockchain-based Arbitrage crypto trading bot, uh, both the concepts that you have to understand, and also we're going to look at the coding implementation for the bot in this presentation today.

So, just a couple of quick house rules before we get started. Um, the live chat for tonight is going to be in the YouTube chat. So, if you're in the Slack channel, uh, somewhere else, uh, make sure we put chats in the YouTube chat that's going to be monitoring. Uh, I am not going to be able to answer a lot of questions while I'm presenting. I'll occasionally monitor the chat, but let's save most of the questions for the end. We'll have a time of Q&A after our presentation tonight.

Um, now, we will be, uh, showing a good amount of code in this presentation today, but what I would say is, don't try to code along live with everything that I'm doing. Um, what I would do is try to get a big picture of what's happening live tonight, and then get the replay link later, uh, however you joined, and go through it a second time. That's when you should do the implementation, okay?

Now, um, also, you know, this is, uh, there's going to be quite a bit of code behind this trading bot, and unfortunately, we don't have the time to build it from scratch in our presentation today. But I'm going to show you how to set it up, how to run it, and, uh, you know, give away the code and explain everything, um, without coding it step by step. But, you know, if you want to build your own trading bots, you know, modify them, create your own strategies, then definitely having, you know, blockchain development skills and professional-level blockchain development skills is going to give you a massive edge in this. And the absolute best way to get those hands-on, uh, skills is with hands-on mentorship, okay?

And I do have a couple of slots open for my blockchain developer mentorship. Uh, I'll put a link to this application down below. You just do a quick one-minute application, let us know kind of where you're coming from so we can see how to serve you best, and we can turn you into a blockchain developer, okay? So you can create your own trading bot, you know, break into the industry, land a job, whatever it is. We've got lots of people from the blockchain mentorship, probably on the session tonight. I think they just got the join link, so they'll be hanging out in the chat. I'm sure they will attest to that as well. So, link to that application is down in the description below if you want to become a blockchain developer as fast as possible.

So, um, last little piece of housekeeping is, um, I'm going to show you to set up a crypto trading bot tonight. Obviously, I can't make any types of promises legally in terms of financial return. Uh, this is for educational purposes only. I'm holding this class by popular request about how to create a crypto trading bot, um, and all that type of stuff. So, uh, with all that being said, I think you'll get a ton of value out of this class. It's going to go behind the curtain and really see how this stuff works. It's really awesome. It's a super powerful blockchain developer tool, and I'm very excited to show it to you.

So, um, let's talk about first some basics. All right, let's talk about this crypto trading bot, uh, what it does and what it does not do. All right, so number one is, let's talk about what it does not do. So, a lot of people think trading bots are a scam because, you know, nobody can actually predict the future about what cryptocurrency prices are going to do. And, you know, these bots have a major problem, right? So, if you're trying to create a bot that tries to, you know, track price movements on cryptocurrency, you know, you need money to trade with these bots, and they might work for a while, but, you know, you also might blow up and lose all your money. All right?

So, what should you do instead, or what could you do instead? All right? Well, that's not how that, that's not how this trading bot works. What does it do? Well, it's a blockchain-based trading bot, all right? It's an Arbitrage bot. So, what are the benefits of that? Well, it doesn't try to predict the future. All right? It actually seizes opportunities that exist in the marketplace right now with Arbitrage. Uh, it doesn't require any money of your trade, of your own money to trade. Just a quick caveat, of course, you have to pay some gas fees. And it also cannot lose money because it's blockchain-based. Of course, caveat, you know, you can lose money on gas fees, um, attempting trades, right?

So, what are the basic features of it? Well, again, it's an Arbitrage bot. So, it looks for opportunities real-time, um, not, doesn't try to predict the future. It uses smart contracts and it uses flash loans. So, we'll talk about that in a minute, but basically, you don't need any money to trade. And because these are on the blockchain, they also cannot lose money, okay?

So, uh, what are we going to cover tonight? Well, we're going to cover the concepts, everything you need to know how to create your own bot, a comprehensive overview of how it works. And then we're also going to look at the implementation, basically the actual coding, the setup, the demonstration, and how to customize it to create your own strategies. And then finally, uh, which blockchain are we going to be focusing on specifically tonight? Well, we're going to be demonstrating the bot on the Arbitrum Layer 2 network for Ethereum. So, you can do this on Ethereum, but the gas fees are kind of high, makes the Arbitrage a little bit harder. But on a lower-cost chain, Layer 2 like Arbitrum, the fees are much lower, okay? And you can also apply this strategy to many other blockchains which are EVM compatible. I'll explain more about that in a minute, okay?

So, finally, just to understand how we're going to do this bot tonight, you know, the whole purpose of this class is to show you how to create a cryptocurrency trading bot, uh, with blockchain, with smart contracts, with flash loans, and basically showing you how to be a blockchain developer this way. So, there's a couple of different ways that I can do this, all right? I've done this class a few different ways in the past. Uh, I've done it before where I actually, you know, create a, create a bot, uh, and give it away, all right, where I'm actually doing the trade live, uh, with a complete strategy set into the bot, okay? But there's a problem with that, okay? When I did it in the past, basically, I give it away, and then everybody's using the exact same strategy, and they're competing with one another, and it makes it harder to essentially, um, you know, be profitable because everybody's doing the exact same thing.

So, because there's really two options: you can be better than everybody else, faster than everybody else, more sophisticated than everybody else, uh, or you can just create your own strategies and look for other opportunities. And that's what we're going to focus on in this class, okay? Basically, I'm going to give you a bot that works, is capable of doing Arbitrages, um, but I'm going to show you how to use it as a platform to basically customize it and create your own strategies, look for other opportunities that other people aren't doing, um, so that you don't have to compete with everybody else doing the exact same thing. It's more like I'm going to teach you how to fish with this rather than just give you a fish, because if I give you a fish, everybody's going to be fighting over the same scraps and bones off the same one.

So, what you're going to get, you're going to get a finished bot solution. Um, I'll show you how to customize it. Uh, we're going to create like a simulation environment where you can see this happen in real time. And, um, yeah, that's how we're going to do it. Basically, we're going to set this up in kind of a sandbox environment. Think about like a flight simulator, okay? Um, if I was going to teach you how to fly an airplane, the absolute worst way to do that was say, "Hey, come on, let's jump in the cockpit. Why don't you just go ahead and take the steering wheel and try to take off?" Right? Like, we're both probably going to die if that happens. So, you don't want to do that with a trading bot either.

So, what you want to do is basically this: in a simulated environment where everything works, um, you know, like it should on the main net, and then you can sort of play around with that, customize it, create your own strategies, and do all your development work there before you actually attempt this on the main net. That's what I'm going to show you how to do tonight. I'll explain that more when we get there, okay?

So, um, let's start off with some basic concepts that you have to understand in order to make this work. So, first and foremost, what is Arbitrage? Well, basically, it's buying cryptocurrency on one exchange and selling it on another exchange for a profit, okay? So, how does this happen? Well, cryptocurrencies, um, get their prices from the marketplace, and each individual exchange basically sets the price that the cryptocurrency is worth on that particular exchange, okay? Now, if you look at lots of cryptocurrency exchanges, you'll notice they have minor price discrepancies between each exchange, all right? And every single time somebody trades, usually those discrepancies, you know, start to, uh, become more apparent, okay? And so, uh, whenever those fall out of sync, basically, that's when an Arbitrage opportunity happens.

So, let's say, for example, you could buy a token on one exchange for a dollar, you could sell on another exchange for $2. Well, let's not do that. $100 on one exchange, buy for that price, sell on the exchange for $101. That'd be a $1 profit, okay? Now, it doesn't sound great, but what if you could do that with a lot of cryptocurrency? That could add up really quickly. Or what if you could do it over and over and over and over and over again? That could definitely add up as well.

Now, you can do Arbitrage on regular cryptocurrency exchanges like Coinbase, Binance, Kraken, etc., etc. But the problem with that is that the price can move on you, all right? So, if you buy on Coinbase and you transfer your funds over to Kraken, by the time that transfer takes place, the Arbitrage is probably gone, okay? But what you can do with blockchain is all of the exchanges are on the blockchain, and so you can do Arbitrages in real time between two exchanges without having to have any hang time in between transferring funds. Everything happens instantly because all the apps are on the same network, okay? So, basically, that's what creates the opportunity to do Arbitrage on blockchain where the price can't move on you and you can't actually lose money on that trade. It's pretty cool.

The next topic to discuss is flash loans. So, what is a flash loan? Um, a flash loan, uh, is basically a technique where you can borrow millions of dollars of cryptocurrency for free, uh, with zero money down, as long as you pay it back in the same transaction, okay? So, how on Earth can you get a zero money down loan for free? Well, because with blockchain, there's no way that you can lose the money that you're borrowing, all right? Let me explain how, because with a flash loan, you're doing this with a complex transaction, all right?

So, blockchains support simple transactions and complex transactions. So, a simple transaction would be like, "Hey, if I'm going to send cryptocurrency from my account to yours, let's say one Ether." That's a simple transaction that just has one instruction in it: take cryptocurrency out of my account and put it in your account, okay? Now, you can do complex transactions that have multiple steps, like step one: you borrow some money, step two: do something with that money, step three: pay it back, and step four: keep the profit, okay? So, how do you do these multi-step transactions? Well, that's what smart contracts are for. So, if you have something like a MetaMask wallet or a Phantom wallet, you can't just do complex transactions all in one go, all right? You actually have to create, uh, smart contracts as a developer and code out each line of a function to represent those complex transactions. So, like, you'd have a smart contract as a function that does all these steps, and this would, like, represent step one would be its own line of code, step two would be its own line of code, step three would be its own line of code, and also step four would be its own line of code.

So, um, there's lots of different things you can do with flash loans. Arbitrage is a very common application, that's what we're going to use today. Um, the cool thing about this is whenever you're borrowing the money, a lot of people freak out and they're like, "Hey, what if I borrowed a million dollars on the blockchain and lost it?" Okay? Well, you can't do that, all right? It's, it's mathematically impossible, uh, on the blockchain, because when you're taking out a flash loan, it has a special safeguard in it that says, "Hey, if you don't pay the money back, we're not even going to complete this transaction, okay?" So, everything is all contained in a single transaction. So, if you borrow the money and accidentally lose it or something like that, or don't pay it back, it's just not even going to take place in the first place. Like, the blockchain just won't even process that transaction.

So, a couple of caveats about the flash loans: number one, just because you can borrow a million dollars doesn't mean you have to. You can borrow smaller amounts of money. Um, you know, I say "for free," obviously there's a gas fee involved, anytime you do anything on the blockchain. Some flash loan providers charge a small fee, but, um, we're going to work with a flash loan provider tonight that charges zero fees, which is nice. See that in a minute. And yeah, awesome.

Okay, the next thing that we want to talk about are ERC20 tokens, okay? So, basically, what cryptocurrencies can you Arbitrage? Well, we're going to Arbitrage any cryptocurrency that is ERC20 compliant, okay? So, what does that mean? Well, basically, uh, if you see any cryptocurrency token out there that is not a native gas token of a blockchain network, and it's on an Ethereum network like Ethereum, Binance Smart Chain, um, you know, Avalanche, or any Ethereum Layer 2 like, uh, Arbitrum, Optimism, etc., etc., uh, it is probably an ERC20 token. So, basically, these are tokens that are powered by smart contracts that live on top of another blockchain, okay? Um, so, if you think about cryptocurrency, like Bitcoin is not an ERC20 token, it's a gas token, basically, on the Bitcoin blockchain. I know Bitcoin doesn't have gas, but that's the idea. Ethereum, or Ether, is like the native cryptocurrency, the Ethereum blockchain is the gas token. Um, you know, SOL is the gas token on Solana, right? So, these aren't ERC20 tokens, those are like native tokens. Now, you might see wrapped versions of those, which are tokens, so like Wrapped Ether, or Wrapped SOL, or Wrapped Bitcoin. You can Arbitrage those, but you can't Arbitrage the native tokens because we're going to use ERC20 tokens for this.

So, what is ERC20? Well, again, these tokens are powered by smart contracts, um, and ERC20 is just a standard that specifies how these smart contracts should work. So, um, basically, it just specifies, like, what functions the smart contract must have, like name, symbol, decimal, total supply, balance of, transfer, transfer from, um, and then, like, what arguments those functions take, um, what the visibility is, and then also a couple of events that the contract must have. So, basically, it's just a standard that specifies how these tokens should work so that they're compatible with, like, every cryptocurrency wallet, every decentralized exchange, etc., etc. All right? So, that's, that's what ERC20 tokens are. And if you want to see, uh, a list of tokens, you can check out, like, Etherscan Token Tracker. All right, here's some tokens you can get on Dex Screener and look at EVM chains. We'll look at that later.

Uh, last little thing, because people ask me this a lot, is can you do cross-chain Arbitrage? Technically, you can, but that's not what we're going to focus on in this class, okay? The bot's not going to be cross-chain. There's no really good way to make airtight cross-chain Arbitrages that settle, uh, in real time, that you can't lose money on. So, basically, um, all the Arbitrages that you're going to do need to be on the exact same blockchain. So, if you're going to do it on something like Arbitrum, which is what we're going to show you tonight, like all the tokens have to be on the Arbitrum network, all the exchanges have to be on the Arbitrum network. If you're going to do it on Ethereum, same thing. Uh, you could do it on multiple different blockchains even at the same time, but you can't move between blockchains when you're doing the Arbitrages.

And I saw a question come up in the chat: "Can we use a blockchain instead of Ethereum? It has huge gas fees." Yes, we're going to use Arbitrum, which has very, very low gas fees, okay? Talking like cents or even sub-cents, okay? But it's going to be, uh, EVM compatible, which means the smart contracts are written in Solidity, they work on Ethereum, and they also work on a different blockchain which is EVM compatible, works the same way, or Layer 2 in this case.

All right, so now let's talk about decentralized exchanges, okay? So, earlier I said, "Hey, you don't want to do this on, uh, regular exchanges like Coinbase, Binance, Kraken. You want to use decentralized exchanges." So, what are those and how do they work? Let me just pull these links up real quick. All right, so a decentralized exchange, or a DEX, is a cryptocurrency exchange that lives on the blockchain, all right? So, let me pull up an example here. This is like Uniswap. This is one of the most popular, uh, applications right on any blockchain. It's a decentralized exchange. But if you go to this website, you see this, you see this page here, it's like, "Hey, I have a cryptocurrency in my wallet, let's say Ether, and I want to select the token, let's say USDC. I say I want to swap one Ether for USDC. I click swap, I sign a transaction in my MetaMask, and boom, it's bits back tokens for me." All right, that's basically how DEXes work, uh, most DEXes, at least.

So, um, how does that actually work underneath the hood, right? Like, if I, if I go to this website and I just say, "Hey, I want to give it cryptocurrency, and it gives me back other cryptocurrency," like a vending machine, where does the cryptocurrency come from that I'm getting back, right? Well, this website right here talks directly to the blockchain, all right? And on the blockchain, uh, there are some smart contracts that power the exchange. Like, here's the website, here's the exchange contract. It's called an Automated Market Maker, all right, which basically means, like, it just handles the trades for you automatically. The market maker is like, normally, like a person or an entity that helps to fill trades. This is all automated.

So, basically, the Automated Market Maker has these things called liquidity pools. So, these are basically giant reservoirs of money or cryptocurrency that power the exchange. So, if I say, "Hey, I've got cryptocurrency in my wallet, I want to get back a new one," basically, I just exchange the cryptocurrency here, and there's a liquidity pool somewhere that has the cryptocurrency that I'm receiving back from the trade, just parked in it, all right? And then when I give it cryptocurrency, of course, my cryptocurrency is going to be deposited into a different pool, probably. And, um, yeah, there you go.

So, where, where does the money come from in these liquidity pools? Well, the bulk of it comes from liquidity providers. So, these are basically just anybody with an on-chain wallet that wants to try to make some passive income, can park their funds into these liquidity pools to get passive income, and then the exchange gets money to trade, okay? It's a win-win-win. If I want to go swap tokens, well, I've got tokens that I can actually receive back. The website, you know, has tokens to operate. And then the liquidity providers, uh, can potentially make some passive income off of parking their cryptocurrency into this application.

Now, um, a couple of things to note is that you'll see often these liquidity pools have, uh, pairs. Like, here you can see USDC. We basically, that means two tokens are going to be added to this pool, like the USDC coin and the Wrapped Ether coin. And then also, ARB. We, so that's the Arbitrum tokens, got nothing to do with Arbitrage, and we, we'll see that in the pools tonight that we're actually going to be arbitraging, okay?

So, um, one other quick note on this is, um, the flash loans actually come from liquidity pools, all right? So, some of the times, it's like, "Hey, where does the money come from when I'm taking out a flash loan?" Well, typically, it comes from a liquidity pool on a DeFi app. Right? There's no real apps that I know of that are strictly just flash loan apps, um, typically they are a secondary function of some other type of, uh, application that's a DeFi app that has liquidity pools, and like, "Hey, you can just take out flash loans on our platform as a secondary service."

So, um, couple of quick notes on the decentralized exchanges. I talked about Uniswap. Um, that is one, um, that is one exchange that we're going to use tonight, okay? We're going to Arbitrage between Uniswap version three and the second exchange is going to be PancakeSwap, okay? I'll come back to that in a minute, but basically, why these two exchanges? Well, basically, Uniswap, sorry, PancakeSwap is a fork of Uniswap version three, okay? So, what does that mean? Well, basically, uh, it's basically, it's essentially a copy of the code, it's modified slightly, but basically it has almost the exact same code, which means that if you can trade on Uniswap with the code, then you already basically know how to trade on PancakeSwap because they work the exact same, all right? So, you want to have two exchanges that basically work the same. You'll see that in the code tonight, but these are the two decentralized exchanges that we're going to be arbitraging between on the Arbitrum network, and you can Arbitrage zillions of different tokens this way, okay?

So, that being said, let's take a quick look at the diagram of how the bot works. So, let's look at everything down here first. Here's a line of demarcation. Everything below this line is going to be on the blockchain, and then everything above this line is going to be off-chain, just running on your computer. You can see blockchain here, all right? This is off-chain.

So, first, let's start off with, uh, your developer smart contract, okay? This is where this little dotted line here represents the Arbitrage contract that, um, we're going to look at tonight. So, a couple of notes about this: this is written in the Solidity programming language, okay? That's the programming language used to create smart contracts on Ethereum and other EVM-compatible chains. It's the most popular blockchain language, okay? Uh, it contains all the rules about how the Arbitrage should work. It actually implements the trading functionality, okay? And also, this is what's responsible for where you can't lose money, because you're using this smart contract, it's got safeguards inside of it, all right? Um, and the blockchain just won't let you do that, all right? So, um, what does this contract do? Well, it essentially orchestrates the Arbitrage process and also orchestrates the flash loan borrowing and repayment, all right? So, you can see it hooks into a flash loan provider here, and it hooks into this cryptocurrency exchange here, Exchange A, and then hooks into a cryptocurrency exchange B over here.

So, um, how does it work? Well, basically, it's a, it's a multi-step process. Like, step one would be: it takes out the flash loan, all right? It gets money into the contract. It trades this token over here on Exchange A, all right? It gets it back, and then it trades that token over here on Exchange B, all right? It gets that token back, and then it pays back the flash loan, all right? And of course, can send any profit to your developer wallet as well.

Now, the important thing to understand about your smart contract is it only does what it's told, all right? It's got a set of rules that it can operate under, that's what a smart contract is. They're predefined whenever you code it out, but then, like, you have to tell it to actually perform an Arbitrage. It's not an autonomous agent in and of itself. Like, you don't just put the smart contract out there on the blockchain and it just does Arbitrages for you. That's not how it works. It actually has to, uh, be told to perform an Arbitrage, okay? And that's what your bot is for.

So, above this line, everything down here is on the blockchain. Above this line, everything's off-chain, on your computer. Really, just one thing here: your bot, okay? So, your bot is a program that's going to run on your computer, and what it's going to do is it's going to monitor the blockchain. It's going to look at each of these different exchanges, and it's going to look for each time a trade comes through, and it's going to check the prices. And if there's a price discrepancy and there's a profit margin on that with the gas fees, then it is going to, uh, call your smart contract and say, "Hey, do this Arbitrage, okay?" And it's going to go through the whole process I, all a minute ago, and then the bot just going to sit back and wait for that to happen and then keep searching for the next one and the next one, all right?

Okay, so, how exactly does that work? Well, basically, um, I talked about how your bot is essentially going to watch for every single trade that happens on each exchange, okay? So, it's monitoring two different exchanges. Again, we're going to be looking at Uniswap and SushiSwap. You could change this to other exchanges later if you want to. And it also operates off of two different tokens, like Token 1, Token 2. So, it watches two exchanges. It watches a single trading pair on each of those exchanges: Token 1, Token 2 on Uniswap; Token 1, Token 2 on PancakeSwap. Um, tonight we're going to use the Arbitrum and WETH tokens. So, basically, it's going to look for Arbitrum and WETH trading pairs on, uh, Uniswap and Arbitrum Wrapped Ether pairs on PancakeSwap.

So, every single time that either Wrapped Ether or, uh, Arbitrum tokens are traded on Uniswap, or every single time that Arbitrum or Wrapped Ether tokens are traded on, uh, PancakeSwap, we're going to listen for that inside the bot, okay? Because every single time a token is traded on PancakeSwap or Uniswap, it emits something called an event, all right? Talked about events a second ago with, uh, ERC20 tokens. Basically, smart contracts let you subscribe to events that are emitted on the blockchain, and you can listen to those events and specifically swap events. We're going to monitor every single swap event on Uniswap and PancakeSwap for either Arbitrum token or Wrapped Ether tokens. We're going to watch for that, we're going to see what happens to the price, okay? And, um, whenever, if the price changes and there's a profit margin, then we will call the contract to make the trade. If not, we'll just sit and wait for the next one. And your contract, whenever it does it, it's going to perform these multiple steps: take out the flash loan for Token 1, buy Token 2 on Exchange A, sell Token 2 on Exchange B, repay the flash loan of Token 1, and then keep the profit, slash send it to your developer wallet.

And you can see the outline here is your Bot contract, Uniswap version 3, Wrapped Ether, the flash loan provider is going to be Balancer, we'll talk about that in a second, and then also PancakeSwap version 3 for Arbitrum token over here. Now, before I talk about the opportunity, let's look at it. Well, I'll talk about the opportunity first, and then we'll, we'll talk about, uh, a couple of resources you want to watch out for, okay?

So, the opportunity for this is crazy, right? Because tonight, we're just looking at two different cryptocurrency exchanges on one blockchain and two different tokens. All right? But that's, let's just count: one, two, three, four, five different variables, okay? Variable one is the blockchain that you're using. Variable two is the first cryptocurrency exchange that you're using. Variable three is the second cryptocurrency exchange that you're using. Variable four is the first token you're watching. Variable five is the second token that you're watching. If you tweak any one of those variables, you are now looking for new opportunities, okay?

So, let's talk about how you can do that. Number one, you can change the tokens, either one or both tokens, all right? If I look at a list like this, this is Etherscan Token Tracker, it's got a thousand tokens on it, there's a lot more than a thousand tokens out there that you can do this with, I promise you, all right? If you look at a website like Dex Screener, there's new tokens launching every single day, okay? Uh, you can go to Dex Screener and look at, you know, new tokens. Hold on, there's new tokens launching every single day. There's thousands and thousands and thousands of tokens, all right? So, that's the first couple of variables.

Second variables are the exchanges, all right? Now, but before I talked about how, you know, PancakeSwap is a fork of Uniswap version three, and we want to use exchanges that implement the exact same code to make it easy. Well, if you go to the forks tab on something like DefiLlama, look at Uniswap version three, there's 137 different exchanges that implement Uniswap version three's code. So, if you learn how to code on Uniswap version three, like we're going to show you tonight, there's 137 different exchanges, okay? So, thousands of tokens, over a hundred exchanges, all right? And then what about blockchains? Well, if you look at the chains, again, we're doing this with Ethereum-based technologies, so EVM-compatible chains with Solidity, obviously Ethereum is the biggest one, but it's got high gas fees, right? You can still do it, but let's see where, where else it works. It works on Ethereum, it works on Binance Smart Chain, works on Base, Arbitrum, it works on Avalanche, and a lot of other chains in this "other" category right here, which I'm not going to drill down into.

So, thousands of tokens, a hundred different DEXes, plus, and then at least a half a dozen different blockchains where this will work, probably more like a dozen blockchains when you dig into everything in this "others" category. So, you don't have to be an expert in discrete math and combinatorics to know that that's like nearly an infinite number of combinations when you start changing these variables to look for opportunities, okay? And so, basically, I'm going to give you the framework and show you how you can tweak those variables to come up with your own strategies, okay?

So, uh, if you want to look at resources for that, again, you can look at the Etherscan Token Tracker if you're on Ethereum. You can use Dex Screener to look at tokens. Um, some people ask me for ways to do this. Well, let's, you could think of a token like, just take one off this list, something like Chainlink token, all right? I'm just picking one at random here in the top 10 and looking at, uh, Dex Screener. So, if I look up, uh, Chainlink, all right, you can see all the trading pairs about where Chainlink is traded, okay? There's all these different places where you could potentially watch for Chainlink trading activity. Now, some have no liquidity, but there's still one, two, three, four, five, you know, at least, you know, probably like 10 to 20 different, um, you know, places where you could actually Arbitrage Chainlink tokens based on that list, okay? Um, if you want to look for DEXes, again, you can go to the forks tab on DefiLlama and look at the different places to find DEXes. And if you want to look at chains, of course, you can look at the chains tab on DefiLlama, that will give you some things as well.

Now, in terms of the flash loan provider, we are going to use Balancer. You could use a different flash loan provider, but I'm going to use Balancer for several reasons. Number one, it is incredibly simple on the grand scheme of things to implement into your smart contracts. Basically, you have a template here that you can just copy and paste, all right? Uh, and then just customize it where these code comments are. We'll see that later. Um, it is free to do flash loans on Balancer. Uh, they don't charge a fee on the platform. Again, you have to pay a gas fee on every single blockchain transaction, but, uh, they don't take a, they don't charge you a fee to do it. And then finally, uh, it's multi-chain. So, that means that you can do flash loans with Balancer on many different blockchains. Now, I said multi-chain, I didn't say cross-chain. Again, you can't do cross-chain Arbitrages, um, really, but you can do it on different blockchains one at a time, all right?

So, again, we'll revisit our, we'll go ahead and get into the technical explanation, revisit our diagram here. We're going to have our contract, we're on Uniswap version 3, PancakeSwap, we're on the Arbitrum Layer 2 network. Uh, you're paying the gas fees in Ethereum or Ether. Um, we're wrapping, we're we're arbitraging Wrapped Ether and then Arbitrum tokens. Uniswap version 3, PancakeSwap version 3, the flash loan provider is Balancer. All right? And then your bot is written in JavaScript and it lives off-chain.

Let's take a look at, um, an Arbitrage sequence, okay? So, basically, it starts off with the Balancer Vault, that's where the flash loans come from, all right? We take out the loan in Wrapped Ether, all right? We swap it on Uniswap version 3 first for Arbitrum tokens. We take those ARB tokens, we swap them on Uniswap, sorry, PancakeSwap version 3 for Wrapped Ether tokens. We pay back the loan to the Balancer protocol, and then we keep the profit. That's what an Arbitrage sequence looks like. And the whole goal here is you start off with this token, and you want to get back more of this token than what you started with, and that's how you profit with this. So, if you start with Wrapped Ether, you want to end up with more Wrapped Ether than what you started with, okay?

So, let's talk about how to recreate an Arbitrage scenario, okay? Because again, before I talked about essentially how you want to do this like a flight simulator first before you go try it in the real world, okay? Last thing you want to do if you're trying to fly an airplane is just get behind the wheel of an airplane and then you're probably going to crash, you're probably going to die. So, um, we're going to do this in a sandbox environment, okay, where you can basically practice your flash loans, practice your Arbitrage that you can actually do it, um, in the main net, okay?

So, how, how do we do that? Well, basically, um, we're going to use a sandbox environment that looks like this, okay? We're going to set all this up on our computer here in a second, but basically, we are going to set up, um, something called, we're going to, we're going to start our own blockchain on our computer in a few minutes, okay? This is going to be called the Hardhat node, okay? Hardhat is the, uh, framework that's used for developing smart contracts, okay? And it has a, it has a program on our computer called the Hardhat node, which is basically just a development blockchain. And the cool thing is is we can take this Hardhat blockchain and we can point it to the real blockchain, all right? And whenever we do that, we can essentially fork it, we can freeze it, we can get a copy of it on our computer, or now we have access to all the accounts, all the contracts, all the exchanges, everybody's balances, all the tokens, all the flash loans, and we can use those on our computer without actually affecting what's happening on the real main net blockchain, okay? It's really awesome.

So, that's the way that you can essentially practice your flash loans without having to spend any money. You can basically recreate Arbitrage scenarios because again, if I was going to do this class, we have to sit around and wait forever to actually ensure that an Arbitrage opportunity was going to happen. But with this setup, you can basically force an Arbitrage opportunity to happen. That's what I'm going to show you in a minute, okay? And then also, if you do this and you customize your own strategies, you can make sure they work on your computer before you actually push them out to the main net. That's the beauty of this, okay?

So, uh, this Hardhat blockchain, what it's going to do, it's going to talk to a blockchain node, okay? You have to have access to a node in order to, uh, actually, you know, do this. That's your gateway to the blockchain. We're going to use Alchemy for this, okay? We're going to get access to our own node later, and then that's going to be pointed to our Hardhat project, again, that's the smart contract development framework for, um, you know, doing that. This is really cool. You know, you can impersonate anybody on the blockchain you want to. You can unlock their wallet. If you want to be a whale, you can, you've got their cryptocurrency. And again, this is not going to affect anything on the real blockchain. So, when we do things later, like we manipulate cryptocurrency prices, we're just doing that on our computer. It's not actual real-world market manipulation, and we're only doing it for developer purposes to, like, show you how to, uh, do an Arbitrage, okay?

So, how are we going to do that? Well, here's how we create an Arbitrage scenario. So, again, basically, arbitrages happen whenever cryptocurrency prices fall out of sync on different exchanges, okay? So, how do exchange prices, uh, change? Well, again, every single time somebody trades a token on on a decentralized exchange, the price changes. That's how an Automated Market Maker works. Now, usually, it's just by a little small amount, and typically it's not going to be big enough for an Arbitrage opportunity to happen with a gas fee profitability, right? There's usually some small difference, but usually the gas fees are going to eat up the profitability. But if a big enough trade comes through, or is a time of high trading volume where lots of trades are going through, then yeah, there definitely can be an Arbitrage opportunity, okay?

So, that's how we can basically create our own Arbitrage opportunity in this sandbox environment that I'm talking about. How can we do that? Well, we can unlock a wallet. We can unlock a huge whale wallet that has like 10,000 Arbitrum tokens in it. We can sell those 10,000 Arbitrum tokens on PancakeSwap, okay? And then that's going to cause the price to dump like crazy. So, Arbitrum is going to be super cheap on PancakeSwap after we sell a bunch. So, then we can Arbitrage, you know, the difference, all right? So, we'll have a script that does that later.

So, finally, let's make a note about the prices. This is the last thing we need to learn before we start coding. Basically, prices on these decentralized exchanges are calculated by, um, their ratios in the liquidity pools, okay? So, let's actually look at this. I'm going to pull up the live links for, uh, PancakeSwap and Uniswap. So, this is the Uniswap, uh, pool on Arbitrum for, um, the Wrapped Ether and Arbitrum token trading pair. So, you can see it's got like, you know, a bunch of Wrapped Ether in here and a bunch of Arbitrum tokens in here, all right? And then it's, here's the one for PancakeSwap. It's got a bunch of Wrapped Ether tokens and a bunch of Arbitrum tokens in here.

Now, these, um, tokens are basically, we, we use these tokens to calculate the price, basically, we just divide them. That's how we get the price. So, you'll see this, like, on Uniswap, just for example purposes, say there's 4,000 Arbitrum tokens and 2,000 Wrapped Ether tokens. Well, the price will be expressed as two ARB per WETH, okay? A lot of times you see cryptocurrency prices as like, you know, say Bitcoin's $100,000. Well, that means it's $100,000, sorry, one Bitcoin per $100,000, right? Um, no, sorry, yeah, yeah, yeah, that's the whole idea, right? Um, but when we're talking about on the blockchain, we don't do it in US dollar terms, we do it in ratios of tokens. So, like, 4,000 Arbitrum per 2,000 WETH, that reduces the fraction to two ARB per one WETH, okay? Um, and on PancakeSwap, let's say there's 1,000 Arbitrum tokens and 1,000 WETH, and that price will be one ARB per WETH when you reduce the fraction. So, we're going to see that at play. All right? You can see how they're doing that here. I think these prices are not updated properly, but that's how it works there.

So, finally, the last little thing I'll note here, sometimes people say, like, "Hey, how much can, can you Arbitrage?" Well, you're going to be limited by the smallest amount of tokens in the reserve. So, this pool is smaller than this one, as you can see. This one's only got 1,000 Wrapped Ether tokens, this one's only got 2,000. So, this is how much you'll be able to, you're limited by how much is in here, all right?

Okey-dokey. Well, actually, one more thing before we get into coding. A final note about profitability. I've kind of mentioned this a couple of times, but I'll just say it again. Basically, an Arbitrage is only profitable when you can buy and sell on one exchange at a profit and then include any gas fees, okay? Now, again, you're going to see cryptocurrency prices change all the time, you'll see discrepancies, but there's not always going to be an Arbitrage opportunity because the price might be smaller than the fee, okay? So, that's, you have to always include gas fees when you're talking about profitability. And of course, if you're using a flash loan provider that charges a fee, like that, you have to take that into account, any trading fees, anything like that, you have to add that in there. But, um, yeah, we should be good to go. All right, let's go ahead and get into the coding part of the show. All right, let's take a look at the code.

So, you've got a link to this down in the description below, all right? Um, you won't have a link to this GitHub repository. All right, this is a private repository, but you do have a zip file down below that you can open. Uh, you're going to want to open this in a terminal. Um, I'm going to go through the README file here, but you will have, uh, the README file inside of your code. You can just look at that here. This will contain all the text that I'm showing you in markdown on this page right here. So, you'll need that, and you will need a terminal in order to follow along. Uh, somebody says, "If I see opportunities in real time, I wonder if I can just deploy the contract to Remix." Probably not. Um, you might get lucky and do an Arbitrage by hand, but most likely, you're going to need a bot in order.

To actually pull it off, um, because usually disappear pretty quick. Okay, so let's look at the prerequisites again. We're going to use Solidity for the smart contracts, uh, that's already installed for you with Hardhat. Uh, we're going to use JavaScript, that's already installed. Um, really the only dependency that you need is going to be Node.js. So if you go to your terminal, all right, and you basically, uh, do `node -v`, that will tell you if you have Node installed already. All right, um, I'm using version 20.0.0. I highly recommend use the same version as me just to reduce any possibilities for problems. Okay, if you don't have Node already installed, you can click this link here for Node.js. Okay, you can just click download and run through the setup steps, it will work.

Okay, so we're also going to use Hardhat for contracts, Ethers.js, which is a JavaScript library for interactive Ethereum blockchain, uh, Alchemy to connect to the blockchain with our Hardhat node, uh, Balancer's flash loan provider, and again, Uniswap version three and PancakeSwap version three. So one other quick prerequisite, um, before we start opening up all of our code here, is, uh, you're going to want to create an Alchemy account. All right, so, so before I talked about how we have this sandbox environment where we have our Hardhat node running, it's pointing to a blockchain. Well, we need access to a blockchain node, and you don't want to run one yourself. Okay, so we want somebody else to run one. All right, so that's what Alchemy is for. You can create a free account. Uh, I'm not going to walk through the setup steps here, but it's pretty straightforward. Just sign up, go in, you're going to create a new project. All right, and you're going to see, um, a link that looks kind of like this. Do connect to Alchemy, click the Arbitrum network. This is the Ethereum version, but it's the same thing for Arbitrum, and you're going to see this thing called an API key right here. Okay, save that. We're going to come back to it, but you need an API key. Basically, it's like your password to Alchemy so that you can make requests so that we can do this process right here of, uh, setting up this sandbox environment to practice our Arbitrage. So save that, we'll come back to it.

All right, so, um, whenever you open up the code in your terminal, you're going to want to make sure that you open up the `trading-v3` folder in your terminal. Okay, so not sure where you're going to save it on your computer. I keep mine in a code directory, but, uh, you're going to want to put it, you're going to want to open up this. Some, a lot of, if you're on a Mac, I know you can just drag the folder to your terminal and it'll open up. If you're on Windows, I'm not sure how that works, uh, but basically you just need to make sure that you can open up this folder in your terminal. If you have questions, you know, ChatGPT could probably help you figure that out if you're not totally sure. All right, so once you're inside there, uh, again, once you've got Node.js installed, once you've got your project open in your terminal, we're going to install all these other dependencies like, uh, Solidity, Hardhat, Ethers, etc., etc., uh, with `npm` (Node Package Manager), which comes with Node.js. So we do this `npm install`. All right, I've already done it, so it's going to finish really fast, but the first time you do it, it'll probably take a few seconds, maybe even a minute plus. All right, and that's going to basically install everything that we need to get started.

All right, so the next thing that you're going to want to do is open up your, uh, code in a text editor. All right, I'm using VS Code. You can use whatever text editor you'd like. Be Sublime Text, it could be Atom, could be Vim. I don't care what it is. Right, probably wouldn't use Microsoft Word, but, uh, anything that's meant to edit code. You can download all these for free, basically. Uh, you just need something where you can open up your project. I recommend your entire folder inside of VS Code or whatever, whatever editor you're using. If you're not sure how to do that, again, ChatGPT is your friend. So inside, if here, do a quick, uh, setup again. We've got our `package.json`. This is where our dependencies are, um, but we need to do one quick prerequisite to set up this project because, again, we're trying to create this sandbox environment to do the Arbitrage. We need to talk to Alchemy, and in order to do that, we have to provide this API key that we, uh, saved here a minute ago. All right, so how do we do that? Well, inside our Hardhat project, we have this `hardhat.config.js` file. All right, you can see here's the network. All right, is forking tab. We do `arb-mainnet.g.alchemy.com/v2/` and then we put the API key in here. Now we're reading the API key with code. All right, if you go back, look at that screenshot, this looks a lot like that same link right here. Okay, but we're reading this from our `.env` file. All right, so you'll see that right here. I'm not going to open mine on screen because your `.env` file is basically like where you store secret information, but you'll see this `.env.example` file. Okay, so let's go ahead and fill this out. All right, the first thing you're going to want to do is copy everything inside of here and create a new file right next to it called `.env`. All right, we have `.env.example`, you want to create a new file right next to it called `.env`. You're going to copy these values and paste them inside of there. So what is a `.env` file? Well, basically, it's like a secret file on your computer where you store sensitive information for this project and for this project only. It doesn't go on GitHub, it doesn't go on a web server, um, it stays here on your computer. All right, it's where you can put things like cryptocurrency private keys, and you can also store like your API keys from Alchemy. So you're going to want, first step is copy this, put it in that new `.env` file. Go ahead, go back to Alchemy, copy this API key, and then put it in between the quotation marks. So let's say it's `abc123...`. All right, put it inside of there. Okay, but do it in the `.env` file, not in the `.env.example`. Again, I'm not going to show you mine because it's got, you know, my private key and my API key in it, which I do not want to expose on this video, but basically you want to look kind of like that. All right, but in the other file, right? I'm just modifying the example for example purposes.

Okay, so the next thing is the private key. All right, so the private key, again, it's kind of like the password to your crypto wallet. You need a crypto wallet in order to do Arbitrage. All right, you got to be able to deploy the smart contract, pay the gas fees for it, um, and, you know, you have to have a place where the money gets sent whenever you get profit. Okay, so, um, I'm going to use just a cryptocurrency wallet from Hardhat on our presentation tonight. You should do the same thing when you're doing your demonstration, uh, but if you go do this for real later, you want to replace this with your actual private key. Now, a quick word of caution, okay? Do not use, like, like create a brand new private key for this. All right, don't use a private key that you already use to, uh, store your crypto in. All right, because anybody who ever saw this file, whether it's by mistake or whatever, could steal your money. All right, you never want to use a different cryptocurrency wallet for development purposes. You always want to create a brand new, uh, private key for that. All right, and and only put the cryptocurrency that you want to use for gas fees. But, uh, tonight we're going to use a Hardhat, uh, private key. So let's go ahead and get that set up.

So basically, we've already added our API key. We're going to go ahead and start this Hardhat node here and set up this sandbox environment. Okay, so you can see that you've got the, um, command here to do that. You can just copy and paste this: `npx hardhat node`. All right, and boom, we have a blockchain running. All right, so you can see we just a blockchain that's this thing right here from this diagram, and it's got, you know, 20 accounts in it with private keys and addresses, and they all have 10,000 fake Ether in there. Now, don't get excited, it's not worth any real money. All right, but this is all fake cryptocurrency on this blockchain, and we can use any of these accounts. Now, if you go back and look at the instructions, it says, "Once you have started the Hardhat node, copy the private key of the first account." So go here, copy this private key, and then in your `.env` file, put it inside the quotation marks. All right, that's going to be the private key for your demonstration purposes. You must do this in order to make it work later. You can change this whenever you're customizing your own strategies, but for now, you got to do that. So make sure you got your API key for Alchemy in there, make sure you got your private key in there, make sure it's in the `.env` file, not the the example file. Okay, and you should be good to go.

Um, now finally, uh, we are, we have this Hardhat node running. All right, and it's actually talking to the blockchain. It's talking to Alchemy because we're using this configuration, which I showed you a minute ago. All right, we're using the forking setting on Hardhat. We're putting in the URL to Alchemy with our API key, and we are forking the Arbitrum blockchain because of this line of code, and that all takes into effect when we simply run this `npx hardhat node` command.

So where's the link to the GitHub? This is a ZIP file down below. Uh, you won't have a link to the actual GitHub itself, but you will have the code in a ZIP file down below. All right, last thing too, before I mentioned, you know, don't put your crypto wallet keys inside of here, also don't use these private keys. Don't, don't put any real cryptocurrency in these wallets either. Okay, because everybody who's used Hardhat before or anybody who's watched this video has access to these private keys, and as soon as you send cryptocurrency to that, somebody's going to withdraw it. Okay, um, it's just going to happen. So do not send any real money to these private keys either. Whenever you switch gears to actually using real money, create a new private key, make sure you put it in here. All right, and then when you're sending cryptocurrency to your address, make sure you don't use this address. Make sure you use the address that corresponds to that other private key.

Uh, yes, it can do multiple pair combinations at once. You got to customize it, though. All right, so now that we have this environment set up, we're going to, uh, deploy this developer smart contract here. Um, then you can do all this. Sorry, work on this part first. We'll get to the bot in a second. So to set up the smart contract, you can see the code, um, is here. All right, we'll go over the code in a minute, but we're going to take this contract and put it on this blockchain right here. All right, so how do we do that? Well, the command for that is here. All right, I'll copy and paste it. I'm going to go back to my terminal. I'm going to create a new window. All right, because I've got the node here, I want to have like a workbench window over here. You can also do this in your text editor, like VS Code, but I just like seeing stuff side by side on these presentations, that's why I'm doing this way. Um, so I'm going to paste this command in there: `npx hardhat run scripts/deploy.js --network localhost`. I'll bring it all the way out in case you want to type that out manually. Hit enter, and you'll see the activity happen over here. All right, there you go. So your Arbitrage contract was deployed. All you can see this address here, you can see the transaction went through on the blockchain. Okay, now you want to copy this address and make sure it matches what's in your config file. We use a config file to keep track of everything. So if you go to this `config.js`, all right, you can see like your project, other project settings. You're inside of here, like `isLocal`, `isDeployed`, `arbitrageAddress`. Paste that sucker in there. Make sure it matches. Okay, it should be the same because usually the first contract that you deploy on Hardhat is the same, but we just want to make sure. Go to your `config.js`, paste that sucker in there, make sure it matches. While we're here, you can see it's got other settings like the tokens you want to arb for, arb against, like this is the arb from token and the wrapped ether token. So if you want to change the tokens, this is where you do it. All right, uh, we have the Uniswap smart contract addresses right here. We have the PancakeSwap smart contract addresses here. So if you want to swap out the exchanges, of course, there's some smart contract coding involved, but you also want to update these here. All right, now if you're just changing the tokens, there's no smart contract coding involved. You can just literally change these addresses. Should be good to go.

All right, so the next step is we're going to start the bot. So we got this set up, we put this contract on the blockchain. Now we're going to start our bot that actually watches for arbitrages. So I'm going to create a new window yet again. I'm going to type this command: `node bot.js`. Okay, you can see that, uh, right here. Start the bot: `node bot.js`. And you can see that the bot is running. Okay, see the bot's running here. It's listening. It's using the Arbitrum WETH pair. It's watching Uniswap pool, the PancakeSwap pool, and then it's waiting for a swap event. All right, so again, what does our bot do? It watches all the trades that come through and it says, "Hey, can I profit or not?" So it's waiting for one of these swap events to evaluate this logic.

All right, now finally, we want to actually create an Arbitrage opportunity and observe the bot doing what it's supposed to do. Okay, so we're going to go back to this scenario that I talked about. We're going to impersonate a large whale wallet with 10,000 ARB tokens. We're going to sell them on PancakeSwap. We're going to create a massive price difference, and our bot is going to detect that in real time, and it's going to do the Arbitrage. We can observe it happening. We can actually look at the profit come into our wallet. So how do we do that? Well, um, if you look at this `scripts` file, you can see we have this `manipulate.js`. What this is going to do is essentially, uh, unlock this account that's the massive ARB whale wallet. We're going to get 10,000 tokens, and it's going to manipulate the price, which you can see here, and it's basically going to sell those on Uniswap with this code. I'm not going to go over all that right now, but basically that's what this does. So we can run this script with the following command. Go back here, copy and paste this. Go to your terminal, paste it here: `npx hardhat run scripts/manipulate.js --network localhost`. All right, I've got the blockchain running here, I've got the bot running here. I want you to watch this window while I run this command. Okay, because once I do it, it's going to finish, and the bot's going to detect it in real time, and it's going to do the Arbitrage. So I'll hit enter. Watch here. All right, boom, there you go. So I'll scroll up. You can see some output here. So waiting for swap event. A swap was detected. It's checking the price. Here's the current block. It's looking for Uniswap, PancakeSwap, our WETH pairs. There's a 40% roughly price difference. It's going to figure out which directions it wants to swap on. Okay, it shows you the Arbitrage: Buy on PancakeSwap, sell on Uniswap version three. All right, it determines the profitability and it logs out a summary here. Basically, if you're arbing Wrapped Ether, here's how much you're going to have before the trade. Here's how much you're going to get after the trade: 0.113. And then here's this is basically the prediction of what's going to happen, and then here's the actual final result. Okay, um, so it actually gained 0.113. It's pretty dang close. Okay, slightly less, but, but pretty dang close. So let's say 0.113 times what's the current price of Ether? Let's just, I can't remember what it is. Let's say it's $3,300, something like that. That'd be a $372, $373 roughly, uh, Arbitrage, uh, right there. Okay, so not too bad for a single arb. Okay, so that is observing the bot working in real time. So that's basically what it will do if it's listening to these things in real time on the mainnet.

Okay, so I'm going to walk through the code here and explain it here in a second, but really quickly, let's talk about how you can run this thing for real. What do you need to change? Uh, obviously, you need to add your developer private key here. Uh, you need to update the, let's see here, `hardhat.config.js` file to actually point to the mainnet. So you just want to add a mainnet network here, put in the URL. All right, and you're going to want to change some settings in your `config.js` file here. So `isLocal` is basically what's the status of your bot? Is your bot looking for trades locally? It's currently set to `true`, so it's watching for our local blockchain. Okay, if you change to `false`, it's going to look for Arbitrage trades on the real blockchain. So I can go ahead and just do `false` here and, uh, and `isDeployed` true or false. Is your contract deployed? True or false? True is on the blockchain, false is not. So `false`. I'm going to set to `false`. So this is basically the setting that you can use, uh, for monitoring on the mainnet. I'm pretty sure. Let me just double check.

So if you want to just watch for arbitrages to see if they come through on a particular token pair before you deploy your contract, you can kind of put your bot in read-only mode with this setting right here. Okay, so I'll just save it. It's not going to actually try to attempt any trades. It'll just watch for stuff. So I can just do that. We can set it, let it run in the background and see if it actually, uh, detects any trades. Okay, so for a deployment setting, would basically be `isLocal: false`, `isDeployed: true`. And that's that's what you need to change if you're going to actually move to mainnet. And of course, you need to deploy your contract, and you run this deployment script on the mainnet. Basically, it's this command right here, but `network` would be `mainnet` instead of `localhost`.

All right, so let's talk about the code itself. All right, let's start off with the Arbitrage code. Okay, so this is the smart contract for doing Arbitrage. If you go back to our diagrams, that's this thing right here. Okay, so this is written in Solidity. Let's go over the basics. Let's first start off with the flash loan template because that's where our starting point. So this is the Balancer flash loan template. Essentially, it, uh, tells you what to do. This is basically a copy and paste that you can put into your project. Basically, you have the imports for the libraries up here. You create your own contract called whatever you want. This is just called `FlashLoanRecipient` for example purposes. Uh, you inherit from the library like this. You say your contract is `FlashLoanRecipient`, and then you add this boilerplate code inside of here. Basically, this template code, it does a couple things. It just saves the address of the vault so that you can take a flash loan with the variable here, and it just has two simple functions. So `makeFlashLoan`. This is what you want to do whenever you're requesting a flash loan. This function can be called whatever you want to, as long as it executes this line right here. Then this second function is what happens when you actually receive the flash loan from the flash loan provider. Now, this function must exist on your smart contract. It must have this exact same name. It must have these exact same arguments. It must have this exact visibility. Why is that? Because you're going to call this function to ask for the flash loan, and then Balancer is going to say, "Okay, hey, here's your flash loan," and when I give it to you, I'm going to call this function on your smart contract. So it's got to be there if you want to, uh, receive the loan. Okay, um, and so inside of here, you'll see this like dot dot dot, you know, do stuff with the money here, and then finally, you repay the money back to the flash loan provider here. So we'll just use this template inside of our code to do the Arbitrage. Let's see how. You'll notice we essentially, uh, pull in the libraries at the top, just like they do here. All right, we additionally pull in the Uniswap router. Okay, right here. That's another library. We create our own contract, we call it `Arbitrage`. We can call it whatever we want to. `Arbitrage` seems to make sense, and we say `isFlashLoanRecipient`, just like the Balancer documentation. Okay, we store the variable for the, uh, Balancer vault where we're asking the flash loans from, just like they tell us to here. Um, we have a couple of other things like we say the owner address. This is your developer wallet so that you can only call certain functions. We have this `trade` struct that we use to simply pass information around. We'll come back in a minute. Uh, we set the owner in the constructor function whenever the contract's put on the network, but you'll see we have this function called `executeTrade`. All right, and that's basically what's representing this `makeFlashLoan` function. This is the first function from the flash loan, and you can see this line here: `vault.flashLoan` is the same line as this `vault.flashLoan` here. Okay, so basically, this is the entry point into our thing, `executeTrade`, and then, uh, you can see this second function here, `receiveFlashLoan`. All right, that's what corresponds to this right here. So we have these two functions in the contract. Basically, `makeFlashLoan` corresponds to `executeTrade`, and then `receiveFlashLoan`. If `receiveFlashLoan`, again, this one can be called whatever you want to. We call ours `executeTrade` because it's a trading contract. `receiveFlashLoan` has to be called `receiveFlashLoan` because it's not going to work if it doesn't. Okay, so another thing that I'll mention is `executeTrade` is the entry point for our smart contract. So essentially, whenever this bot is calling your smart contract to execute an Arbitrage, it's going to be calling this calling this `executeTrade` function. It's going to say, "Hey, all right, I found a trade. Call the `executeTrade` function." It's going to run down the logic. So what is that logic? Well, it's got a couple few, it's got a couple arguments here: uh, the `routerPath`, basically the order that you want to swap on the exchanges, uh, the `tokenPath`, like which token to swap first, which token to swap second, any `fee` that's involved, which is going to be zero in this case, and the `amount` of money that you want to flash loan. Okay, so basically, we just save those things to some variables right here. All right, and then we call the `vault.flashLoan` function with the current smart contract address, which is the recipient of the flash loan. That's what this stands for: is the address, the smart contract you're coding inside of, uh, the token that you're arbitraging or borrowing, excuse me, uh, the amount you're borrowing, and `data` that you need to access later, which we save, uh, in this `trade` struct to pass around right here. Okay, so then, uh, that's what we do to ask for the flash loan. Now, when we receive the flash loan, um, we get it back, and it tells us the tokens that we get, the amount we get, any fees, and `data`, which we passed in here, and we're going to save all those into variables again. All right, and then basically, um, what we're going to do is arbitrage twice, or not arbitrage, we're going to trade twice because again, what you're going to do is basically swap on one exchange and then do the exact opposite on the other exchange. We go back to this sequence here. Okay, we swap on this exchange, we go from WETH to ARB. We do the exact opposite on the second exchange, ARB to WETH. So if you think about terms, token one, basically, the first exchange here, token here, and the second token here. We do the exact opposite. So let's, let's, let's walk through that step by step. So, uh, swap on V3. So which, what is this? This is a function down here that implements the swapping functionality for Uniswap version three. Okay, so here's Uniswap documentation for version three. Let's see here. Basically, here's how to do a swap in Solidity. We can see it directly inside documentation. We're, we're this smart contract is really not that fancy. We're basically just taking what's in the documentation for, uh, the instructions and just gluing it into our own smart contract. Okay, so you can see here, uh, here's how they tell you to set it up. Basically, you call this function `exactInputSingle` and then you pass in these parameters, which you configure right here. So you can see that `exactInputSingleParams`, and then you set up the `params` here. That's what `swapOnV3` is. It works the exact same on Uniswap version three as it does PancakeSwap. That's why you're seeing the beauty of using the exact same exchanges. They work the same. So we can literally just copy and paste the code, but do it in the reverse order because basically, you can see the router address is the exchange you want to use. We just swap out the different router. The first token is token in, the amount in, token out, the amount out, and any fees. And we basically just, uh, swap those values around to accommodate the trades. So for the first trade, uh, we trade on the first exchange, exchange zero, the first token, token zero, we use the flash amount, and then the second token, token one, here. All right, on the second swap, which would be, you know, PancakeSwap in this case, well, in our case, it was it was PancakeSwap first, and then, uh, Uniswap second. So Uniswap would be exchange one, token one, token one, uh, token zero, flash amount, and any trade fee. Okay, so that's the first swap. That's the second swap. Finally, after we swapped, we have to do a couple other things. We have to repay the flash loan. Okay, because again, none of this is going to work if we don't pay the money back. Earlier I said, "Hey, it's mathematically impossible to take out a flash loan and accidentally lose the money or try to steal the money." Well, that's because it's not going to let you do the transaction unless you pay it back. Here's the line of code that pays back the transaction, and then finally, uh, any profit that we have off of this transaction, we send to our developer wallet right here. All right, so that's it. That's the overview of the contract.

Okay, so quick question: Does the inputs have to be in an array? Uh, unfortunately, yes, um, because that's how Balancer flash loans work, and, um, whenever you're, it's already coded for in the bot that way, and whenever you're swapping here, uh, we need to work with arrays because, because we keep everything in order, arrays help you keep your code sorted in an order. It's pretty standard practice when you're doing this type of stuff. So, uh, wait, loss f is asked a couple times, can the bot trade multiple pair combinations at once? Uh, it can, you've got to customize it to do that. Okay, so, um, let's go look at the bot code. All right, so all this stuff at the top, don't get freaked out by this. This is just pulling in some files. This is pulling in some libraries. Okay, Ethers is the JavaScript library that talks to the blockchain. We've got our `config.js` here, which again, I showed you that before, that's our configuration settings. Um, let me just close this over here. We're pulling in some helpers that we've created. I'll reference those in a second. These are the variables from our `.env` file and our config file, or just the config file. Uh, basically, `arbFor`, `arbAgainst`, these are the tokens. `pullFee`, `uniswapPriceDifference`, `gasLimit`, `gasPrice`. Again, those are all coming from the `config.js` file here. We're just saving them as variables so that we can use them in our code. `isExecuting` is a variable, uh, because everything runs, have this main function, and you don't want to try to call the function twice. So we set, we keep track of that here. Like you don't want to call the function while it's being executing. That's called reentrancy. Um, so we have a safeguard that keeps you from doing that here. Okay, um, so let's look at the `main` function here. Okay, so `main` essentially is the function that makes the app run. So really, this is all a single JavaScript file. All right, we can see we have this `main` function here that's the meat and potatoes of the entire program. It calls other functions, of course, but this is basically what starts the app. We define the function here, and you can see we simply call it here at the bottom of the file. This is what starts the app whenever you run the script, but we essentially just write the function here. Okay, so what's it do? Well, it gets the token and contract, saves them to variables. Okay, um, based upon our settings of the app, uh, it gets the different Uniswap pools and this, the PancakeSwap pool. So `uPool` stands for Uniswap Pool, `pPool` for PancakeSwap Pool. It logs as the console, and then finally, it listens to the event. So again, um, we talk here about the, the app is basically just watching all of the trades that come through. All right, the swap events on Exchange one and Exchange two. It listens for those and it says, "Can I profit? Yes or no?" All right, so basically, uh, here's how it listens for those. So basically, on the Uniswap pool, or `uPool`, it says `onSwap`. So every single swap event that comes through, it's going to call this function called `eventHandler`, that's going to eventually evaluate, uh, the data that comes back to determine whether or not it can Arbitrage, and if it can Arbitrage, it's going to do it. All right, so we do that for the all the swap events on Uniswap and all the swap events on PancakeSwap. All right, so whenever it gets, um, a swap, it uses the `eventHandler` function. It passes in the pools and the tokens. It's got this `isExecuting` variable we talked about before because you don't want to call this function while it's being executed. Um, we just have that wrapped in a conditional here, and the first thing it does is it calculates the price difference because again, this whole thing is a new trade just came in. We need to see if it can make a profit. If we can make a profit, we're going to execute a trade. If not, we're going to sit there and do nothing. So the first step is check price to calculate the price difference. So we got this `checkPrice` function down here. It's going to pass in the pools, the first token, the second token. All right, it gets the current block and it checks the Uniswap price. So it's got this `calculatePrice` function here that comes from the helpers. All right, so if you look at helpers, `calculatePrice`, let's go back to our notes and our diagram. Remember, our prices are expressed as ratios of how many tokens are in each liquidity pool. So here you can see that there's, you know, 8 million Arbitrum tokens and 1300, you know, Wrapped Ether tokens. You divide those two things to get the price. Okay, just like we saw here, 4,000 ARB, 2,000 WETH, that's two ARB per WETH. Well, basically, we're going to do that same math in our code here. Okay, so `calculatePrice`, what it's going to do is basically, uh, take the pool. All right, it's going to get the price, and it's going to, it's going to tell you the price based upon, uh, the ratio of those two things. If you, you look at this link here, it'll give you more details on how that works. Go through this. All right, it's pretty good. It's, it can get a little bit complicated, but I think you'll get the idea. Two, this function does that for us. It calculates the price. Uh, we get the price on Uniswap, we get the price on SushiSwap, sorry, PancakeSwap, and then we do those fixed, and then we calculate the price difference here. Basically, we subtract the Uniswap price from the PancakeSwap price, divided by the, uh, PancakeSwap price here, multiply by 100, and then we do `toFixed` to, all right, and that'll tell you the price difference. Now, uh, um, we also get the `exchangePath`. All right, so we determine the trade direction. Basically, which exchange do you want to start on? Are you going to start on Uniswap? You're going to start on PancakeSwap? We need to know. So the price difference will give us a clue to that information. So the `determineDirection` function, which you can see here, passing the price difference. So basically, if the price difference is larger than our price difference that we have in the app settings, uh, basically it'll say, "Hey, potential Arbitrage Direction: Buy on Uniswap, sell on PancakeSwap." Okay, else if it's less than that minus right here, uh, we do the opposite: start on PancakeSwap, finish on Uniswap. All right, so price difference, exchange path. Now, you'll notice the `exchangePath`. If it doesn't get either one of those, it's going to return `null`. Okay, so basically, uh, that's going to give us a clue on whether or not there's actually an Arbitrage opportunity because if it gives us an exchange path, then we know where the Arbitrage is and how we can execute it. All right, um, basically, if the `exchangePath` does not exist, we didn't tell it, you know, "Hey, here's the path you can do it on." That's because there's no Arbitrage opportunity available. So if there's no `exchangePath`, we're just going to log to the bot, "Hey, there's no Arbitrage opportunity currently available." We're going to exit the function right now, and it'll just wait for the next swap to come through. Okay, now if that's not the case, it's going to continue on. All right, and it's going to say, "Hey, now we're actually going to calculate if this could be profitable or not." Okay, because again, either there is an Arbitrage opportunity, there's not. If there is, we still have to see if it's possible based upon the profitability. So we call this `determineProfitability` function, pass in the `exchangePath`, `tokenZero`, `tokenOne`. All right, uh, let me just close this. We get the liquidity pool again. That's going to come from the helpers as well. Again, the Uniswap gave us the price directly, uh, from the app itself, but now we can actually determine token balances based off these ratios. So again, going back here, we can see, um, these ratios. We're basically going to get these reserves here, all right, and we're going to return those as an array right here. That's going to show the liquidity. It's basically going to show us exactly what's in here, like this amount and this amount. We're going to get each of those right here in the helper. We're going to turn to an array. All right, here's the liquidity, here's a percentage. The minimum amount, and then we're basically going to, uh, get the `exactOutputSingleParams` to give us the tokens needed. So again, we saw that before over here in the Uniswap documentation. I'll see where it go. Yeah, right here, `exactInputParams`. This is `exactOutputParams`, and we're going to quote, we're going to get a quote to see how much tokens are going to come back. So that'll give us tokens needed, uh, based upon that information. We can get the quote for the `exactInputParams`, which is what this is for the swap. We pass those in, it'll tell us how much token is returned. Okay, and then basically, it'll tell us, "If you put in this amount in, this is how much you're going to get out." Okay, and then we can calculate the differences by taking `amountOut` minus `amountIn`. That's going to give us the price difference. That's going to help us to determine the profitability. Now, again, you have to factor in the gas costs. So we're going to take the estimated gas cost, which is the gas limit times the gas price. All right, we're going to factor all those in, and we're going to log to the table, uh, whether or not that's going to be profitable or not, with the price difference and also the gas fees involved. Uh, set up. Okay, so if the `amountOut` is less than the `amountIn`, it's not profitable. So we're going to exit this function. All right, uh, if there's no ETH balance after, we don't have enough gas, we'll exit this. Otherwise, we return `isProfitable: true`, and then we'll give the amount, and we will also log that to the console. Okay, so `determineProfitability`, we just finished that. `isProfitable` bang. If that's not profitable, we'll just exit this function. But if it is profitable, we're going to execute the trade. Now, this is the exciting part. Again, we've been listening to the events, evaluating the data as it comes in, we got a swap, we did the math, is profitable? Yes, no. In the yes case, we finally get to this point of executing the trade. Okay, so, um, that's what we do when we call this function. So what does it do? All right, so `executeTrade`, um, basically it takes in the `exchangePath`, `tokenZero`, `tokenOne`, the `amount`. It sets up the `routerPath`, it sets up the `tokenPath`. Basically, it's setting up all the variables for the input of this function right here on our smart contract: `routerPath`, `tokenPath`. You can see that here, `routerPath`, `tokenPath`. All right, the `account` is just the account that we're connected to from our private key. It creates a new Ethers signer to do that. All right, um, we've got the `fee` and the `flashAmount`. All right, so we fetch the token balances, ETH balances before, just so that we can fill out this table later. But basically, uh, if the project is deployed, which is that setting from our `config.js` file, which you can see here: `isDeployed: true/false`. So if `deployed` is `false`, we're not actually going to make any trades. But if `deployed` is `true`, we are going to make trades. Um, so it's going to pass this condition, and, uh, we do a transaction on the blockchain like this with Ethers.js. We say `await Arbitrage.connect(account).executeTrade(...)`. We call this `executeTrade` function, which is literally that exact function right here. All right, we pass in the variables: `routerPath`, `tokenPath`, `poolFee`, and `amount`. That's the same as `routerPath`, `tokenPath`, `poolFee`, and the `amount`. All right, and then we wait for that transaction to finish: `receipt = await transaction.wait()`. Whenever that's done, uh, we'll log "Trade complete" and we'll put all these variables out into the console, like the balance before, balance after, etc., etc. All right, um, so that's it. That's an explanation of the code.

So, uh, I'm going to say a couple other things about customizing this. Um, once I'm done with that, we'll roll into a time of questions. So if you got questions, go ahead and start dropping them in the chat there. Um, someone says, "Do we still need an Alchemy setup to run this on the mainnet?" Uh, yes, you do, but you don't have to fork it. Uh, you'll actually use the mainnet setup. Kind of wallet. Do we need to set up? You don't actually need an external wallet like MetaMask setup. You can just import the private key into your bot. Do we keep Arbitrum for gas fees? No, you pay the gas fees on the Arbitrum network in Ethereum cryptocurrency or Ether. Um, I say, I say that because the cryptocurrency is actually called Ether, but most people call it Ethereum. So I just say that so people know what I'm talking about. Um, so, um, so as you can see, there's a lot of here, right? Like I wish we had the time to build this out from scratch. We unfortunately don't on this presentation. Um, couple things I'll say about that. If you want to do the easy button and just fiddle around with stuff and not have to get into the weeds with all the code, right? You, of course, can just change the tokens, uh, inside this `config.js` file, right? You can just change these tokens here, our for and against, right, and deploy the contracts with the mainnet and then set it up that way. Okay, that's the easy way. Now, again, in terms of creating your own strategies, modifying the tokens, modifying the exchanges, that's when the developer stuff starts to kick in. And again, you're going to need some developer skills to do that. You know, the best way to get those types of skills to create a competitive trading bot is going to be hands-on mentorship. I do have a couple slots open for the blockchain developer mentorship. I'll put a link to the application down below. You want to make sure you jump on that while we still can. Um, yeah, I'll put a link to that down in the description below. We got a lot of students from the mentorship on the presentation tonight. I'm sure that they will attest to the fact that it is a huge game-changer for leveling up your blockchain skills, no matter what your goals are. If you're trying to create a bot, if you're trying to break into the industry, land a job, it's definitely the fast track to becoming a pro-level blockchain developer. So anyways, that's, that's pretty much how you're going to modify this. You can swap out the tokens pretty easily with the `config.js` and some other adjustments, but if you want to create your own strategies, implement new exchanges, implement other stuff where you're changing the smart contract code, modifying the bots, you're gonna need some develop. Um, and I did see one question earlier, like, "How do I get this to watch multiple tokens at the same time?" I'll go ahead and answer that now. Basically, um, you can, uh, look for multiple, basically you just add this over and over again, right, and and create new pools. You're just going to duplicate this `eventHandler` with different pools and different tokens. That's how you get to watch multiple tokens at the same time. That's the easy way to do it. So how would you find tokens? Is it just random combinations? You can think about, uh, yep, basically again, you can use something like Etherscan Token Tracker as an entry point. There's, you know, I think I said a thousand before earlier. I don't know why I said that. Oh, I said a thousand because, uh, it has 1,931 tokens with our, uh, okay, or neutral reputation, but it's got like 1.4 million tokens indexed on there. That's just for the Ethereum network. There's a lot more than that on other blockchains. So you can use this as a starting point. Again, you can use Dex Screener as a starting point, and then look them up to see where they're trading across different cryptocurrency exchanges. Uh, okay, how much money do you need to load your bot with? Your fees on Arbitrum, you don't need much. I mean, you could start with a dollar, you could start with 10 bucks if you wanted to. How do we know which tokens we can Arbitrage for on Balancer? Are they only mentioning the token holdings? Yeah, you'll see them on the Balancer documentation.

Also, a pro tip is if you can't like, like this is getting more advanced, but like you're not limited to tokens that you can borrow on Balancer, right? Because let's say you only wanted to borrow Wrapped Ether from Balancer, well, in your smart contract, you could instantly swap that to a different token, right, that you wanted to arbitrage for. Now, it's gonna eat up in the cost a little bit, but you could do that if you had to.

Uh, can I test the Balancer loan on the Hardhat? For you, sure can. That's why we do it that way.

Uh, where are we going to get the files on the tabs to the left other than Pancake and Uniswap website? Um, I'm not sure the question there. All these files that you're seeing here on the tab to the left are contained inside that zip file.

Um, does it keep deploying? I'm not sure what that question is. Are my Linux platform or Windows? I'm on Mac, so it's it's Unix-based.

Um, how do we know what tokens? So we talked about that already. Sorry, my chat keeps moving on me. How often does it deploy and does it keep going indefinitely? Oh, so it doesn't deploy anything new. Like, once you deploy the smart contract on there, it's just done forever, if you're saying.

Um, how often does it, maybe your question is like, if the bot's listening for trading activity and it finds an arbitrage opportunity, um, it's going to trigger the arbitrage and it's going to keep running. It's going to keep running until you stop it.

Uh, excuse me, how do I change it to work on Base blockchain? The good news is the code doesn't really have to change. Um, you want to change your conf.json file. Um, you have to deploy the contract on Base. So, uh, in the Hardhat config file, basically you want to create a Base setting here. So like, here's Hardhat, you basically a new thing after your Base. You don't want to use the forking setting. You put in the URL, basically you get the, uh, Alchemy URL for Base. You put it in there. Whenever you run your deployment script, you want to do `--network base`. So again, going over here, uh, your deploy script, `--network base`. And then of course, if there's any, uh, exchange addresses that have changed for Base, you want to look those up and then add those to your contracts, sorry, your config.json file here and update any token addresses for Base as well. That's pretty much it. It's super simple to change the blockchain if you, if you keep the exchanges the exact same.

Okay, um, well, we need to load up the wallet with Wrapped Ether for gas fees. So, no, not Wrapped Ether, actual Ethereum cryptocurrency Ether. You're gonna have to bridge it over to the Arbitrum network if you're doing it on Arbitrum. Or if you have a cryptocurrency exchange that supports, um, withdrawals, you could just withdraw it onto the Arbitrum network. Or if you have a wallet where you can purchase, you know, cryptocurrency directly on the network, like with a debit card, like MetaMask lets you do that, you could just buy some in there.

Is this video, excuse me guys, I'm really sorry, I've had a long day. Um, is this video available after the program? Yeah, you have a replay link.

Please provide some websites that provide APIs for tokens that we can fetch all the prices. Uh, you can get the prices directly from Uniswap. You don't need a special API for that.

Um, sorry, my chat keeps moving on me. How do you know what tokens we can arbitrage for Balancer? Are they only mentioned? Yeah, I talked about before, the tokens have to be the same addresses. These, the tokens have to be the same addresses. These all correct?

Um, I'm not sure what that question is. Let's see here. So, do I personally use this bot? So this is a framework for creating your own strategies. So I have used this template as a launching point for my own bot, but I obviously customize things to do my own strategies. That's what I talked about before, like I did a class in the past where essentially I took one of my strategies that I was doing and I was like, all right, let's just do it in the class. But as soon as, you know, you do that, everybody's trying to jump off the same opportunity and, uh, it's just you're competing with one another. So the best that I can do is give you a framework, and this is a framework for something that I will use. It's just obviously I'm not using these exact same settings.

Let's see here. Is where the same address for Pancake, Uni, and Balancer? Yes, it is. Uh-huh. If it's on the same network, that the cryptocurrency address is the same.

Can you put this, can you make this work on a Docker container? Yeah, you can dockerize it for sure.

Is the terminal in Alchemy? No, the terminal's on your computer, computer, where you put the money for fees. Uh, you put it into the wallet that you're using on the bot. So like, you can create a MetaMask wallet, send the money to that, export the private key, put in your .env file. But again, you want to use actual Ethereum Ether, um, not ETH.

Yeah, I, I, so it's confusing. Like Arbitrum is an Ethereum Layer 2. So I understand like not liking the gas fees on Ether, they are high. Arbitrum Layer 2, the gas fees are way, way, way cheaper. We're talking like cents, um, even fractions of a cent in some cases. Um, and but you still pay the gas fees in ETH. So you have to use Ethereum, actual Ethereum cryptocurrency Ether, bridge to the Arbitrum network. Arbitrum is not the gas token for the Arbitrum network.

How did I loan out? We, I don't see it in the Balancer token holdings. Uh, it's definitely in there. You might be looking at a different version of Balancer. Uh, you may, you may be looking at the pool address. No, you keep your gas and the same as the ARB wallet. It's just you don't want to like, if you're like, hey man, I'm a crypto holder and I've already got a crypto wallet, so I'm just gonna use that, run this bot. Don't do that because you don't want to expose that private key.

Oh, oh, I see what you're saying now. Yeah, so the ARB wallet, the ARB contract isn't a wallet, it's a contract. So, um, yeah, the gas money goes to your developer wallet, right? Which that's what you put in your API key in this .env example right here, like your API, like I mean, sorry, your private key inside here. This is your developer wallet. This is where the gas money goes.

Same contract works on Uniswap version 3 forks? Yes. Sorry, my chat keeps moving.

Where does it show how much we're buying and selling? Uh, in the bot.js file, you can see that's all this type stuff.

Um, what about running a light node? You could theoretically do that.

So great for putting this together. Such a much detail for a great price. Awesome. I'm glad you really dug it. I was so excited to do this class. Um, so got to run, running late. Yeah, we're gonna wrap up here in a second. I'm just gonna crush through some more of these questions and we'll sign off.

Um, let's see here. Helps me with a new trading bot too. Awesome.

Um, same contract works? Yep, yep, yep. On all V3 forks? Yep.

Let's see. Dev wallet could be run on Metamask or do you recommend a hardware wallet? I mean, it doesn't matter as long as you get a private key. Um, that's all you, that's all you need. Metamask is what you mean? Yeah, it could be a Metamask wallet, that'd be totally fine. You just don't want to keep a lot of money in there.

Can we use Dex Screener for price tracking? Not for arbitrage. Like, you can, you can watch stuff, like you can watch volume and stuff, but you don't want that to be the signal for the bot.

So you put Ether in the wallet, call to make approvals by the bot, basically? Yeah, you run this Node.js. Yep.

What's competition like? Uh, I mean, it, arbitrage is competitive, but that's what I was saying, like if you have so many different strategies, like you can find set that other people aren't doing. Like you theoretically could find a manual arbitrage out there, it's gonna be hard to do. But if you have a bot, like, and you're looking at stuff, you can definitely do it.

All right, how much money, gas money? I mean, you could start with a few dollars, would be fine.

Did I start with constants for gas fee and cost? Yeah, just to keep things simple. You can make it dynamic, though.

Uh, do you not need a, uh, to do I need a VPS to run the bot 24/7? You can, that's definitely a great way to do it. You can also just keep your computer on all the time if you want to.

All right, everybody, um, I'm gonna have to go and wrap it up there for today. We got some great questions. I know there's a couple questions we didn't get to fully answer on the class tonight, um, but there are definitely a couple ways we can get those questions answered.

Number one, if you join the Blockchain Mastery Program, we definitely get a chat room inside of there for the presentation tonight. Got lots of great questions. You can drop them in there, uh, as we're working through all this type of stuff.

Uh, and again, there's a lot to creating a cryptocurrency trading bot. Um, again, you can take this one off the shelf, do some minor customizations, make it the easy button. But if you want to really get competitive and and create your own strategies, the absolute best way to do that is to get, you know, level up your blockchain development skills. And the best way to do that is with hands-on mentorship. I do have a couple slots opening up for the Blockchain Developer Mentorship. You can see the application to the, uh, that down below.

So anyways, guys, great presentation tonight. I'm so glad everybody could make it. And until next time.