Contract 0xfeea0d87233be9a8261a335e55dcccbc90276af3

Contract Overview

Balance:
0 BNB
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x45e85ad673afda7f4f920824952959d9b868505fcb7333ba3f7c08dea7267ae10x6080604085482842021-05-04 13:36:38143 days 13 hrs ago0x014c0018db28b08e17066a826a0701517dfb653f IN  Contract Creation0 BNB0.02044916
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Similar Match)
Note: This contract matches the deployed ByteCode of the Source Code for Contract 0xb7e991182091a3aa143c88ba1af43628fc83660b

Contract Name:
tokenSwap

Compiler Version
v0.8.0+commit.c7dfd78e

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 1 : swap.sol
pragma solidity ^0.8.0;


//import the ERC20 interface

interface IERC20 {
    function totalSupply() external view returns (uint);
    function balanceOf(address account) external view returns (uint);
    function transfer(address recipient, uint amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint);
    function approve(address spender, uint amount) external returns (bool);
    function transferFrom(
        address sender,
        address recipient,
        uint amount
    ) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
}


//import the uniswap router
//the contract needs to use swapExactTokensForTokens
//this will allow us to import swapExactTokensForTokens into our contract

interface IUniswapV2Router {
  function getAmountsOut(uint256 amountIn, address[] memory path)
    external
    view
    returns (uint256[] memory amounts);
  
  function swapExactTokensForTokens(
  
    //amount of tokens we are sending in
    uint256 amountIn,
    //the minimum amount of tokens we want out of the trade
    uint256 amountOutMin,
    //list of token addresses we are going to trade in.  this is necessary to calculate amounts
    address[] calldata path,
    //this is the address we are going to send the output tokens to
    address to,
    //the last time that the trade is valid for
    uint256 deadline
  ) external returns (uint256[] memory amounts);
}

interface IUniswapV2Pair {
  function token0() external view returns (address);
  function token1() external view returns (address);
  function swap(
    uint256 amount0Out,
    uint256 amount1Out,
    address to,
    bytes calldata data
  ) external;
}

interface IUniswapV2Factory {
  function getPair(address token0, address token1) external returns (address);
}



contract tokenSwap {
    
    //address of the uniswap v2 router
    address private constant UNISWAP_V2_ROUTER = 0xD99D1c33F9fC3444f8101754aBC46c52416550D1;
    
    //address of WETH token.  This is needed because some times it is better to trade through WETH.  
    //you might get a better price using WETH.  
    //example trading from token A to WETH then WETH to token B might result in a better price
    address private constant WETH = 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd;
    

    //this swap function is used to trade from one token to another
    //the inputs are self explainatory
    //token in = the token address you want to trade out of
    //token out = the token address you want as the output of this trade
    //amount in = the amount of tokens you are sending in
    //amount out Min = the minimum amount of tokens you want out of the trade
    //to = the address you want the tokens to be sent to
    
   function swap(address _tokenIn, address _tokenOut, uint256 _amountIn, uint256 _amountOutMin, address _to) external {
      
    //first we need to transfer the amount in tokens from the msg.sender to this contract
    //this contract will have the amount of in tokens
    IERC20(_tokenIn).transferFrom(msg.sender, address(this), _amountIn);
    
    //next we need to allow the uniswapv2 router to spend the token we just sent to this contract
    //by calling IERC20 approve you allow the uniswap contract to spend the tokens in this contract 
    IERC20(_tokenIn).approve(UNISWAP_V2_ROUTER, _amountIn);

    //path is an array of addresses.
    //this path array will have 3 addresses [tokenIn, WETH, tokenOut]
    //the if statement below takes into account if token in or token out is WETH.  then the path is only 2 addresses
    address[] memory path;
    if (_tokenIn == WETH || _tokenOut == WETH) {
      path = new address[](2);
      path[0] = _tokenIn;
      path[1] = _tokenOut;
    } else {
      path = new address[](3);
      path[0] = _tokenIn;
      path[1] = WETH;
      path[2] = _tokenOut;
    }
        //then we will call swapExactTokensForTokens
        //for the deadline we will pass in block.timestamp
        //the deadline is the latest time the trade is valid for
        IUniswapV2Router(UNISWAP_V2_ROUTER).swapExactTokensForTokens(_amountIn, _amountOutMin, path, _to, block.timestamp);
    }

    function testContract(uint256 input) external pure returns (uint256) {
      return input + 1;
    }
    
       //this function will return the minimum amount from a swap
       //input the 3 parameters below and it will return the minimum amount out
       //this is needed for the swap function above
     function getAmountOutMin(address _tokenIn, address _tokenOut, uint256 _amountIn) external view returns (uint256) {

       //path is an array of addresses.
       //this path array will have 3 addresses [tokenIn, WETH, tokenOut]
       //the if statement below takes into account if token in or token out is WETH.  then the path is only 2 addresses
        address[] memory path;
        if (_tokenIn == WETH || _tokenOut == WETH) {
            path = new address[](2);
            path[0] = _tokenIn;
            path[1] = _tokenOut;
        } else {
            path = new address[](3);
            path[0] = _tokenIn;
            path[1] = WETH;
            path[2] = _tokenOut;
        }
        
        uint256[] memory amountOutMins = IUniswapV2Router(UNISWAP_V2_ROUTER).getAmountsOut(_amountIn, path);
        return amountOutMins[path.length -1];
    
    }
    
}

Settings
{
  "remappings": [],
  "optimizer": {
    "enabled": false,
    "runs": 200
  },
  "evmVersion": "istanbul",
  "libraries": {},
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_tokenIn","type":"address"},{"internalType":"address","name":"_tokenOut","type":"address"},{"internalType":"uint256","name":"_amountIn","type":"uint256"}],"name":"getAmountOutMin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenIn","type":"address"},{"internalType":"address","name":"_tokenOut","type":"address"},{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"uint256","name":"_amountOutMin","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"input","type":"uint256"}],"name":"testContract","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]

608060405234801561001057600080fd5b506111a4806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80631714b0c5146100465780633c50eec114610076578063d5bcb9b5146100a6575b600080fd5b610060600480360381019061005b9190610d92565b6100c2565b60405161006d9190610ebe565b60405180910390f35b610090600480360381019061008b9190610c62565b6100d8565b60405161009d9190610ebe565b60405180910390f35b6100c060048036038101906100bb9190610cb1565b6105b6565b005b60006001826100d19190610ff9565b9050919050565b6000606073ae13d989dac2f0debff460ac112a837c89baa7cd73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161480610169575073ae13d989dac2f0debff460ac112a837c89baa7cd73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16145b156102cf57600267ffffffffffffffff8111156101af577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280602002602001820160405280156101dd5781602001602082028036833780820191505090505b509050848160008151811061021b577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508381600181518110610290577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250506104b5565b600367ffffffffffffffff811115610310577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405190808252806020026020018201604052801561033e5781602001602082028036833780820191505090505b509050848160008151811061037c577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505073ae13d989dac2f0debff460ac112a837c89baa7cd81600181518110610405577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050838160028151811061047a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505b600073d99d1c33f9fc3444f8101754abc46c52416550d173ffffffffffffffffffffffffffffffffffffffff1663d06ca61f85846040518363ffffffff1660e01b8152600401610506929190610ed9565b60006040518083038186803b15801561051e57600080fd5b505afa158015610532573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061055b9190610d28565b9050806001835161056c919061104f565b815181106105a3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010151925050509392505050565b8473ffffffffffffffffffffffffffffffffffffffff166323b872dd3330866040518463ffffffff1660e01b81526004016105f393929190610e5e565b602060405180830381600087803b15801561060d57600080fd5b505af1158015610621573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106459190610d69565b508473ffffffffffffffffffffffffffffffffffffffff1663095ea7b373d99d1c33f9fc3444f8101754abc46c52416550d1856040518363ffffffff1660e01b8152600401610695929190610e95565b602060405180830381600087803b1580156106af57600080fd5b505af11580156106c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e79190610d69565b50606073ae13d989dac2f0debff460ac112a837c89baa7cd73ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161480610777575073ae13d989dac2f0debff460ac112a837c89baa7cd73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16145b156108dd57600267ffffffffffffffff8111156107bd577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280602002602001820160405280156107eb5781602001602082028036833780820191505090505b5090508581600081518110610829577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050848160018151811061089e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050610ac3565b600367ffffffffffffffff81111561091e577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405190808252806020026020018201604052801561094c5781602001602082028036833780820191505090505b509050858160008151811061098a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505073ae13d989dac2f0debff460ac112a837c89baa7cd81600181518110610a13577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508481600281518110610a88577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505b73d99d1c33f9fc3444f8101754abc46c52416550d173ffffffffffffffffffffffffffffffffffffffff166338ed173985858486426040518663ffffffff1660e01b8152600401610b18959493929190610f09565b600060405180830381600087803b158015610b3257600080fd5b505af1158015610b46573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190610b6f9190610d28565b50505050505050565b6000610b8b610b8684610f94565b610f63565b90508083825260208201905082856020860282011115610baa57600080fd5b60005b85811015610bda5781610bc08882610c4d565b845260208401935060208301925050600181019050610bad565b5050509392505050565b600081359050610bf381611129565b92915050565b600082601f830112610c0a57600080fd5b8151610c1a848260208601610b78565b91505092915050565b600081519050610c3281611140565b92915050565b600081359050610c4781611157565b92915050565b600081519050610c5c81611157565b92915050565b600080600060608486031215610c7757600080fd5b6000610c8586828701610be4565b9350506020610c9686828701610be4565b9250506040610ca786828701610c38565b9150509250925092565b600080600080600060a08688031215610cc957600080fd5b6000610cd788828901610be4565b9550506020610ce888828901610be4565b9450506040610cf988828901610c38565b9350506060610d0a88828901610c38565b9250506080610d1b88828901610be4565b9150509295509295909350565b600060208284031215610d3a57600080fd5b600082015167ffffffffffffffff811115610d5457600080fd5b610d6084828501610bf9565b91505092915050565b600060208284031215610d7b57600080fd5b6000610d8984828501610c23565b91505092915050565b600060208284031215610da457600080fd5b6000610db284828501610c38565b91505092915050565b6000610dc78383610dd3565b60208301905092915050565b610ddc81611083565b82525050565b610deb81611083565b82525050565b6000610dfc82610fd0565b610e068185610fe8565b9350610e1183610fc0565b8060005b83811015610e42578151610e298882610dbb565b9750610e3483610fdb565b925050600181019050610e15565b5085935050505092915050565b610e58816110c1565b82525050565b6000606082019050610e736000830186610de2565b610e806020830185610de2565b610e8d6040830184610e4f565b949350505050565b6000604082019050610eaa6000830185610de2565b610eb76020830184610e4f565b9392505050565b6000602082019050610ed36000830184610e4f565b92915050565b6000604082019050610eee6000830185610e4f565b8181036020830152610f008184610df1565b90509392505050565b600060a082019050610f1e6000830188610e4f565b610f2b6020830187610e4f565b8181036040830152610f3d8186610df1565b9050610f4c6060830185610de2565b610f596080830184610e4f565b9695505050505050565b6000604051905081810181811067ffffffffffffffff82111715610f8a57610f896110fa565b5b8060405250919050565b600067ffffffffffffffff821115610faf57610fae6110fa565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b6000611004826110c1565b915061100f836110c1565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115611044576110436110cb565b5b828201905092915050565b600061105a826110c1565b9150611065836110c1565b925082821015611078576110776110cb565b5b828203905092915050565b600061108e826110a1565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61113281611083565b811461113d57600080fd5b50565b61114981611095565b811461115457600080fd5b50565b611160816110c1565b811461116b57600080fd5b5056fea264697066735822122087a0c39bd3cd44d593345c3f2b4ed5105f636d90c692d71b0ca88a7d61c506d664736f6c63430008000033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading