@samudai_xyz/web3-sdk
Version:
## All in one web3 integrations for Samudai
59 lines (58 loc) • 1.98 kB
JavaScript
import snapshot from '@snapshot-labs/snapshot.js';
import { SnapshotQueries } from '../lib/snapshotQueries';
export class Snapshot {
//private hub = 'https://hub.snapshot.org'
constructor(spaceId) {
this.queries = new SnapshotQueries();
this.getSpace = async () => {
try {
const result = await this.queries.getSpace(this.spaceId);
return result;
}
catch (err) {
throw err;
}
};
this.getActiveProposals = async () => {
try {
const result = await this.queries.getActiveProposals(this.spaceId);
return result;
}
catch (err) {
throw err;
}
};
this.getRecentProposals = async () => {
try {
const result = await this.queries.getRecentProposals(this.spaceId);
return result;
}
catch (err) {
throw err;
}
};
this.castVote = async (proposalId, choice, account, provider, reason) => {
try {
const client = new snapshot.Client712('https://hub.snapshot.org');
const result = await this.queries.getProposal(proposalId);
if (result) {
const space = result.space.id;
const proposal = proposalId;
const type = result.type;
const voteReceipt = await client.vote(provider, account, {
space: space,
proposal: proposal,
choice: choice,
type: type,
reason: reason,
});
return voteReceipt;
}
}
catch (err) {
throw err;
}
};
this.spaceId = spaceId;
}
}