hedsvote
v0.1.135
Published
This SDK provides a simple interface for interacting with the Heds Voting System. It includes functions for interacting with proposals, casting and updating votes, and calculating user voting power.
Downloads
84
Readme
Heds Voting SDK
This SDK provides a simple interface for interacting with the Heds Voting System. It includes functions for interacting with proposals, casting and updating votes, and calculating user voting power.
Installation
npm install heds-voting-sdk
Usage
Import the SDK and create a client:
import { createClient, calculateUserVotingPower, VoteMethod, ProposalState } from 'heds-voting-sdk';
const client = createClient();
Signer
Signer The signer is an object that holds the user's private key and is used to sign messages for certain actions like creating or deleting proposals, casting, and updating votes. You can use a library like ethers.js to create a signer from a private key or a JSON-RPC provider.
Example:
Interacting with Proposals
Get all proposals
Get a single proposal
Create a new proposal
Delete a proposal
Casting and Updating Votes
Cast a vote
const voteObject: VoteObject = {
proposalId: 'proposal-id',
spaceId: 'your-space',
vote: {
choice: { [yourChoice]: 1 },
created: Math.round(Date.now() / 1000),
signature: 'sig',
voter: 'foo',
vp: 30,
},
};
const castedVote = await client.castVote(signer, voteObject);
Update a vote
const updatedVoteObject: UpdatedVoteObject = {
proposalId: 'proposal-id',
spaceId: 'your-space',
isUpdatedVote: true,
previousVote: {
choice: { [previousChoice]: 1 },
created: Math.round(Date.now() / 1000),
signature: 'old sig',
voter: 'foo',
vp: 30,
},
vote: {
choice: { [newChoice]: 1 },
created: Math.round(Date.now() / 1000),
signature: 'new sig',
voter: 'foo',
vp: 30,
},
};
const updatedVote = await client.updateVote(signer, updatedVoteObject);
Calculating User Voting Power
Types
The SDK includes several exported types that can be useful when working with the Heds Voting System:
Choice ClientConfig HedsClient IpfsLink Proposal QuadraticVote SingleChoiceVote Strategy UpdatedVoteObject VoteObject VotePayload Additionally, the SDK exports the following enums:
VoteMethod ProposalState For a complete understanding of the types and enums, refer to the source code.