# 2.9 Send a Token to another address

Let's perform another important task:

Send tokens to another account.

Like we explained in chapter 2.6, we learned that handling wallet addresses is not an easy task. Wallet address are pretty compex to write down or remember. If you just provide someone with even one digit or one letter wrong your money is lost forever One way to get an address is scan a QR code. BTW you should also check id the address is valid.

When you have the correct address we need to Send tokens to them, here's how to do it.

# Use cases

Send a token to another account

# Tools

The Sacco library, our own open source tool to sign and send transactions to any Cosmos SDK based blockchain, including Commercio.network.

The Commercio SDK, our own open source tool to format transactions to Commercio.network

# Functions and APIs

  • TxHelper createSignAndSendTx.

# Step by step sequence

  1. Generate the sender wallet;
  2. Generate the recipient wallet;
  3. Set up the amounts list;
  4. Set up the messages list;
  5. Finally, execute the TxHelper createSignAndSendTx function to send the token.

# Code Examples

Here's an example of the implementation in all the available languages.

# Dart

final wallet = Wallet.derive(mnemonic, networkInfo);
final recipientWallet = Wallet.derive(recipientMnemonic, networkInfo);
final amount = [const StdCoin(denom: 'ucommercio', amount: '500')];
final msgs = [
  MsgSend(
    amount: amount,
    fromAddress: wallet.bech32Address,
    toAddress: recipientWallet.bech32Address,
  ),
];

final response = await TxHelper.createSignAndSendTx(
  msgs,
  wallet,
  fee: StdFee(
    gas: '200000',
    amount: [
      const StdCoin(
        denom: 'ucommercio', amount: '10000'
      ),
    ],
  ),
  mode: BroadcastingMode.SYNC,
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# Kotlin

val wallet = Wallet.derive(mnemonic = mnemonic, networkInfo = networkInfo)
val recipientWallet = Wallet.derive(mnemonic = recipientMnemonic, networkInfo = networkInfo)
val gas = "200000"
val amount = listOf(StdCoin( "ucommercio", "500"))
val amountFee= listOf(StdCoin( "ucommercio", "10000"))
val msgs = listOf(
  MsgSend(
    amount = amount,
    fromAddress = wallet.bech32Address,
    toAddress = recipientWallet.bech32Address
  )
)

val response = TxHelper.createSignAndSendTx(
  msgs = msgs,
  wallet = wallet,
  fee = StdFee(
    gas = gas,
    amount = amountFee
  )
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# C#

var senderWallet = commercio.sacco.lib.Wallet.derive(senderMnemonic, networkInfo);

var recipientWallet = commercio.sacco.lib.Wallet.derive(recipientMnemonic, networkInfo);

var gas = "200000";
List<commercio.sacco.lib.StdCoin> amount = new List<commercio.sacco.lib.StdCoin>();
amount.Add(new commercio.sacco.lib.StdCoin(denom: "ucommercio", amount: "10"));

var msgs = new List<commercio.sacco.lib.StdMsg>();
msgs.Add(new commercio.sacco.lib.MsgSend(
   amount: amount,
   fromAddress: senderWallet.bech32Address,
   toAddress: recipientWallet.bech32Address
 ));

var res = commercio.sdk.TxHelper.createSignAndSendTx(
 msgs,
 senderWallet,
 fee: new commercio.sacco.lib.StdFee(
   gas: gas,
   amount: amount
 ));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22