Can I get a contract to vote on proposals via snapshot.js #2949
Replies: 4 comments 8 replies
-
Good question. I'd be interested in hearing about this too |
Beta Was this translation helpful? Give feedback.
-
Yes, the way it work is that a contract can vote if it implement EIP-1271. On Snapshot a vote is a signed message, to verify a vote from a contract we call the function "isValidSignature" from that contract with the hash of the message and the signature. If that function return true then the vote is valid and can be casted / visible on Snapshot. |
Beta Was this translation helpful? Give feedback.
-
@ChaituVR This is my contract with EIP 1271 implemented: This is my core that is using snapshot.org js library <h1>EIP 1271 snaptshot test</h1>
<input type="button" onclick="voteAsync()" value="vote!"></input>
<script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"
type="application/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/@snapshot-labs/snapshot.js"></script>
<script>
async function voteAsync() {
const provider = new ethers.providers.Web3Provider(window.ethereum)
await provider.send("eth_requestAccounts", []);
const signer = provider.getSigner()
const hub = 'https://hub.snapshot.org'; // or https://testnet.snapshot.org for testnet
const client = new snapshot.Client712(hub);
const web3 = provider;
// Smart Contract with EIP 1271 on Optimism
const account = "0xcf9eea9e11f7ad18a14a8670C757f09043A524Bf"
const receipt = await client.vote(web3, account, {
space: 'opcollective.eth',
proposal: '0x88583c43b196ec86cee45345611b582108f1d6933ab688a7cae992a6baa552a6',
type: 'approval-voting',
choice: 1,
reason: 'Choice 1 make lot of sense',
app: 'my-app'
});
}
</script> |
Beta Was this translation helpful? Give feedback.
-
HEJ. JEST TAM KTOS LUDZKI??? PROSZĘ O KONTAKT
niedz., 1 paź 2023, 02:01 użytkownik Ahmed Castro ***@***.***>
napisał:
… @ChaituVR <https://github.com/ChaituVR>
I have the same problem, I implemented EIP 1271 and it doesn't work
This is my contract with EIP 1271 implemented:
https://optimistic.etherscan.io/address/0xcf9eea9e11f7ad18a14a8670C757f09043A524Bf#code
This is my core that is using snapshot.org js library
<h1>EIP 1271 snaptshot test</h1>
<input type="button" onclick="voteAsync()" value="vote!"></input>
<script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"
type="application/javascript"></script>
<script ***@***.***/snapshot.js"></script>
<script>
async function voteAsync() {
const provider = new ethers.providers.Web3Provider(window.ethereum)
await provider.send("eth_requestAccounts", []);
const signer = provider.getSigner()
const hub = 'https://hub.snapshot.org'; // or https://testnet.snapshot.org for testnet
const client = new snapshot.Client712(hub);
const web3 = provider;
// Smart Contract with EIP 1271 on Optimism
const account = "0xcf9eea9e11f7ad18a14a8670C757f09043A524Bf"
const receipt = await client.vote(web3, account, {
space: 'opcollective.eth',
proposal: '0x88583c43b196ec86cee45345611b582108f1d6933ab688a7cae992a6baa552a6',
type: 'approval-voting',
choice: 1,
reason: 'Choice 1 make lot of sense',
app: 'my-app'
});
}
</script>
—
Reply to this email directly, view it on GitHub
<#2949 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUUANJSYIJFQK3JNPMVFY23X5CXFNANCNFSM555TDNYQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I'm a very new solidity developer and I was wondering if it would be possible for a contract to vote on a snapshot proposal. I know that only EOAs can sign transactions, however I wanted to see if there was a suitable work around? (For example am i able to delegate my vote to a contract). Ideally the voting power is taken from this contract rather than the actual user.
Thank you
Beta Was this translation helpful? Give feedback.
All reactions