Created
February 11, 2020 21:13
-
-
Save ajb413/3524d5c619005b84339452d6f9d4244e to your computer and use it in GitHub Desktop.
Snippet for supplying ETH to the Compound Protocol with Web3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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