cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
655 stars 344 forks source link

How to vote with cosmosjs #1575

Open laohe-adam opened 7 months ago

laohe-adam commented 7 months ago
const result = await signingClient.signAndBroadcast(

            address,

            [
                {
                    typeUrl: "/cosmos.gov.v1beta1.MsgVote",
                     value: {
                        proposalId:895,
                        voter: i,
                        option:1,
                        //amount: { denom: "uatom", amount: 0, },
                    },
                    },
            ],
            "auto"

            )

                // Output the result of the Tx
                console.log("Transfer result:", result)

/ how to fix it

With signing client, chain id: cosmoshub-4 , height: 19756249
Error: Broadcasting transaction failed with code 11 (codespace: sdk). Log: out of gas in location: WriteFlat; gasWanted: 43121, gasUsed: 43494: out of gas
    at SigningStargateClient.broadcastTx (d:\deskbokk\cosmjs-sandbox-master\node_modules\@cosmjs\stargate\src\stargateclient.ts:386:9)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runAll (d:\deskbokk\cosmjs-sandbox-master\投票.ts:64:24)
seleniumforest commented 7 months ago

https://atmoner.github.io/cosmjs-examples/broadcast/gov/MsgVote.html