mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Use sendTokens and signAndBroadcast in example
This commit is contained in:
parent
20e49746c5
commit
e3b18c3859
@ -24,22 +24,44 @@ const gasPrice = GasPrice.fromString("0.025ucosm");
|
||||
// Setup client
|
||||
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet);
|
||||
|
||||
// Send transaction (using simulate)
|
||||
const recipient = "cosmos1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5";
|
||||
const amount = coins(1234567, "ucosm");
|
||||
const sendMsg: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: {
|
||||
fromAddress: account.address,
|
||||
toAddress: recipient,
|
||||
amount: amount,
|
||||
},
|
||||
};
|
||||
const memo = "With simulate";
|
||||
const gasEstimation = await client.simulate(account.address, [sendMsg], memo);
|
||||
const fee = calculateFee(Math.floor(gasEstimation * 1.3), gasPrice);
|
||||
const result = await client.sendTokens(account.address, recipient, amount, fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
// Send transaction (using sendTokens)
|
||||
{
|
||||
const recipient = "cosmos1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5";
|
||||
const amount = coins(1234567, "ucosm");
|
||||
const sendMsg: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: {
|
||||
fromAddress: account.address,
|
||||
toAddress: recipient,
|
||||
amount: amount,
|
||||
},
|
||||
};
|
||||
const memo = "With simulate";
|
||||
const gasEstimation = await client.simulate(account.address, [sendMsg], memo);
|
||||
const fee = calculateFee(Math.floor(gasEstimation * 1.3), gasPrice);
|
||||
const result = await client.sendTokens(account.address, recipient, amount, fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
}
|
||||
|
||||
// Send transaction (using signAndBroadcast)
|
||||
{
|
||||
const recipient = "cosmos1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5";
|
||||
const amount = coins(1234567, "ucosm");
|
||||
const sendMsg: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: {
|
||||
fromAddress: account.address,
|
||||
toAddress: recipient,
|
||||
amount: amount,
|
||||
},
|
||||
};
|
||||
const memo = "With simulate";
|
||||
const gasEstimation = await client.simulate(account.address, [sendMsg], memo);
|
||||
const fee = calculateFee(Math.floor(gasEstimation * 1.3), gasPrice);
|
||||
const result = await client.signAndBroadcast(account.address, [sendMsg], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
}
|
||||
|
||||
client.disconnect();
|
||||
|
Loading…
x
Reference in New Issue
Block a user