This project is a smart contract that allows you to swap ERC20 tokens using Uniswap V3.
https://sepolia.arbiscan.io/address/0x309cb4897b463a5264e11a6cf13a8a0ecd1f697a#code
Before you begin, ensure you have met the following requirements:
- You have installed the latest version of Node.js and npm.
- You have a Windows/Linux/Mac machine.
- You have read the Uniswap V3 documentation.
To install the Swapping ERC20 Tokens, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/swapping-ERC20.git
-
Navigate to the project directory:
cd swapping-ERC20
-
Install the dependencies:
npm install
To use the Swapping ERC20 Tokens, follow these steps:
Before running the project, you need to configure the environment variables. These variables are used to specify the settings for the Ethereum network and the smart contracts.
Create a .env
file in the root directory of the project and add the following variables:
ROUTER_ADDRESS = "<UniswapV3_Router_Address>" --> "0xE592427A0AEce92De3Edee1F18E0157C05861564"
WETH_ADDRESS = "<WETH_Address>" --> "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
TOKENERC20 = "<TokenERC20_Address>" -->"0x514910771AF9Ca656af840dff83E8264EcF986CA"(LINK Token)
RPC_URL_ARBITRUM = "<Your_Arbitrum_RPC_URL>"
PRIVATE_KEY = "<Your_Private_Key>"
RPC_URL_ARBITRUM
: This is the RPC URL for the Arbitrum network. You can get this URL from Alchemy or Infura.PRIVATE_KEY
: This is the private key of your Ethereum account. Be careful not to share this key with anyone.ROUTER_ADDRESS
: This is the address of the Uniswap V3 Router contract. You can find this address in the Uniswap V3 documentation.WETH_ADDRESS
: This is the address of the WETH contract. You can find this address in the Uniswap V3 documentation.TOKENERC20
: This is the address of the TokenERC20 contract.
Replace <Your_Arbitrum_RPC_URL>
, <Your_Private_Key>
, <UniswapV3_Router_Address>
, <WETH_Address>
and <TokenERC20_Address>
with your actual values.
First, you need to compile the smart contracts. This will check the contracts for errors and prepare them for deployment.
npx hardhat compile
Before deploying the contracts, you need to run a local Ethereum node. We will use Hardhat Network for this, which is a local Ethereum network designed for development.
We will also fork the Ethereum mainnet. This allows us to simulate the state of the mainnet for testing purposes, which is useful for interacting with real smart contracts and replicating live scenarios.
Run the following command to start a local Ethereum node and fork the mainnet:
npx hardhat node --fork https://eth-mainnet.g.alchemy.com/v2/<YOUR_ETHEREUM_MAINNET_APIKEY> --no-deploy
Now you can deploy the contracts to your local Ethereum network. We use the --network localhost option to specify that we want to deploy to our local Ethereum node.
We also use the --tags Swapper option to only deploy the contracts tagged with "Swapper".
Run the following command to deploy the contracts:
npx hardhat deploy --network localhost --tags Swapper
After deploying the contracts, you can run tests against them. We use the --network localhost option to specify that we want to run the tests on our local Ethereum node.
Run the following command to test the contracts:
npx hardhat test --network localhost test/01_swapperTest.ts
Finally, you can interact with the deployed contracts using Hardhat tasks or a web3 library like ethers.js. This allows you to call functions on the contracts and read their state.
To contribute to Swapping ERC20 Tokens, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <branch_name>
. - Make your changes and commit them:
git commit -m '<commit_message>'
- Push to the original branch:
git push origin <project_name>/<location>
- Create the pull request.
This project uses the following license: UNLICENSED.