Skip to content

Instantly share code, notes, and snippets.

@ajb413
Last active February 11, 2020 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajb413/4f438c3d6430ddbf9ea1d1a4889c3e5e to your computer and use it in GitHub Desktop.
Save ajb413/4f438c3d6430ddbf9ea1d1a4889c3e5e to your computer and use it in GitHub Desktop.
snippet from my Solidity smart contract
function supplyErc20ToCompound(
address _erc20Contract,
address _cErc20Contract,
uint256 _numTokensToSupply
) public returns (uint) {
// Create a reference to the underlying asset contract, like DAI.
Erc20 underlying = Erc20(_erc20Contract);
// Create a reference to the corresponding cToken contract, like cDAI
CErc20 cToken = CErc20(_cErc20Contract);
// Approve transfer on the ERC20 contract
underlying.approve(_cErc20Contract, _numTokensToSupply);
// Mint cTokens and return the result
uint mintResult = cToken.mint(_numTokensToSupply);
return mintResult;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment