Skip to content

Instantly share code, notes, and snippets.

@ajb413
Last active August 17, 2021 22:20
Show Gist options
  • Save ajb413/204abca1ab3ed87e187c706e1cd324a8 to your computer and use it in GitHub Desktop.
Save ajb413/204abca1ab3ed87e187c706e1cd324a8 to your computer and use it in GitHub Desktop.
Example to delegate your Compound Governance voting rights on the Ropsten network using web3. https://github.com/compound-developers/compound-governance-examples
compAbi = window.compAbi;
comp = new web3.eth.Contract(compAbi, compAddress);
let currentDelegate;
try {
currentDelegate = await comp.methods.delegates(myAccount).call();
} catch (e) {
currentDelegate = 0;
}
delegate.innerText = currentDelegate == 0 ? 'None' : currentDelegate;
submit.onclick = async () => {
const delegateTo = newDelegate.value;
if (!delegateTo) {
alert('Invalid address to delegate your votes.');
return;
}
loader.classList.remove('hidden');
try {
const tx = await comp.methods.delegate(delegateTo).send({ from: myAccount });
console.log(tx);
alert(`Successfully Delagated to ${delegateTo}`);
window.location.reload();
} catch(e) {
console.error(e);
alert(e.message);
}
loader.classList.add('hidden');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment