2

I am trying to implement a Ropsten Testnet swap via contract. This contract swaps Testnet DAI for a token I have created. Liquidity is added and swapping via the UI works.

IUniswapV2Router02 private router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
Token public token; //address passed via constructor 
ERC20 public stablecoin = ERC20(0xaD6D458402F60fD3Bd25163575031ACDce07538D); //DAI 
address[] paths = [address(stablecoin), address(token)]; 

unction swapper (uint buyValue, uint minAmount, uint time) public {
        require(msg.sender==owner, "only contract owner");
        router.swapExactTokensForTokens(buyValue, minAmount, paths, address(this), time);
    }

When I run the swapper function, it returns Fail with error 'UniswapV2Library: ZERO_ADDRESS'. What is wrong?

1 Answer 1

0

You need to build the paths like this for some reason

cvxPath = new address[](2);
cvxPath[0] = address(stablecoin);
cvxPath[1] = address(token);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.