Fix stargate example to latest fee API

This commit is contained in:
Simon Warta 2021-11-18 22:36:17 +01:00
parent 5461db8cd5
commit f3227209df

View File

@ -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);