The error I get when trying to make ethertoDai() run is:

{ "message": "VM Exception while processing transaction: revert", "code": -32000, "data": { "stack": "o: VM Exception while processing transaction: revert\n at Function.o.fromResults (/app/ganache-core.docker.cli.js:6:120966)\n at e.exports (/app/ganache-core.docker.cli.js:41:2269990)", "name": "o" } }

/// @title Kyber Network interface
interface KyberNetworkProxyInterface {
    function maxGasPrice() public view returns(uint);
    function getUserCapInWei(address user) public view returns(uint);
    function getUserCapInTokenWei(address user, ERC20 token) public view returns(uint);
    function enabled() public view returns(bool);
    function info(bytes32 id) public view returns(uint);

    function getExpectedRate(ERC20 src, ERC20 dest, uint srcQty) public view
        returns (uint expectedRate, uint slippageRate);

    function tradeWithHint(ERC20 src, uint srcAmount, ERC20 dest, address destAddress, uint maxDestAmount,
        uint minConversionRate, address walletId, bytes memory hint) public payable returns(uint);

    function swapEtherToToken(ERC20 token, uint minRate) public payable returns (uint);

    function swapTokenToEther(ERC20 token, uint tokenQty, uint minRate) public returns (uint);

contract Playground {

    address public daiAddress = 0x6b175474e89094c44da98b954eedeac495271d0f;
    address public kyberAddress = 0x818E6FECD516Ecc3849DAf6845e3EC868087B755;
    address private ETH_ADDRESS = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee; 
    address public UniDaiAddress = 0x2a1530C4C41db0B0b2bB646CB5Eb1A67b7158667;



    function etherToDai(uint256 quantity) payable returns (uint256) { // Buy DAI on the KyberNet
        KyberNetworkProxyInterface KNPI = KyberNetworkProxyInterface(daiAddress);
        uint256 expectedRate;
        uint256 slippageRate;
        ERC20 daiToken = ERC20(daiAddress);
        (expectedRate, slippageRate) = KNPI.getExpectedRate(ERC20(ETH_ADDRESS), daiToken, quantity);
        uint256 received = KNPI.swapEtherToToken.value(quantity)(ERC20(daiAddress), slippageRate);
        require(daiToken.transfer(msg.sender, received));
        return received;

    function () external payable  {


What is the problem, and how am I supposed to debug an error like this?

  • How do you call this function? – goodvibration Sep 28 at 5:45
  • Please share the code of KyberNetworkProxyInterface. – goodvibration Sep 28 at 5:46
  • I tried to run it in the Remix tool after deployment (on mainnet fork) – Raven Sep 28 at 5:46
  • Nevertheless, how do you call it (what input parameters do you pass)? – goodvibration Sep 28 at 5:47
  • updated - I only pass "quantity" (uint265) – Raven Sep 28 at 5:48

To begin with, given:

address public daiAddress = 0x6b175474e89094c44da98b954eedeac495271d0f;
address public kyberAddress = 0x818E6FECD516Ecc3849DAf6845e3EC868087B755;

You should probably change this:

KyberNetworkProxyInterface KNPI = KyberNetworkProxyInterface(daiAddress);

To this:

KyberNetworkProxyInterface KNPI = KyberNetworkProxyInterface(kyberAddress);

As it's not really clear why you are converting the ERC20 DAI token into a Kyber-Network proxy.

Another problem seems to be in:

uint256 received = KNPI.swapEtherToToken.value(quantity)(ERC20(daiAddress), slippageRate);

Where the second input argument should probably be expectedRate rather than slippageRate.

Another potential problem is the fact that your contract must own at least quantity wei ether.

One way to ensure this is by passing that value when you call the function.

And by "passing that value", I don't mean as an input parameter to the function, but as a value to the transaction.

Note that for consistency, the Kyber contract might be requiring that you also pass it as an input parameter to the function.

| improve this answer | |
  • I'm able to get the output of { "0": "uint256: expectedRate 320076140761407614076", "1": "uint256: slippageRate 310473856538565385653" } with this change, however, when I uncomment the last 3 lines I get the same error. I'm trying to convert my ETH into DAI over Kyber – Raven Sep 28 at 6:13
  • @Raven: See updated answer. – goodvibration Sep 28 at 6:16
  • I made that change, but I still get the same cryptic error =( – Raven Sep 28 at 6:24
  • @Raven: See updated answer. – goodvibration Sep 28 at 6:52
  • By passing a value, do you mean replacing quantity with "msg.value", and then change my function to function etherToDai() payable returns (uint256) ? Now, it won't let me chose how much ether I want to send, and it only pays gas. And it still fails with the same error. – Raven Sep 28 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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