Skip to content

Instantly share code, notes, and snippets.

@ajb413
Created February 11, 2020 21:53
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/7062f57c5d6a5c9e7e21f42fa2dea1f7 to your computer and use it in GitHub Desktop.
Save ajb413/7062f57c5d6a5c9e7e21f42fa2dea1f7 to your computer and use it in GitHub Desktop.
Snippet for supplying ETH to Compound Protocol via Web3.sj
// Mint some cETH by supplying ETH to the Compound Protocol
console.log('Sending ETH to the Compound Protocol...');
compoundCEthContract.methods.mint().send({
from: myWalletAddress,
gasLimit: web3.utils.toHex(150000), // posted at compound.finance/developers#gas-costs
gasPrice: web3.utils.toHex(20000000000), // use ethgasstation.info (mainnet only)
value: web3.utils.toHex(web3.utils.toWei('1', 'ether'))
}).then((result) => {
console.log('cETH "Mint" operation successful.');
return compoundCEthContract.methods
.balanceOfUnderlying(myWalletAddress).call();
}).then((balanceOfUnderlying) => {
balanceOfUnderlying = web3.utils.fromWei(balanceOfUnderlying).toString();
console.log("ETH supplied to the Compound Protocol:", balanceOfUnderlying);
return compoundCEthContract.methods.balanceOf(myWalletAddress).call();
}).then((cTokenBalance) => {
cTokenBalance = (cTokenBalance / 1e8).toString();
console.log("My wallet's cETH Token Balance:", cTokenBalance);
}).catch((error) => {
console.error(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment