Skip to content

Instantly share code, notes, and snippets.

Adam Bavosa ajb413

Block or report user

Report or block ajb413

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ajb413
ajb413 / supply-erc20-via-solidity.js
Created Feb 11, 2020
Snippet for supplying DAI to Compound
View supply-erc20-via-solidity.js
// Mint some cDAI by sending DAI to the Compound Protocol
console.log('MyContract is now minting cDAI...');
let supplyResult = await myContract.methods.supplyErc20ToCompound(
daiMainNetAddress,
compoundCDaiContractAddress,
web3.utils.toHex(10e18) // 10 DAI to supply
).send({
from: myWalletAddress,
gasLimit: web3.utils.toHex(5000000), // posted at compound.finance/developers#gas-costs
gasPrice: web3.utils.toHex(20000000000), // use ethgasstation.info (mainnet only)
@ajb413
ajb413 / supply-erc20-via-solidity.js
Last active Feb 16, 2020
Supply DAI to Compound snippet
View supply-erc20-via-solidity.js
console.log('Now transferring DAI from my wallet to MyContract...');
let transferResult = await daiContract.methods.transfer(
myContractAddress,
web3.utils.toHex(10e18) // 10 DAI to send to MyContract
).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)
});
@ajb413
ajb413 / supply-erc20-via-solidity.js
Last active Feb 11, 2020
Supplying DAI to Compound with Web3
View supply-erc20-via-solidity.js
const main = async function() {
let approve = await daiContract.methods.approve(
myContractAddress,
web3.utils.toHex(10e18) // 10 DAI to send to MyContract
).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)
});
@ajb413
ajb413 / supply-eth-via-json-rpc.js
Created Feb 11, 2020
Snippet for supplying ETH to Compound Protocol via Web3.sj
View supply-eth-via-json-rpc.js
// 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
@ajb413
ajb413 / deploy-smart-contracts.js
Created Feb 11, 2020
Deploy smart contract example code with Web3.js
View deploy-smart-contracts.js
myContract.deploy({
data: bytecode
}).send({
from: myWalletAddress,
gas: 5000000
}).then((deployment) => {
console.log('Your contract was successfully deployed!');
console.log('The contract can be interfaced with at this address:');
console.log(deployment.options.address);
}).catch((err) => {
@ajb413
ajb413 / supply-erc20-via-json-rpc.js
Created Feb 11, 2020
Supply ERC20 to Compound with Web3.js
View supply-erc20-via-json-rpc.js
// Tell DAI contract to allow 10 DAI to be taken by Compound's contract
daiContract.methods.approve(compoundCDaiContractAddress, web3.utils.toBN(10e18))
.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)
}).then((result) => {
console.log('DAI contract "Approve" operation successful.');
console.log('Sending DAI to the Compound Protocol...');
// Mint cDAI by supplying DAI to the Compound Protocol
@ajb413
ajb413 / mint-testnet-dai.js
Created Feb 11, 2020
Minting test DAI snippet
View mint-testnet-dai.js
let daiContract;
let accounts;
web3.eth.getAccounts().then((ganacheAccounts) => {
accounts = ganacheAccounts;
daiContract = new web3.eth.Contract(daiAbi, daiMainNetAddress);
// 500 DAI
const numbDaiToMint = web3.utils.toWei('500', 'ether');
@ajb413
ajb413 / supply-eth-via-json-rpc.js
Created Feb 11, 2020
Snippet for supplying ETH to the Compound Protocol with Web3.js
View supply-eth-via-json-rpc.js
// 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
@ajb413
ajb413 / MyContract.sol
Last active Feb 11, 2020
snippet from my Solidity smart contract
View MyContract.sol
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);
@ajb413
ajb413 / MyContract.sol
Created Feb 11, 2020
snippet of a Solidity smart contract file
View MyContract.sol
contract Erc20 {
function approve(address, uint) external returns (bool);
function transfer(address, uint) external returns (bool);
}
contract CErc20 {
function mint(uint) external returns (uint);
}
You can’t perform that action at this time.