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.
npm install hedsvoteThis 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.
``bash`
npm install heds-voting-sdk
Import the SDK and create a client:
`
import { createClient, calculateUserVotingPower, VoteMethod, ProposalState } from 'heds-voting-sdk';
const client = createClient();
`
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:
#### Get all proposals
`const proposals = await client.getAllProposals('your-space');`
#### Get a single proposal
`const proposal = await client.getProposal('your-space', 'proposal-id');``
#### Create a new proposalconst newProposal = await client.createProposal(signer, 'your-space', proposal);`
#### Delete a proposal
` const deletedProposal = await client.deleteProposal(signer, 'your-space', 'proposal-id');`
#### 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);
`
const userVotingPower = await calculateUserVotingPower(walletId, strategies);
``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.