forked from silentnoname/cosmos-learn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6-voteProposal.js
41 lines (33 loc) · 1.04 KB
/
6-voteProposal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {
SigningStargateClient
} from "@cosmjs/stargate";
import { coins, Secp256k1HdWallet } from '@cosmjs/launchpad'
async function voteProposal(client, proposalId, address, option) {
let ops = [];
let msg = {
typeUrl: "/cosmos.gov.v1beta1.MsgVote",
value: {
proposalId: proposalId,
voter: address,
option: option
},
};
ops.push(msg);
const fee = {
amount: coins(800, "uatom"),
gas: "180000",
};
let result = await client.signAndBroadcast(address, ops, fee, '');
console.log("Broadcasting result:", result);
}
async function start(mnemonic) {
const rpcEndpoint = "https://cosmoshub.validator.network/";
const wallet = await Secp256k1HdWallet.fromMnemonic(
mnemonic
);
const [account] = await wallet.getAccounts();
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet);
await voteProposal(client, "62", account.address, 1);
}
const mnemonic = "";//enter mnemonic
start(mnemonic);