9

调用薄饼合约换币失败

 2 years ago
source link: https://learnblockchain.cn/question/3047
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

调用薄饼合约换币失败 | 登链社区 | 技术问答

调用薄饼合约换币失败

pragma solidity 0.6.6;
import "https://github.com/Uniswap/v2-periphery/blob/master/contracts/UniswapV2Router01.sol";
contract owned {
    address public owner;

    constructor () public{
        owner = msg.sender;
    }
    modifier onlyOwner {
        require (msg.sender == owner);
        _;
    }
}
interface TetherToken {
    function balanceOf(address who) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transfer(address to, uint256 value) external returns (bool);
    function transferFrom(address _from, address _to, uint256 _value) external returns (bool);
}
 
contract Bhe is owned{
    address router_address = 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 ;
    UniswapV2Router01 public uniswapRouter;
    address wp = 0x22bd6B32F007410A78B2F31AF1a59eE74193956c;
    address dog = 0x5257C1F1804605218b4b46851F5488bf278524F2;
    TetherToken public c_wp = TetherToken(wp);  //U
    constructor() public{
        uniswapRouter = UniswapV2Router01(0xD99D1c33F9fC3444f8101754aBC46c52416550D1);
    }
    function inside(uint _usdt) public returns(uint[] memory){
        uint deadline = block.timestamp + 15;
        c_wp.approve(router_address, _usdt);
        return uniswapRouter.swapExactTokensForTokens(_usdt, 0, getPath(),address(this),deadline);  
    }
    function getPath() private view returns (address[] memory) {
        address[] memory path = new address[](2);
        path[0] = wp;
        path[1] = dog;
        return path;
    } 
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK