# Sending mosaics and messages between two accounts¶

Transfer mosaics and messages between two accounts.

## Background¶

Sending a TransferTransaction

Alice wants to send 10 cat.currency to Bob, whose address is SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54.

### Monitoring the network¶

Once an account announces a transaction, the server will always return an OK response. Receiving an OK response does not mean the transaction is valid. A good practice is to monitor transactions before being announced.

To understand the transaction lifecycle, we recommend you to open three new terminals. The first terminal monitors announced transactions validation errors.

nem2-cli monitor status


Monitoring unconfirmed shows you which transactions have reached the network, but are not included in a block yet.

nem2-cli monitor unconfirmed


Once a transaction is included, you will see it under the confirmed terminal.

nem2-cli monitor confirmed


## Getting into some code¶

1. Define the TransferTransaction, including Bob address as the recipient and attaching 10 cat.currency.
const recipientAddress = Address.createFromRawAddress('SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54');

const transferTransaction = TransferTransaction.create(
[NetworkCurrencyMosaic.createRelative(10)],
PlainMessage.create('Welcome To NEM'),
NetworkType.MIJIN_TEST);

const recipientAddress = Address.createFromRawAddress('SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54');

const transferTransaction = TransferTransaction.create(
[NetworkCurrencyMosaic.createRelative(10)],
PlainMessage.create('Welcome To NEM'),
NetworkType.MIJIN_TEST);


As you may have noticed, transfer transactions require an array of mosaics as a parameter, allowing to send transfer transactions with multiple mosaics at the same time.

If you own more than one mosaic, you can send them together in the same transaction:

    [new Mosaic( new MosaicId('7cdf3b117a3c40cc'), UInt64.fromUint(1000)),
NetworkCurrencyMosaic.createRelative(10)],

    [new Mosaic( new MosaicId('7cdf3b117a3c40cc'), UInt64.fromUint(1000)),
NetworkCurrencyMosaic.createRelative(10)],


Note

NEM works with absolute amounts. To get an absolute amount, multiply the amount of assets you want to send by 10divisibility. For example, if the mosaic has divisibility 2, to send 10 units (relative) you should define 1000 (absolute) instead.

1. Sign the transaction with Alice’s account.

Note

To make the transaction only valid for your network, include the first block generation hash. Open http://localhost:3000/block/1 in a new tab and copy the meta.generationHash value.

const privateKey = process.env.PRIVATE_KEY as string;
const account = Account.createFromPrivateKey(privateKey,NetworkType.MIJIN_TEST);
const networkGenerationHash = process.env.NETWORK_GENERATION_HASH as string;

const signedTransaction = account.sign(transferTransaction, networkGenerationHash);

const privateKey = process.env.PRIVATE_KEY;
const account = Account.createFromPrivateKey(privateKey,NetworkType.MIJIN_TEST);
const networkGenerationHash = process.env.NETWORK_GENERATION_HASH;

const signedTransaction = account.sign(transferTransaction, networkGenerationHash);

1. Once signed, announce the transaction to the network.
const transactionHttp = new TransactionHttp('http://localhost:3000');
transactionHttp
.announce(signedTransaction)
.subscribe(x => console.log(x), err => console.error(err));

const transactionHttp = new TransactionHttp('http://localhost:3000');
transactionHttp
.announce(signedTransaction)
.subscribe(x => console.log(x), err => console.error(err));

 nem2-cli transaction transfer --recipient SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54 --mosaics @cat.currency::10000000 --message "Welcome to NEM"

1. Open the terminal where you are monitoring account transactions status. It should be empty. If there is an error, you can check the error code meaning here.

A new transaction should have appeared in the terminal where you are monitoring unconfirmed. At this point, the transaction has reached the network, but it is not clear if it will get included in a block.

If it is included in a block, the transaction gets processed, and the amount stated in the transaction gets transferred from the sender’s account to the recipient’s account.