Skip to content

Instantly share code, notes, and snippets.

[
{
"address": "0x9687eb285292cba14a60a0c77dfd36dd95b93889",
"support": "In Favor",
"votes": "8500000.00"
}
]
@ajb413
ajb413 / get_all_ballots_web3.js
Last active August 17, 2021 22:16
Get all ballots for a Compound Governance proposal on the Ropsten network using Web3. https://github.com/compound-developers/compound-governance-examples
const governanceAbi = window.governanceAbi;
const gov = new web3.eth.Contract(governanceAbi, governanceAddress);
(async () => {
// Tell the user that we're waiting on a request to return data
ballotListContainer.innerHTML = '<p style="text-align:center;">Fetching ballots...</p>';
const voteCastEvents = await gov.getPastEvents('VoteCast', {
fromBlock: 0,
toBlock: 'latest'
[
{
"against_votes": "601000.00",
"description": "10 BTC is actually a decent amount. Boop!",
"for_votes": "835000.00",
"id": 18,
"title": "Reduce WBTC reserves by 10!",
"state": "succeeded"
}
]
@ajb413
ajb413 / get_all_proposals_api.js
Last active April 17, 2020 22:11
Get all Compound Governance proposals on the Ropsten network using the Compound API's Governance Service. https://github.com/compound-developers/compound-governance-examples
let requestParameters = {
"network": "ropsten", // mainnet, ropsten
"page_size": 100, // integer, defaults to 10
// "proposal_ids": 1, // an integer ID or array of IDs
// "state": "active", // "pending", "active", "canceled", "defeated", "succeeded", "queued", "expired", "executed"
// "with_detail": true, // boolean
// "page_number": 1, // see subsequent response's `pagination_summary` to specify the next page
};
requestParameters = '?' + new URLSearchParams(requestParameters).toString();
[
{
"delegate": "0xb61c5971d9c0472befceffbe662555b78284c307",
"vote_weight": "2.000000%"
}
]
@ajb413
ajb413 / get_delegates_web3.js
Last active August 17, 2021 22:14
Get all COMP token holders on the Ropsten network using the COMP token contract's DelegateVotesChanged event. https://github.com/compound-developers/compound-governance-examples
// Ropsten COMP Contract
const compAddress = '0xf76d4a441e4ba86a923ce32b89aff89dbccaa075';
const compAbi = window.compAbi;
const comp = new web3.eth.Contract(compAbi, compAddress);
(async () => {
// Tell the user that we're waiting on a request to return data
delegateListContainer.innerHTML = '<p style="text-align:center;">Fetching delegates...</p>';
const delegations = await comp.getPastEvents('DelegateVotesChanged', {
@ajb413
ajb413 / get_comp_holders_web3.js
Last active April 17, 2020 22:11
Get all COMP token holders on the Ropsten network using Web3.js. https://github.com/compound-developers/compound-governance-examples
// Ropsten COMP Contract
const compAddress = '0x1fe16de955718cfab7a44605458ab023838c2793';
const compAbi = window.compAbi;
const comp = new web3.eth.Contract(compAbi, compAddress);
(async () => {
const transfers = await comp.getPastEvents('Transfer', {
fromBlock: 0,
toBlock: 'latest'
});
[
{
"address": "0xb61c5971d9c0472befceffbe662555b78284c307",
"balance": "200000.0000",
"delegate": "0xb61c5971d9c0472befceffbe662555b78284c307",
}
]
@ajb413
ajb413 / get_comp_holders_api.js
Last active August 28, 2020 09:29
Get all COMP token holders on the Ropsten network using the Compound API's Governance Service. https://github.com/compound-developers/compound-governance-examples
let requestParameters = {
"page_size": 100, // number of results in a page
"network": "ropsten", // mainnet, ropsten
"order_by": "balance", // "votes", "balance", "proposals_created"
// "page_number": 1, // see subsequent response's `pagination_summary` to specify the next page
// addresses: ['0x123'], // array of addresses to filter on
// with_history: true, // boolean, returns a list of transaction history for the accounts
};
requestParameters = '?' + new URLSearchParams(requestParameters).toString();
@ajb413
ajb413 / output.txt
Created March 19, 2020 21:34
API output example
curl localhost:3000/wallet-balance/eth/
> 100
curl localhost:3000/wallet-balance/ceth/
> 0
curl localhost:3000/supply/eth/5
> OK
curl localhost:3000/protocol-balance/eth/