This code is snippet from a smart contract, In the code below:

  1. who is approving whom and whose funds are cDai allowed to transfer within the given _amount?

  2. what is dai.approve doing?

  3. If contract is depositing funds to compound, why I should use approve cDai?

     function _depositToCompound(uint256 _amount) internal returns (uint256) {
     require(dai.approve(address(cDai), _amount));
     uint256 result = cDai.mint(_amount);
     return result;

1 Answer 1


The approve function approves usage of the token to be transferred given the _amount.

  1. The wallet that calls the function is approving the DAI contract to use _amount from the wallet.

  2. dai.approve uses the approve function which takes in two parameters, spender and amount.

  3. Your contract is using cDai to run a mint function, which I assume you're depositing cDai.

You can read more on approval here.

Your Answer

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

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