Getting Started with the Compound Protocol

Compound is an open-source protocol for Money Markets on the Ethereum blockchain; interest rates are determined algorithmically based based on the supply and demand for ERC-20 tokens, allowing users to seamlessly earn interest or borrow ERC-20 tokens without managing an order book.

This guide contains instructions for interacting with the Compound protocol using MyEtherWallet, and is intended for users familiar with Ethereum smart contracts.

Contracts, ABI, and Interface

Smart contract addresses, contract ABIs, and a visual interface to the protocol are available at compound.finance/alpha; start by opening this in a new tab.

An example of Compound Money Markets available for you to test

Test Network

Compound is currently running on a testnet, Rinkeby, which behaves similarly to the Ethereum blockchain, except that it’s a safe sandbox environment; do not send Ether or tokens on the Ethereum main-net or you will lose your assets.

Before using the Compound protocol, carefully read The Beginners Guide to Using an Ethereum Test Network, and ensure that you have a small supply of Rinkeby Ether.

1. Acquiring testnet Tokens

In order to test the Compound protocol, we’ve created faucets for popular tokens, which are listed in our table of deployed contracts on compound.finance/alpha.

Visit https://www.myetherwallet.com/#contracts and:

  • Enter the Contract Address of a faucet token you’d like to receive, such as BAT (e.g. 0x11ce67f3153a7a22b17d43b8405d30d46e1dda44 or whatever is listed on /alpha)
  • Copy and paste the the JSON ABI for FaucetToken from the deployed contracts table
  • Click Access and scroll down to the section labeled Read / Write Contract
  • Select the allocate function, and submit the transaction. You’ll receive approximately an Ether worth of the token (but don’t get too excited, these are testnet tokens)
Adding a balance of FaucetToken

2. Supplying Tokens to a Money Market

There are only two transactions required to supply a token to a Compound money market to earn interest.

Approve the use of your token

First, we have to approve the MoneyMarket to use our token. Visit https://www.myetherwallet.com/#contracts and:

  • Enter the Contract Address of the token you’d like to supply
  • Copy and paste the the JSON ABI for FaucetToken from the deployed contracts table
  • Click Access and scroll down to the section labeled Read / Write Contract
  • Select the approve function
  • Paste the MoneyMarket address in _spender, and your quantity of tokens in _value (add 18 zeros), and submit the transaction
Approve the MoneyMarket to use your token

Supply Tokens to the Money Market

Next, we supply the token to the money market. Visit https://www.myetherwallet.com/#contracts and:

  • Enter the Contract Address of the MoneyMarket
  • Copy and paste the the JSON ABI for MoneyMarket from the deployed contracts table
  • Click Access and scroll down to the section labeled Read / Write Contract
  • Select the customerSupply function
  • Paste the token address in asset, and your quantity of tokens in amount (add 18 zeros), and submit the transaction
Enter the asset, and amount that you’d like to supply

Once the transaction has been completed successfully, go back to the contract in MyEtherWallet and choose the function getSupplyBalance. Enter your address and the asset address in the fields and click “Read.” This should show you the balance you entered. Be sure to come back in a day or two, and watch as you begin to accrue interest.

3. Borrowing Tokens

Compound allows interested parties to borrow tokens given sufficient collateral of other tokens. For example, if you hold a large amount of OMG tokens, but want to have ether to invest in an ICO, you can hold your OMG tokens in the Compound Money Market as collateral, and Compound will lend you ether for your investment. Small amounts of interest will accrue on your borrowed assets until the total amount is repaid.

To borrow assets, first make sure to have a balance of assets in the Compound Money Market. The Compound Money Market values all assets in your account and lets you borrow an amount that is up to half of the value of your assets. For example, if you hold 100 OMG tokens and OMG tokens are worth 0.02 Ether, your account would have a value of 2 Ether. You would be allowed to borrow 1 Ether or the equivalent in other tokens of 1 Ether. Note: if your collateral becomes less than the value of your borrow, the protocol will convert some of your collateral to the borrowed asset at market rates to de-risk your account.

To borrow an asset, you will first need to determine the value of your supplied capital assets. From the Money Market contract page in MyEtherWallet, choose “getMaxBorrowAvailable,” and enter your account address. Select “Read” to view the maximum allowed loan in Ether-equivalents (that is, with all assets valued in Ether at market rates from the PriceOracle contract). Take note of this number.

Viewing the Ether value equivalent of your account balance.

To borrow an asset, let’s say Ether, choose “customerBorrow.” Choose an asset, in this case, the address of the Wrapped Ether Token contract above. Enter an amount that is less than or equal to the max loan balance noted above. Note: if your transaction fails, it is likely due to hold insufficient collateral. You should provide at least a 10% margin in borrowing due to the natural fluctuation of ERC-20 token prices. Execute the transaction and verify that it completed successfully in Etherscan.

Borrowing Wrapped Ether Token. Note: addresses may vary.

Finally, you should now be able to verify your updated balances. If you run “getSupplyBalance,” for the borrowed token, you should see a positive balance. If you run “getBorrowBalance,” for the borrowed token, you should also see a positive (owed) balance. You should note: the balance is available to you in the Money Market but has not yet been made available to your personal account. You should follow the steps to withdraw a capital balance in the section above.

4. Withdrawing Assets

After borrowing an asset, or earning interest, you might want to withdraw your assets held in the Compound protocol to a wallet or your favorite exchange. Visit https://www.myetherwallet.com/#contracts and:

  • Enter the Contract Address of the MoneyMarket
  • Copy and paste the the JSON ABI for MoneyMarket from the deployed contracts table
  • Click Access and scroll down to the section labeled Read / Write Contract
  • Select the customerWithdraw function
  • Paste the token address in asset, and your quantity of tokens in amount (add 18 zeros), and the recipient in to, and submit the transaction
Specify the asset, amount, and destination

5. Repaying a Borrowed Asset

Finally, once you’ve utilized your borrowed asset and wish to repay that asset, view the Money Market contract on MyEtherWallet as above. Choose “customerPayBorrow,” choose the asset and the amount to repay. Your borrowed asset may have accrued interest since it was borrowed and thus you should make sure you repay the current balance of the loan.

For the community, by the community

Compound is built for you and the Ethereum community. All of our code and smart contracts are open-source on GitHub; we’d love to hear your thoughts, suggestions and ideas by visiting us in Discord.