Vote
Learn how to interact with your Vote contract in the SDK.
Create a Vote Contract
- React
- Javascript
- Python
- Go
const sdk = useSDK();
const contractAddress = await sdk.deployer.deployVote({
name: "My Vote",
primary_sale_recipient: "your-address",
voting_token_address: "your-token-contract-address",
});
const contractAddress = await sdk.deployer.deployVote({
name: "My Vote",
primary_sale_recipient: "your-address",
voting_token_address: "your-token-contract-address",
});
Python SDK support for deployVote is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for deployVote is coming soon.
Want this feature sooner? Let us know in Discord!
Getting the contract in your application
To start using your Vote contract inside your application, you'll need to use its contract address. You can get the contract address from the dashboard.
- React
- Javascript
- Python
- Go
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
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("{{chainName}}");
const contract = sdk.getVote("{{contract_address}}");
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
- React
- Javascript
- 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);
// 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);
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.
- React
- Javascript
- Python
- Go
const proposals = await contract.getAll();
console.log(proposals);
const proposals = await contract.getAll();
console.log(proposals);
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 on a specific proposal.
- React
- Javascript
- 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);
// 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);
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!
Vote on a Proposal
- React
- Javascript
- 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);
// 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);
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!
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.
- React
- Javascript
- Python
- Go
// The proposal ID of the proposal you want to check
const proposalId = "0";
const canExecute = await contract.canExecute(proposalId);
console.log(canExecute);
// The proposal ID of the proposal you want to check
const proposalId = "0";
const canExecute = await contract.canExecute(proposalId);
console.log(canExecute);
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.
- React
- Javascript
- Python
- Go
// The proposal ID ofthe proposal you want to execute
const proposalId = "0"
await contract.execute(proposalId);
// The proposal ID ofthe proposal you want to execute
const proposalId = "0"
await contract.execute(proposalId);
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!