Last active
August 17, 2021 22:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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