Vote
When using the Vote smart contract, additional top-level functionality is available to use.
To access the top-level functionality, provide the vote
contract type when creating the contract instance:
const contract = await sdk.getContract(
"{{contract_address}}",
"vote", // Provide the "vote" contract type
);
In addition to the methods listed below, the pack contract supports the following extensions:
balance
Check the balance of the vote contract in the native token of the chain
const balance = await contract.balance();
Configuration
Return Value
{
symbol: string;
value: BigNumber;
name: string;
decimals: number;
displayValue: string;
}
balanceOfToken
Check the balance of the vote contract for a particular token.
const balance = await contract.balanceOfToken("{{token_contract_address}}");
Configuration
canExecute
Check if a proposal can be executed (i.e. the proposal has succeeded).
const canExecute = await contract.canExecute("{{proposal_id}}");
Configuration
execute
Execute the related transactions for a proposal if the proposal succeeded.
const tx = await contract.execute("{{proposal_id}}");
Configuration
get
Get information about a proposal using it’s ID.
const proposal = await contract.get("{{proposal_id}}");
Configuration
proposalId
The ID of the proposal to get information about.
Must be a string
.
Return Value
{
/**
* The unique identifier of the proposal.
*/
proposalId: BigNumber;
/**
* The address of the wallet that created the proposal.
*/
proposer: string;
/**
* The description of the proposal.
*/
description: string;
startBlock: BigNumber;
endBlock: BigNumber;
/**
* The current state of the proposal.
*/
state: {
(Pending = 0),
(Active = 1),
(Canceled = 2),
(Defeated = 3),
(Succeeded = 4),
(Queued = 5),
(Expired = 6),
(Executed = 7);
}
/**
* All votes that have been cast on the proposal.
*/
votes: {
type: {
(Against = 0), (For = 1), (Abstain = 2);
}
label: string;
count: BigNumber;
}
[];
/**
* All executions that have been proposed for the proposal.
*/
executions: {
/**
* The address of the contract that the proposal will execute a transaction on.
* If the proposal is sending a token to a wallet, this address should be the address
* of the wallet that will be receiving the tokens.
*/
toAddress: string;
/**
* The amount of a native token that may be sent if a proposal is executing a token transfer.
*/
nativeTokenValue: BigNumberish;
/**
* The transaction payload that will be executed if the proposal is approved.
*/
transactionData: BytesLike;
}
[];
}
get - Contract Metadata
Get the metadata of a smart contract.
const metadata = await contract.metadata.get();
Configuration
Return Value
While the actual return type is any
, you can expect an object containing
properties that follow the
contract level metadata standards, outlined below:
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}
getAll
Get information about all proposals.
const proposals = await contract.getAll();
Configuration
Return Value
Returns an array of Proposal
objects with the following properties:
{
/**
* The unique identifier of the proposal.
*/
proposalId: BigNumber;
/**
* The address of the wallet that created the proposal.
*/
proposer: string;
/**
* The description of the proposal.
*/
description: string;
startBlock: BigNumber;
endBlock: BigNumber;
/**
* The current state of the proposal.
*/
state: {
(Pending = 0),
(Active = 1),
(Canceled = 2),
(Defeated = 3),
(Succeeded = 4),
(Queued = 5),
(Expired = 6),
(Executed = 7);
}
/**
* All votes that have been cast on the proposal.
*/
votes: {
type: {
(Against = 0), (For = 1), (Abstain = 2);
}
label: string;
count: BigNumber;
}
[];
/**
* All executions that have been proposed for the proposal.
*/
executions: {
/**
* The address of the contract that the proposal will execute a transaction on.
* If the proposal is sending a token to a wallet, this address should be the address
* of the wallet that will be receiving the tokens.
*/
toAddress: string;
/**
* The amount of a native token that may be sent if a proposal is executing a token transfer.
*/
nativeTokenValue: BigNumberish;
/**
* The transaction payload that will be executed if the proposal is approved.
*/
transactionData: BytesLike;
}
[];
}
[];
getProposalVotes
Get all the votes that have been cast on a proposal.
const votes = await contract.getProposalVotes("{{proposal_id}}");
Configuration
hasVoted
Check to see if a wallet has voted on a proposal.
const hasVoted = await contract.hasVoted(
"{{proposal_id}}",
"{{voter_address}}",
);
Configuration
propose
Create a new proposal for token holders to vote on.
// 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 set up in code)
transactionData: tokenContract.encoder.encode("transfer", [
fromAddress,
amount,
]),
},
];
const txResult = await contract.propose(description, executions);
Configuration
description
The description of the proposal you want to pass.
Must be a string
.
executions
An array of ProposableExecution
objects defining what actions will be executed if this proposal passes.
A ProposableExecution
object contains the following properties:
{
/**
* The address of the contract that the proposal will execute a transaction on.
* If the proposal is sending a token to a wallet, this address should be the address
* of the wallet that will be receiving the tokens.
*/
toAddress: string;
/**
* The amount of a native token that may be sent if a proposal is executing a token transfer.
*/
nativeTokenValue: BigNumberish;
/**
* The transaction payload that will be executed if the proposal is approved.
*/
transactionData: BytesLike;
}
set - Contract Metadata
Overwrite the metadata of a contract, an object following the contract level metadata standards.
This operation ignores any existing metadata and replaces it with the new metadata provided.
const txResult = await contract.metadata.set({
name: "My Contract",
description: "My contract description",
});
Configuration
metadata
Provide an object containing the metadata of your smart contract following the contract level metadata standards.
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}
update - Contract Metadata
Update the metadata of your smart contract.
const txResult = await contract.metadata.update({
name: "My Contract",
description: "My contract description",
});
Configuration
metadata
Provide an object containing the metadata of your smart contract following the contract level metadata standards.
New properties will be added, and existing properties will be overwritten. If you do not provide a new value for a previously set property, it will remain unchanged.
Below are the properties you can define on your smart contract.
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}
vote
Vote on an active proposal from the connected wallet.
// Import the VoteType enum, which contains .Against, .For, and .Abstain
import { VoteType } from "@thirdweb-dev/sdk";
// 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);