Vote
The Vote contract is designed for groups such as DAO's to vote on proposals.
In order to use the Vote contract, you also need to have an existing ERC-20 token,
such as our Token Contract to act as the governance token
.
You could use the Vote contract to:
- Vote to decide on organizational changes
- Vote on managing and distributing funds in a treasury
- Vote on any other proposal in an organization, such as a DAO
Create a Vote Contract
Using the dashboard
Learn how to create any of thirdweb's pre-built contracts in the Deploying Contracts page.
Getting the contract in your application
To start using your Vote contract inside your application, you'll need to use it's contract address. You can get the contract address from the dashboard.
- Javascript
- React
- Python
- Go
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("rinkeby");
const contract = sdk.getVote("{{contract_address}}");
import { useVote } from '@thirdweb-dev/react'
export default function Component() {
const vote = useVote("<YOUR-CONTRACT-ADDRESS>")
// Now you can use the vote contract in the rest of the component
}
Python SDK support for initializing the SDK is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for initializing the SDK is coming soon.
Want this feature sooner? Let us know in Discord!
Creating A Proposal
Using the dashboard
Using the SDK
- Javascript
- React
- Python
- Go
// The description of the proposal you want to pass
const description = "This is a great proposal - vote for it!"
// You can (optionally) pass in contract calls that will get executed when the proposal is executed.
const executions = [
{
// The contract you want to make a call to
toAddress: "0x...",
// The amount of the native currency to send in this transaction
nativeTokenValue: 0,
// Transaction data that will be executed when the proposal is executed
// This is an example transfer transaction with a token contract (which you would need to setup in code)
transactionData: tokenContract.encoder.encode(
"transfer", [
fromAddress,
amount,
]
),
}
]
const proposal = await contract.propose(description, executions);
React SDK support for propose is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for propose is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for propose is coming soon.
Want this feature sooner? Let us know in Discord!
Viewing Proposals
View all of the proposals that have been created in this Vote smart contract.
- Javascript
- React
- Python
- Go
const proposals = await contract.getAll();
console.log(proposals);
React SDK support for getAll is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for getAll is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for getAll is coming soon.
Want this feature sooner? Let us know in Discord!
Check if a wallet has voted
Check if a wallet address has voted in a specific proposal.
- Javascript
- React
- Python
- Go
// The proposal ID of the proposal you want to check
const proposalId = "0";
// The address of the wallet you want to check to see if they voted
const address = "{{wallet_address}}";
await contract.hasVoted(proposalId, address);
React SDK support for hasVoted is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for hasVoted is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for hasVoted is coming soon.
Want this feature sooner? Let us know in Discord!
Execute A Proposal
Check if a proposal can be executed
Check to see if the amount of votes required for the proposal to be executed has been met
- Javascript
- React
- Python
- Go
// The proposal ID of the proposal you want to check
const proposalId = "0";
const canExecute = await contract.canExecute(proposalId);
console.log(canExecute);
React SDK support for canExecute is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for canExecute is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for canExecute is coming soon.
Want this feature sooner? Let us know in Discord!
Execute a proposal
Execute a proposal that has a sufficient amount of votes.
- Javascript
- React
- Python
- Go
// The proposal ID ofthe proposal you want to execute
const proposalId = "0"
await contract.execute(proposalId);
React SDK support for execute is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for execute is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for execute is coming soon.
Want this feature sooner? Let us know in Discord!
Vote on a Proposal
- Javascript
- React
- Python
- Go
// The proposal ID of the proposal you want to vote on
const proposalId = "0";
// The vote type you want to cast, can be VoteType.Against, VoteType.For, or VoteType.Abstain
const voteType = VoteType.For;
// The (optional) reason for the vote
const reason = "I like this proposal!";
await contract.vote(proposalId, voteType, reason);
React SDK support for vote is coming soon.
Want this feature sooner? Let us know in Discord!
Python SDK support for vote is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for vote is coming soon.
Want this feature sooner? Let us know in Discord!