Get the value of COMP earned for an address that uses the Compound protocol. This can be done using the Lens contract with JSON RPC or another Smart Contract. If you do an eth_call
with JSON RPC, it is free (no gas costs).
- Use the
getCompBalanceMetadataExt
method in the Lens contract https://etherscan.io/address/0xd513d22422a3062Bd342Ae374b4b9c20E0a9a074#code - Lens address is posted here https://github.com/compound-finance/compound-protocol/blob/master/networks/mainnet.json#L11
- Here is the definition https://github.com/compound-finance/compound-protocol/blob/master/contracts/Lens/CompoundLens.sol#L278
- pass: COMP contract address, Comptroller contract address, and the address you want to know the amount of COMP earned
There is an API endpoint hosted by Compound Labs. This data is slightly behind the blockchain information with respect to time. Use URL parameters to provide the address
that you wish to retrieve the COMP accrued value.
HTTP GET https://api.compound.finance/api/v2/governance/comp/account?address=0x123123123123abcabcabcabcabcab
Use the returned comp_allocated
value in the JSON object response.
Alternatively there is a cool tool from KZen networks that does the same thing. https://github.com/KZen-networks/compound-playground#comp
KZen also created the COMP checker page: https://kzen-networks.github.io/comp-checker/