Created
February 11, 2020 21:53
-
-
Save ajb413/7062f57c5d6a5c9e7e21f42fa2dea1f7 to your computer and use it in GitHub Desktop.
Snippet for supplying ETH to Compound Protocol via Web3.sj
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