From f3227209df70953c5f7d8e6a43df2fe10dd26d29 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 18 Nov 2021 22:36:17 +0100 Subject: [PATCH] Fix stargate example to latest fee API --- packages/cli/examples/stargate.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/cli/examples/stargate.ts b/packages/cli/examples/stargate.ts index b666cd76..fabd8c11 100644 --- a/packages/cli/examples/stargate.ts +++ b/packages/cli/examples/stargate.ts @@ -1,7 +1,8 @@ import { makeCosmoshubPath } from "@cosmjs/amino"; import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; -import { assertIsBroadcastTxSuccess, SigningStargateClient } from "@cosmjs/stargate"; +import { assertIsBroadcastTxSuccess, calculateFee, GasPrice, SigningStargateClient } from "@cosmjs/stargate"; +// Wallet const mnemonic = "economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone"; const path = makeCosmoshubPath(3); @@ -10,15 +11,27 @@ const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { hdPaths: [ const [account] = await wallet.getAccounts(); console.log("Signer address:", account.address); +// Network config const rpcEndpoint = "ws://localhost:26658"; +const gasPrice = GasPrice.fromString("0.025ucosm"); + +// Setup client const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet); +// Send transaction const recipient = "cosmos1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5"; const amount = { denom: "ucosm", amount: "1234567", }; -const result = await client.sendTokens(account.address, recipient, [amount], "Have fun with your star coins"); +const fee = calculateFee(200_000, gasPrice); +const result = await client.sendTokens( + account.address, + recipient, + [amount], + fee, + "Have fun with your star coins", +); assertIsBroadcastTxSuccess(result); console.log("Successfully broadcasted:", result);