# IOTA 101: Transactions
A transaction is a smallest piece of data that can be broadcasted to the network. Each transaction consists of fixed 2673 trytes. Transactions (TXs) are basically of two types:
* **Value TXs:** those transactions change ownership of IOTA tokens. Two possible states: spending TXs or receiving TXs
* **Non-Value TXs:** those transactions include piece of data that can be broadcasted and read from the Tangle

Transactions are broadcasted in an envelope called *Bundle*. Bundle may consist of multiple TXs. Bundle is processed by the Tangle as a single entity; meaning only the whole bundle is confirmed by the network (and all TXs within) or nothing. You have to prepare a bundle even if you broadcast single transaction only. Bundle is also described as *atomic* since every bundle includes all information needed to process it antonomously.

Each transaction includes several fields, let's name the most important ones:
* **`Value`:** Value can be *positive* number = receiving IOTA tokens, *negative* number = spending IOTA tokens or *zero* = broadcasting only piece of data
* **`Address`:** It is IOTA address that is associated with the given transaction. *Value* indicates whether it is an address of a receiver or a sender
* **`Tag`:** It is an user-defined tag that can be used for searching, etc.
* **`SignatureMessageFragment`:** This is the most lenghty attribute (2187 trytes) and could include: *transaction signature* based on private key in case it is a spending TX or *piece of data (message)* in case it is non-value TX. Alternatively it can be also left blank (in case of non-value TXs)
* **`TrunkTransaction` / `branchTransaction`:** Those two fields refer to some previous transactions in the Tangle (tips) that the given bundle is going to approve
* **`Timestamp`:** TX timestamp. It is actually UNIX timestamp (UTC)

A process of sending IOTA transaction can be summarized in 5 steps:
* To create transation(s) with the given attributes: *value*, *address* and potentially also *tag* or *message*
* To finalize a bundle that includes all transactions. Once the bundle is finalized no new transactions can be added. It basically means to generate a *bundle hash*
* To search for two tips in the Tangle that you are going to validate. There is not a strict rule how to search them but it is generally recommended to leave it on a *tip selection algorithm* implemented on node's side
* To do a *Proof-of-Work* for each transaction in the bundle. Result of POW is *Nonce* and *Transaction hash* stored with each transaction
* Finally you need to *broadcast* the whole bundle to the network

### A secret of a bundle
There is a secret to be shared. You have to understand one important thing. Bundle is a top level construct that link all related transactions under one entity however the bundle itself is not broadcasted in fact. You still broadcast "only" collection of individual transactions instead. All transactions are recognized to be part of a bundle by the IOTA protocol however any data peering is based on individual transactions (in trytes).

In other words, a bundle can be reconstructed anytime from a collection of transactions via fields `bundle hash`, `current index` and `last index`.

## Non-value transactions
Let's start with non-value transactions (meta transactions) first since they are a bit easier for starters.

*Please note, the chapter is divided in two separate sections. In the first section, examples are really close to bare metal (still not too close:) to illustrate the whole process and describing implementation details wherever possible. It is also useful when you want to experiment with different settings at each step (hey "non-existing tips", looking at you).*

*In the second section, IOTA-facing libraries are fully levearged since they are capable to hide all implementation details behind a curtain. Needless to say, if you are not interested in such details then you would probably like to start with the second section.*

### Creating and broadcasting transaction in 5 steps (you want to understand the process)
#### Create a transaction
First of all let's create transactions (offline; in memory) and set main fields.

BTW: `Timestamp` field is defined automatically by the IOTA-facing libraries in the process. It is important field while creating `bundle hash`.

In the examples within this chapter we are going to broadcast meta transactions (data only) to two different IOTA addresses.

```python
import iota
from datetime import datetime
from pprint import pprint

MySeed = b"HGW9HB9LJPYUGVHNGCPLFKKPNZAIIFHZBDHKSGMQKFMANUBASSMSV9TAJSSMPRZZU9SFZULXKJ9YLAIUA"
TargetAddress1 = b"CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9"
TargetAddress2 = b"CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW"

NowIs = datetime.now() # get a actual date & time - just to have some meaningfull info

# preparing transactions
pt = iota.ProposedTransaction(address = iota.Address(TargetAddress1), # 81 trytes long address
                              message = iota.TryteString.from_unicode('Here comes a first message. Now is %s' % (NowIs)),
                              tag     = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'), # Up to 27 trytes
                              value   = 0)

pt2 = iota.ProposedTransaction(address = iota.Address(TargetAddress2), # 81 trytes long address
                               message = iota.TryteString.from_unicode('Here comes a second message. Now is %s' % (NowIs)),
                               tag     = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'), # Up to 27 trytes
                               value   = 0)
# besides the given attributes, library also adds a transaction timestamp

print("Created transaction objects:\n")
pprint(vars(pt))
print("\n")
pprint(vars(pt2))
```

    Created transaction objects:

    {'_legacy_tag': None,
     'address': Address(b'CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9'),
     'attachment_timestamp': 0,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 0,
     'branch_transaction_hash': TransactionHash(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'bundle_hash': None,
     'current_index': None,
     'hash': None,
     'is_confirmed': None,
     'last_index': None,
     'message': TryteString(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA'),
     'nonce': Nonce(b'999999999999999999999999999'),
     'signature_message_fragment': None,
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1530080759,
     'trunk_transaction_hash': TransactionHash(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'value': 0}

    {'_legacy_tag': None,
     'address': Address(b'CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW'),
     'attachment_timestamp': 0,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 0,
     'branch_transaction_hash': TransactionHash(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'bundle_hash': None,
     'current_index': None,
     'hash': None,
     'is_confirmed': None,
     'last_index': None,
     'message': TryteString(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA'),
     'nonce': Nonce(b'999999999999999999999999999'),
     'signature_message_fragment': None,
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1530080759,
     'trunk_transaction_hash': TransactionHash(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'value': 0}

#### Finalizing bundle
Once all individual transactions are created it is time to prepare and finalize the bundle. While preparing the bundle you need at least to specify list of prepared transaction(s). In case of non-value transactions it is quite straightforward process. However, it is a bit more complicated in case of value transactions - please see later.

Finalizing the bundle consists of several tasks under the hood:
* Each transaction is indexed. Attributes `current_index` / `last_index` are set
* `Bundle hash` is generated (*Sponge function* + normalization) and assigned to each transaction
* `signatureMessageFragment` is bascially copy of `message` field in case of non-value transactions
* PyOTA library also checks whether the data in `message` field is larger than transaction allows (2187 trytes). If this is the case then it takes care of it and split your data into several transactions

*Please note, finalizing the bundle also means you are no longer able to add new transactions to the bundle post the finalization process.*

Simply put, `bundle hash` is a cryptographic "fingerprint" of all transactions in the bundle. It uniquely represents them and so as long as transactions are the same (incl their particular order) the `bundle hash` is also the same.

$$BundleHash = fce(address, value, legacy tag, timestamp, current index, last index)$$

You may be wondering what is a difference between `tag` and `legacy_tag`. `Tag` includes actualy the tag that was defined during the transaction creation. `Legacy_tag` is also based on it however it is modified during the normalization process while bundle hashing to be sure that `bundle hash` is can be securely used while TX signing. That's why the `bundle hash` is sometimes refered as `normalized bundle hash`.

The bundle refers to the first transaction in collection as `tail_transaction`. You can perceive `tail transaction` as an official representative of the whole bundle while checking for confirmation status, etc. Remember, the bundle is an atomic entity and so whatever is done to bundle it applies to ALL transactions within.

```python
# preparing bundle that consists of both transactions prepared in the previous example
pb = iota.ProposedBundle(transactions=[pt,pt2]) # list of prepared transactions is needed at least

# generate bundle hash using sponge/absorb function + normalize bundle hash + copy bundle hash into each transaction / bundle is finalized
pb.finalize()

#bundle is finalized, let's print it
print("\nGenerated bundle hash: %s" % (pb.hash))
print("\nTail Transaction in the Bundle is a transaction #%s." % (pb.tail_transaction.current_index))

print("\nList of all transactions in the bundle:\n")
for txn in pb:
    pprint(vars(txn))
    print("")

```

    Generated bundle hash: TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADW

    Tail Transaction in the Bundle is a transaction #0.

    List of all transactions in the bundle:

    {'_legacy_tag': Tag(b'PVIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9'),
     'attachment_timestamp': 0,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 0,
     'branch_transaction_hash': TransactionHash(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'bundle_hash': BundleHash(b'TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADW'),
     'current_index': 0,
     'hash': None,
     'is_confirmed': None,
     'last_index': 1,
     'message': TryteString(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA'),
     'nonce': Nonce(b'999999999999999999999999999'),
     'signature_message_fragment': Fragment(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1530080759,
     'trunk_transaction_hash': TransactionHash(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'value': 0}

    {'_legacy_tag': None,
     'address': Address(b'CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW'),
     'attachment_timestamp': 0,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 0,
     'branch_transaction_hash': TransactionHash(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'bundle_hash': BundleHash(b'TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADW'),
     'current_index': 1,
     'hash': None,
     'is_confirmed': None,
     'last_index': 1,
     'message': TryteString(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA'),
     'nonce': Nonce(b'999999999999999999999999999'),
     'signature_message_fragment': Fragment(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1530080759,
     'trunk_transaction_hash': TransactionHash(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'value': 0}

At this stage you can also see how does our finalized bundle look encoded in Trytes so far. It is also a proof that there is no bundle to be broadcasted itself, only list of transations matter.

```python
Trytes = pb.as_tryte_strings() # bundle as trytes
pprint(Trytes)

```

    [TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW999999999999999999999999999HRIBEK999IOTA999TUTORIAL999TFDCQZD99A99999999A99999999TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADW999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999HRIBEK999IOTA999TUTORIAL999999999999999999999999999999999999999999999999999999999'),
     TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9999999999999999999999999999PVIBEK999IOTA999TUTORIAL999TFDCQZD99999999999A99999999TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADW999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999HRIBEK999IOTA999TUTORIAL999999999999999999999999999999999999999999999999999999999')]

#### Selecting two tips
As mentioned earlier you need to find two tips that you are going to validate together with your bundle for a sake of network participation. This will be outsourced to an IOTA node and so it will be for the first time we interact with the network (via API call `get_transactions_to_approve`).

There is a `depth` parameter needed. It instructs a node how many milestones it should go in the past while confirming tips. The higher value the better to network however more resources needed. `Depth=3` is considered to be well-balanced compromise. Higher value than `depth=10` will probably throw an exception depending on node's configuration.

It should return two selected tips as `branch` and `trunk` transactions. Those transactions will be used while broadcasting the bundle.

```python
api = iota.Iota("https://nodes.thetangle.org:443") # selecting IOTA node

gta = api.get_transactions_to_approve(depth=3) # get tips to be approved by your bundle
pprint(gta)

```

    {'branchTransaction': TransactionHash(b'KQBDDBHWHVLQSJFENGWRBHIOULOMC9GXDW99ECMVFHZXGFZQJOXATSMDLYQJFBZCXA9IJ9SQUXAFZ9999'),
     'duration': 1700,
     'fieldName': 'F-Node Montabaur',
     'fieldPublicId': '1bdeeb759f960554',
     'fieldVersion': '0.1.6',
     'trunkTransaction': TransactionHash(b'RRYDZLPS9IWCSWRROPQQJTKBRONOJNLUHVHFXFEOZAVGFEOUAHXWWHJSHAGWSSNSMWHN9SEYNBOEA9999')}

#### Performin' POW
*Proof of work* is a relatively simple cryptograhic puzzle to be solved. It represents energy-based costs of your transaction. It also helps to minimize risks of some attack vectors to the network.

This task can be also outsourced to IOTA nodes. In order to perform it you need *selected tips*, *finalized bundle* (in trytes) and also `Minimum Weight Magnitude` parameter. This parameter defines how diffciult the given cryptographic puzzle should be to be accepted by the network. As of now, you should set at least `min_weight_magnitude=14` in case of mainnet.

Please note, POW is performed per each transaction and so it can take some time. That's why it is not recommended to have more than 30 transactions in a bundle.

Once succesfully performed, the modified bundle (list of all transactions in trytes) is returned in order to be broadcasted.

Specifically:
* Fields `nonce` and `transaction hash` are calculated per each transaction
* `Trunk` and `Branch` tips are correctly mapped among transactions within the bundle. Check that `trunk` of the first TX refers to the second TX, etc.

```python
print("Performing POW... Wait please...\n")
att = api.attach_to_tangle(trunk_transaction=gta['trunkTransaction'], # first tip selected
                           branch_transaction=gta['branchTransaction'], # second tip selected
                           trytes=Trytes, # our finalized bundle in Trytes
                           min_weight_magnitude=14) # MWMN
pprint(att)
```

    Performing POW... Wait please...

    {'duration': 12267,
     'fieldName': 'iota-fn01.sairai.de',
     'fieldPublicId': '45f52c5a2e829a00',
     'fieldVersion': '0.1.6',
     'trytes': [TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9999999999999999999999999999PVIBEK999IOTA999TUTORIAL999TFDCQZD99999999999A99999999TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADWNNNY9QAGVOOGTCIGBBEPIYISUZKNJYUQMROBTZARQVPHONNLQNQFAHTBNXMYWDFHAHMNRJ9URLKX99999RRYDZLPS9IWCSWRROPQQJTKBRONOJNLUHVHFXFEOZAVGFEOUAHXWWHJSHAGWSSNSMWHN9SEYNBOEA9999HRIBEK999IOTA999TUTORIAL999RLISAKGKE999999999L99999999QRZIERPEJFLKTIVKEBQIHJXTAX9'),
                TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW999999999999999999999999999HRIBEK999IOTA999TUTORIAL999TFDCQZD99A99999999A99999999TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADWRRYDZLPS9IWCSWRROPQQJTKBRONOJNLUHVHFXFEOZAVGFEOUAHXWWHJSHAGWSSNSMWHN9SEYNBOEA9999KQBDDBHWHVLQSJFENGWRBHIOULOMC9GXDW99ECMVFHZXGFZQJOXATSMDLYQJFBZCXA9IJ9SQUXAFZ9999HRIBEK999IOTA999TUTORIAL999GDVSAKGKE999999999L99999999OOLRWTCMJMIQIAUVWBY9TVMZAJJ')]}

You can eventually also preview what specific fields have been modified using transaction objects. The bundle is ready to be broadcasted and so it also show you all fields/values that will be stored in the network.

```python
# show what has been broadcasted - hash transaction + nonce (POW)
print("Final bundle including POW and branch/trunk transactions:\n")
for t in att['trytes']:
    pprint(vars(iota.Transaction.from_tryte_string(t)))
    print("")
```

    Final bundle including POW and branch/trunk transactions:

    {'_legacy_tag': Tag(b'PVIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9'),
     'attachment_timestamp': 1530081729891,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 12,
     'branch_transaction_hash': TransactionHash(b'RRYDZLPS9IWCSWRROPQQJTKBRONOJNLUHVHFXFEOZAVGFEOUAHXWWHJSHAGWSSNSMWHN9SEYNBOEA9999'),
     'bundle_hash': BundleHash(b'TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADW'),
     'current_index': 0,
     'hash': TransactionHash(b'SYDECKQB9BHWFUYOZMANREHOCXHCOPY9JCSZSNIZRNDJTZXHHSESCCLQOENGRVFLDMNXYAHHEWRDZ9999'),
     'is_confirmed': None,
     'last_index': 1,
     'nonce': Nonce(b'QRZIERPEJFLKTIVKEBQIHJXTAX9'),
     'signature_message_fragment': Fragment(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1530080759,
     'trunk_transaction_hash': TransactionHash(b'NNNY9QAGVOOGTCIGBBEPIYISUZKNJYUQMROBTZARQVPHONNLQNQFAHTBNXMYWDFHAHMNRJ9URLKX99999'),
     'value': 0}

    {'_legacy_tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW'),
     'attachment_timestamp': 1530081719485,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 12,
     'branch_transaction_hash': TransactionHash(b'KQBDDBHWHVLQSJFENGWRBHIOULOMC9GXDW99ECMVFHZXGFZQJOXATSMDLYQJFBZCXA9IJ9SQUXAFZ9999'),
     'bundle_hash': BundleHash(b'TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADW'),
     'current_index': 1,
     'hash': TransactionHash(b'NNNY9QAGVOOGTCIGBBEPIYISUZKNJYUQMROBTZARQVPHONNLQNQFAHTBNXMYWDFHAHMNRJ9URLKX99999'),
     'is_confirmed': None,
     'last_index': 1,
     'nonce': Nonce(b'OOLRWTCMJMIQIAUVWBY9TVMZAJJ'),
     'signature_message_fragment': Fragment(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1530080759,
     'trunk_transaction_hash': TransactionHash(b'RRYDZLPS9IWCSWRROPQQJTKBRONOJNLUHVHFXFEOZAVGFEOUAHXWWHJSHAGWSSNSMWHN9SEYNBOEA9999'),
     'value': 0}

#### Broadcasting
Now it is time to broadcast the given bundle to the network. List of all transations in trytes returned from the previous step is only thing needed.

Once succesfully broadcasted it returns the same input bundle as a confirmation.

```python
print("Broadcasting transaction...")
res = api.broadcast_and_store(att['trytes'])
pprint(res)
```

    Broadcasting transaction...
    {'trytes': [TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9999999999999999999999999999PVIBEK999IOTA999TUTORIAL999TFDCQZD99999999999A99999999TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADWNNNY9QAGVOOGTCIGBBEPIYISUZKNJYUQMROBTZARQVPHONNLQNQFAHTBNXMYWDFHAHMNRJ9URLKX99999RRYDZLPS9IWCSWRROPQQJTKBRONOJNLUHVHFXFEOZAVGFEOUAHXWWHJSHAGWSSNSMWHN9SEYNBOEA9999HRIBEK999IOTA999TUTORIAL999RLISAKGKE999999999L99999999QRZIERPEJFLKTIVKEBQIHJXTAX9'),
                TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAWAABEAUA9BDBWAZADBZACBSAXAVAABXAABWA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW999999999999999999999999999HRIBEK999IOTA999TUTORIAL999TFDCQZD99A99999999A99999999TL9EHBGBIDCTLCARLPKBSUQIG9CKQPDGTLOVNLG9TALAGEWQRBEK9DPLDDBGOAZIREKGYPYFCWJCTOADWRRYDZLPS9IWCSWRROPQQJTKBRONOJNLUHVHFXFEOZAVGFEOUAHXWWHJSHAGWSSNSMWHN9SEYNBOEA9999KQBDDBHWHVLQSJFENGWRBHIOULOMC9GXDW99ECMVFHZXGFZQJOXATSMDLYQJFBZCXA9IJ9SQUXAFZ9999HRIBEK999IOTA999TUTORIAL999GDVSAKGKE999999999L99999999OOLRWTCMJMIQIAUVWBY9TVMZAJJ')]}

You can check the broadcasted bundle via The Tangle Explorer at any of the receiving addresses:
* Target address 1: https://thetangle.org/address/CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9
* Target address 2:
https://thetangle.org/address/CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW

### Creating and broadcasting transaction in a single call (you want send a transaction quickly)
As mentioned above, IOTA-facing libraries are able to encapsulate all implementation details and so you do not need to care of them anymore. It is usually based on *extended API calls* that were proposed to be included by IOTA Foundation to make developer's life easier (https://github.com/iotaledger/wiki/blob/master/api-proposal.md).

Even if using extended API calls you can still slightly control a level of your involvement in the whole process. From almost no involvement and fully automatic (`send_transfer()`) to semi-manual approach discussed above.

There are some specifics you should consider while designing your app:
* You are loosing a bit of control of individual steps of the process and you have to rely of some predefined parameters (tip selection algo, etc.)
* If there is an exception raised during the process then you need to go back at beginning and restart the whole process again

So it is basically your call to decide what works best for you.

Now back to our exercise. Here comes a code that basically broadcasts transactions in a single call (`send_transfer()`) and you do not have to care of any implemenation details that are hidden under the hood.

```python
import iota
from datetime import datetime
from pprint import pprint

MySeed = b"HGW9HB9LJPYUGVHNGCPLFKKPNZAIIFHZBDHKSGMQKFMANUBASSMSV9TAJSSMPRZZU9SFZULXKJ9YLAIUA"
TargetAddress1 = b"CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9"
TargetAddress2 = b"CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW"

NowIs = datetime.now() # get a actual date & time - just to have some meaningfull info

# preparing transactions
pt = iota.ProposedTransaction(address = iota.Address(TargetAddress1), # 81 trytes long address
                              message = iota.TryteString.from_unicode('Here comes a first message. Now is %s' % (NowIs)),
                              tag     = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'), # Up to 27 trytes
                              value   = 0)

pt2 = iota.ProposedTransaction(address = iota.Address(TargetAddress2), # 81 trytes long address
                               message = iota.TryteString.from_unicode('Here comes a second message. Now is %s' % (NowIs)),
                               tag     = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'), # Up to 27 trytes
                               value   = 0)
# besides the given attributes, library also adds a transaction timestamp

api = iota.Iota("https://nodes.thetangle.org:443")

print("Preparing/Broadcasting... Wait please...")
# the whole process initiated in a single call
FinalBundle = api.send_transfer(depth=3,
                                transfers=[pt,pt2],
                                min_weight_magnitude=14)['bundle'] # it returns a dictionary with a bundle object

#bundle is broadcasted, let's print it
print("\nGenerated bundle hash: %s" % (FinalBundle.hash))
print("\nTail Transaction in the Bundle is a transaction #%s." % (FinalBundle.tail_transaction.current_index))

print("\nList of all transactions in the bundle:\n")
for txn in FinalBundle:
    pprint(vars(txn))
    print("")
```

    Preparing/Broadcasting... Wait please...

    Generated bundle hash: AEFTRFKZLIFXSQCBLJOEDKYKPHSJD9UZFFAYVYELHKYVDRKXQKOKQTOCLBLCLEODRGZPUAWOXSFHJEPOW

    Tail Transaction in the Bundle is a transaction #0.

    List of all transactions in the bundle:

    {'_legacy_tag': Tag(b'ECIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9'),
     'attachment_timestamp': 1532100908930,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 3812798742493,
     'branch_transaction_hash': TransactionHash(b'SCVPZOUXDBIV9AJBVEE9SRLWWJZIXRKWHFMI9HDNZ9D9YPRLAFVIJ9OJZQWUXMOTMCQRBTMM9CRK99999'),
     'bundle_hash': BundleHash(b'AEFTRFKZLIFXSQCBLJOEDKYKPHSJD9UZFFAYVYELHKYVDRKXQKOKQTOCLBLCLEODRGZPUAWOXSFHJEPOW'),
     'current_index': 0,
     'hash': TransactionHash(b'SVZ99MALQGVFHPONJTHRPPLIFBJWJWJTEHOGWTFRPZGDSPDKEUCIWLGPNKEFXLAGXEODSBBETKBP99999'),
     'is_confirmed': None,
     'last_index': 1,
     'nonce': Nonce(b'WRMXCTEXLGCMUZJOBSCMHNQD9VS'),
     'signature_message_fragment': Fragment(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUAABRAWAUAEAVAABDBXAZADBUAUASAVABBUAUACBUA9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1532100900,
     'trunk_transaction_hash': TransactionHash(b'CVRWTIPJHU9DOIZUNMEIOCPPMITKILETO9QALYEZCULKRD9ALIUYYQFYWPJEMYGBSNS9WUAHGCHEZ9999'),
     'value': 0}

    {'_legacy_tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW'),
     'attachment_timestamp': 1532100903056,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 3812798742493,
     'branch_transaction_hash': TransactionHash(b'XUBGHJCEBSJXQYQJHBFBCVLVFLAM9SXLDFJJRRQISEXJJXCMNCRDXJABTHZEDW9RZWBWALDXAQCRA9999'),
     'bundle_hash': BundleHash(b'AEFTRFKZLIFXSQCBLJOEDKYKPHSJD9UZFFAYVYELHKYVDRKXQKOKQTOCLBLCLEODRGZPUAWOXSFHJEPOW'),
     'current_index': 1,
     'hash': TransactionHash(b'CVRWTIPJHU9DOIZUNMEIOCPPMITKILETO9QALYEZCULKRD9ALIUYYQFYWPJEMYGBSNS9WUAHGCHEZ9999'),
     'is_confirmed': None,
     'last_index': 1,
     'nonce': Nonce(b'FXXJWXQEMJFJMNRIWULHJDPFVRI'),
     'signature_message_fragment': Fragment(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUAABRAWAUAEAVAABDBXAZADBUAUASAVABBUAUACBUA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1532100900,
     'trunk_transaction_hash': TransactionHash(b'SCVPZOUXDBIV9AJBVEE9SRLWWJZIXRKWHFMI9HDNZ9D9YPRLAFVIJ9OJZQWUXMOTMCQRBTMM9CRK99999'),
     'value': 0}

You can check the broadcasted bundle via The Tangle Explorer at any of the receiving addresses:
* Target address 1: https://thetangle.org/address/CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9
* Target address 2:
https://thetangle.org/address/CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW

And to complete the picture here is addtional code that uses `prepare_transfer()` and `send_trytes()` combo.

```python
import iota
from datetime import datetime
from pprint import pprint

MySeed = b"HGW9HB9LJPYUGVHNGCPLFKKPNZAIIFHZBDHKSGMQKFMANUBASSMSV9TAJSSMPRZZU9SFZULXKJ9YLAIUA"
TargetAddress1 = b"CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9"
TargetAddress2 = b"CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW"

NowIs = datetime.now() # get a actual date & time - just to have some meaningfull info

# preparing transactions
pt = iota.ProposedTransaction(address = iota.Address(TargetAddress1), # 81 trytes long address
                              message = iota.TryteString.from_unicode('Here comes a first message. Now is %s' % (NowIs)),
                              tag     = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'), # Up to 27 trytes
                              value   = 0)

pt2 = iota.ProposedTransaction(address = iota.Address(TargetAddress2), # 81 trytes long address
                               message = iota.TryteString.from_unicode('Here comes a second message. Now is %s' % (NowIs)),
                               tag     = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'), # Up to 27 trytes
                               value   = 0)
# besides the given attributes, library also adds a transaction timestamp

api = iota.Iota("https://nodes.thetangle.org:443")

# Creating bundle, preparing inputs and finalizing bundle. It returns trytes of prepared TXs
Trytes = api.prepare_transfer(transfers=[pt,pt2])

print("Almost prepared bundle - tips and POW are still missing")
pprint(Trytes)

print("\nSearching for tips and performing POW... Wait please...")
Result = api.send_trytes(trytes=Trytes["trytes"],
                         depth=3) # Searching for tips, performing POW and broadcasting

print("Bundle was broadcasted.")

print("\nFinal transactions were returned - including nonce (POW)")
pprint(Result)
```

    Almost prepared bundle - tips and POW are still missing
    {'trytes': [TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAXAUAEAUAABDBXAXADBYA9BSAXAYAWAWAZAYA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW999999999999999999999999999HRIBEK999IOTA999TUTORIAL999JINQRZD99A99999999A99999999CMRQYFTKZ9DANXOBEBKCIX9UBEIAWJJYFOXXSASFGUHOESLINSHF9TYDKTH9YDYLPQHWIUY9HDF9GWLLC999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999HRIBEK999IOTA999TUTORIAL999999999999999999999999999999999999999999999999999999999'),
                TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAXAUAEAUAABDBXAXADBYA9BSAXAYAWAWAZAYA9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9999999999999999999999999999RTIBEK999IOTA999TUTORIAL999JINQRZD99999999999A99999999CMRQYFTKZ9DANXOBEBKCIX9UBEIAWJJYFOXXSASFGUHOESLINSHF9TYDKTH9YDYLPQHWIUY9HDF9GWLLC999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999HRIBEK999IOTA999TUTORIAL999999999999999999999999999999999999999999999999999999999')]}

    Searching for tips and performing POW... Wait please...
    Bundle was broadcasted.

    Final transactions were returned - including nonce (POW)
    {'trytes': [TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAUCXCFDGDHDEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAXAUAEAUAABDBXAXADBYA9BSAXAYAWAWAZAYA9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9999999999999999999999999999RTIBEK999IOTA999TUTORIAL999JINQRZD99999999999A99999999CMRQYFTKZ9DANXOBEBKCIX9UBEIAWJJYFOXXSASFGUHOESLINSHF9TYDKTH9YDYLPQHWIUY9HDF9GWLLCYLURVDFXJWJRPTUHGRXSW9RPMZKPWBQWSHSSHRKGSJMDMLTPTENNGDBMEOGKUXDPGKFYUHIRTBCPZ9999ALYKPSMJNIXJGKOVORRLEOWGUSERFODOQZFBAHRBHMGWKIJ9WOFOHJCJDTQQPICAKJM9JFIBJAHFZ9999HRIBEK999IOTA999TUTORIAL999HW9HHBHKE999999999L99999999DLOEWKSWVGN9CVDUKAXTTEDBGHR'),
                TransactionTrytes(b'RBTCFDTCEARCCDADTCGDEAPCEAGDTCRCCDBDSCEAADTCGDGDPCVCTCSAEAXBCDKDEAXCGDEAWAUAVABBRAUA9BRAXAUAEAUAABDBXAXADBYA9BSAXAYAWAWAZAYA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW999999999999999999999999999HRIBEK999IOTA999TUTORIAL999JINQRZD99A99999999A99999999CMRQYFTKZ9DANXOBEBKCIX9UBEIAWJJYFOXXSASFGUHOESLINSHF9TYDKTH9YDYLPQHWIUY9HDF9GWLLCALYKPSMJNIXJGKOVORRLEOWGUSERFODOQZFBAHRBHMGWKIJ9WOFOHJCJDTQQPICAKJM9JFIBJAHFZ9999WVJQWHI9JHXRIZETFPYTDCZ9LLSSDGUIVVUKSDEFDWUTYJSBNXFFOHTVLFXBENLYVZBARO9WNXOGZ9999HRIBEK999IOTA999TUTORIAL999JDXHHBHKE999999999L99999999ZVTKMTIN9VFLWYQCPBMZVRMBMJE')]}

You can check the broadcasted bundle via The Tangle Explorer at any of the receiving addresses:
* Target address 1: https://thetangle.org/address/CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9
* Target address 2:
https://thetangle.org/address/CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW

## Value transactions
Meta transactions were discussed in the previous chapter. This chapter describes `value transactions` which are transactions that transfer IOTA tokens between IOTA addresses. Tokens are fully premined and so number of tokens in the network is given. So `transfering tokens` means changing their ownership only.

While preparing a bundle with `value transations` it is important to distinguish three different transaction types within a bundle:
* **Input TXs:** those are transactions that *deducting* (spending) value from address(es). Those transactions have negative `value` field. They usually refer to `senders`
* **Output TXs:** those are transactions that *adding* (receiving) value to address(es). Those transactions have positive `value` field. They usually refer to `recipients`
* **Unspent/change TX:** technically speaking it is also *output* transaction that *adding* value however it usually refers to `senders` and so it is better to consider it separated from other output TXs

All three types have to be part of each bundle otherwise you are under a risk of loosing IOTA tokens. In other words, each bundle should consists of at least one `input` TX, one `output` TX and one `unspent` TX. Total balance of the bundle should be zero since the number of tokens is the same, just token owners have been "changed".

Example:
* Alice owns 100 tokens (*input = 100*)
* Alice is going to send 20 tokens to John from the address that includes 100 tokens of her (*Alice -100*)
* John is going to receive 20 tokens from Alice (*output = 20*; *John +20*)
* Alice still owns 80 tokens after the transaction (*unspent = 80*; *Alice +80*)

Alice's bundle should look like:
\begin{align}
Input - Output & = \ Unspent \\
Input - Output - Unspent & = \ 0 \\
100 - 20 - 80 & = \ 0
\end{align}

Why Alice has to "put" all 100 tokens in the bundle while she is going to actually spend only 20 tokens? The reason is that IOTA protocol uses one-time signature scheme (OTS) for transaction signing while spending tokens. And with every signing process a half of a private key of the given address is revealed. That's why no one should ever spend tokens from the same address again.

### Spending tokens
*Please note: for a purpose of this chapter we are going to switch to a test network called `devnet`. It is the testing Tangle. Tokens are not real and everything you do have no implication to the mainnet at all. However it is stil powered by standard node software and so technicaly speaking it behaves like the mainnet. If you need more info regarding devnet please refer to [the official documentation](https://docs.iota.org/introduction/testnet/introduction).*

Everything what has been mentioned in the previous chapter focused on `non-value` transations is still valid also in case of value transactions however there are several additional tasks you should take care of. Needless to say, IOTA libraries (PyOTA and others) are ready to help you and are able to hide all implementation details in case you would like to. In this case I would encourage everyone to prefer a functionality that is offered by extended API calls, such as `send_transfer`. Experimenting with value transactions and trying to tweak them does not seem to be a good idea (on the mainnet).

Anyway, even in this chapter I am going to describe main tasks that are performed under the hood to be able to understand the whole concept.

Let's have the following setup:

```python
import iota
from pprint import pprint

# Sender's side ***********
# Sender's seed
SeedSender = b"HGW9HB9LJPYUGVHNGCPLFKKPNZAIIFHZBDHKSGMQKFMANUBASSMSV9TAJSSMPRZZU9SFZULXKJ9YLAIUA"

# Receiver's side ***********
# Recipient's seed - this is actually not needed for the exercise - it is just to have corresponding seed somewhere written
SeedReceiver = b"NVPDKGLESTYNJEH9DTWD9DUBYWHZJDDWTBLKWEYLVZKBKKAZTIZ9CFFJMHPEKIFUWQTXRGAVRXAQZCPHL"

# This is our target address to which we are going to send tokens to (BTW: it is a first generated address based on recipient's seed)
AddressReceiver = b"BMFSMZMNBGKHAWPIZIOMJGRBXZETVSAYDSTDQCHLYTBWZMIXLNXF9XHLTMOCATFVFOMBQF9IOQGPEBPDC"

#DevNet node - Devnet Tangle that is used only for testing/dev purposes - no real tokens here:(
DevnetNode = "https://nodes.devnet.iota.org:443"

print("Variables were initialized.")
```

    Variables were initialized.

You may be wondering why only the seed for sender's side is defined. As mentioned above the reason is that the address with tokens is changing with every spending exercise and so you have to find address with tokens that left in a bucket programatically (if any tokens left:).

Let's find out. For this purpose you can use extended API call `get_account_data` which returns a list of used addresses and total sum of all tokens available accross all of them:

```python
api = iota.Iota(DevnetNode,
                seed=SeedSender # let's use seed of the sender and so library can do all hard work
               )

print("Checking for total balance. This may take some time...")

# now we can find out whether there are any tokens left
SenderBalance = api.get_account_data(start=30, #starting from 30th address to save time
                                    stop=None) # Get the total available balance for the given seed and all related used addresses

print("\nPlease note, this may take some time if many addresses has been used already...")
pprint(SenderBalance)

if SenderBalance['balance']>0:
    print("\nYes, there are some tokens available! hurray")
```

    Checking for total balance. This may take some time...

    Please note, this may take some time if many addresses has been used already...
    {'addresses': [Address(b'OTJSUNSQ9DLJVLKMVVPLDUTRHZAJDISDPZQCEPWNJWUGZOSFWRRBTUJAWCKKXACMZQIUP9NVVFYWRISWA'),
                   Address(b'BGUDHNNYKGZWLBVIFCAGCSBWZRHXZSPT9NWLWFM9KLWCEPUGEDE9XRBOGFJLJCUJKQFILMIPGKZJYUAVW'),
                   Address(b'AYYUYIMDUGBXQBKMVOA9XBKXICCMLVYZCPAAAUVPSDDBJSOZJIY9RVMPMEVMGJVEROVMDVVYQXXKRANSD'),
                   Address(b'WHVPRFXYKBSIB9NYHWSGEWHLQYAIPLGIUIPGGIJNQYKKCWRMGLZNUIADZATOBCGBLBI99HYVQOHIFWRS9'),
                   Address(b'SUYDJCMS9XMBKOPIPOXKGXMFVYXQ9YRNZLDYLRFARZFOFJDDH9JZLCQVO9GBRQKBCXHSPHOAPPWFFLMBW'),
                   Address(b'NHVGPRAXYTDZJLMLSUMZGVBBMICDQGGAAZ9UJGLIPPOTUEZJXABCSDFUTRTBFOLDOQZIBS9QTRXAB9IUX'),
                   Address(b'VZITIWJF99TH9REMKLYZUWELFLEW9FVYXPZPVMVFZVIQHAOEMEDABUUZGFROKKIVMT999PWGGLICKJOAD'),
                   Address(b'XPV9CTUC9JEKATOVABXXLICTDAQEOHR9HXXFLHKN9OZFMFAZKKUDZMREOBZJONZAHXCGNN9FHGNFBAKMC'),
                   Address(b'NDQMBGBQIBAQURVAQEUVONVMECKXSNYZZNKMMMOHOLPEYHJHDBTFWOZMAPFUAHLHIQUAV9GVZPEMBKL9Z'),
                   Address(b'QYENROHVANIYBSIIMWGFDOUHXTMFOXIHOQXTJZLRFRJMOOINFTWCVVEJUFIITLBIHLVTESPVLUOSCFJDZ'),
                   Address(b'SZAVDSKTHNQFWTTINRAYQKJAXTLD9CRFFWWBSEXIEXPLBBEP9FT9IVGICWIXTJCFUKJSTOUFANJGBTPQX')],
     'balance': 3828,
     'bundles': [<iota.transaction.base.Bundle object at 0x7f87d8de0390>,
                 <iota.transaction.base.Bundle object at 0x7f87d8dfc8d0>,
                 <iota.transaction.base.Bundle object at 0x7f87d8da8160>,
                 <iota.transaction.base.Bundle object at 0x7f87d8d97860>,
                 <iota.transaction.base.Bundle object at 0x7f87d8e03cf8>,
                 <iota.transaction.base.Bundle object at 0x7f87d949b320>,
                 <iota.transaction.base.Bundle object at 0x7f87d8de4780>,
                 <iota.transaction.base.Bundle object at 0x7f87d8de2470>,
                 <iota.transaction.base.Bundle object at 0x7f87d8e06908>,
                 <iota.transaction.base.Bundle object at 0x7f87d8def048>,
                 <iota.transaction.base.Bundle object at 0x7f87d8dea6a0>,
                 <iota.transaction.base.Bundle object at 0x7f87d8dbe198>,
                 <iota.transaction.base.Bundle object at 0x7f87d8df42e8>]}

    Yes, there are some tokens available! hurray

*Please note: API call `get_account_data` consider only confirmed transactions while calculating total balance. So it is better to wait until all transactions are cleared before you send additional tokens.*

Are there any tokens left (value in `balance` field)? If yes then continue - no action is needed.
If not, then you need to obtain some. It can be done visiting [IOTA faucet](http://faucet.devnet.iota.org) and entering an unused address of the given seed:

```python
# Now let's find a first unused address that can be used as a destination address for unspent/new tokens

print("\nPlease note, this may take some time if many addresses has been used already...")
FreeAddressSender = api.get_new_addresses(index=30,
                                          count=None, # If None is specified, then it identifies a first non-used address
                                          security_level=2) # Let's generate an address using default security level=2.

print("\nThis is the first unused address that can be used for new tokens or unspent tokens:")
pprint(FreeAddressSender)

```

    Please note, this may take some time if many addresses has been used already...

    This is the first unused address that can be used for new tokens or unspent tokens:
    {'addresses': [Address(b'MHJIRKPUVSXBZWUXKUBNT9MRSEG9CRR9DNKIVNSCBZVGEDIDYTXIAVJLSTKQGVGDBFHRCRHBEMMZXPUFZ')]}

What have just happened behind the curtain?
* The PyOTA library started to generating addresses from the `index=0` of the given seed and at the same time it also checked whether there are any transactions registered for each address
* If yes, then in case we are after balances, the balance is saved. In case we are after new unused address then the given address is skipped. First address for which there are not registered transactions is returned
* That's why it may be quite time consuming. And now you also understand all issues regarding `zero balances` after the snapshot

You may be also wondering how to get individual balances for each used address? This can be checked using the core API call `get_balances` which provides you with a balance for any address you specify. Let's query for used addresses from the previous exercise:

```python
# only if there is any used addresses from the previous steps

# it returns the balances as a list in the same order as the addresses were provided as input.
if len(SenderBalance['addresses'])>0:
    print("\nSome positive balance identified. Individual confirmed balances per used addresses:")
    pprint(api.get_balances(addresses=SenderBalance['addresses'],
                           threshold=100) # Confirmation threshold; official docs recommend to set it to 100
           )
else:
    print("\nNo positive balance identified.")
```

    Some positive balance identified. Individual confirmed balances per used addresses:
    {'balances': [0, 0, 0, 0, 0, 0, 0, 0, 0, 2979, 849],
     'duration': 1,
     'milestone': None,
     'milestoneIndex': 1366125,
     'references': ['BZXG9BLWNISGNFNUNPAZGPURMJUIAQPUAGAQJFVWOSTHINBVWVNGLWPKHI9WTAORCGUPCBCNHNIEQH999']}

It returns `balances` and you can see how the remaining tokens move to new unused address every time you spend some tokens. Needless to say, used addresses with zero balances should not be used anymore since tokens were already spent from them. So let's spend some tokens:

```python
tx1 = iota.ProposedTransaction( address = iota.Address(AddressReceiver), # 81 trytes long address
                                message = None,
                                tag     = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'),
                                value   = 10) # we are going to spend 10i

# Sending the iotas
print("\nSending iotas... Please wait...")
SentBundle = api.send_transfer(depth=3,
                         transfers=[tx1], # one transaction defined above. It is an output TX that adds tokens
                         inputs=None, # input address(es) that are used to finance the given transaction. Tokens will be deducted from them
                         change_address=None, # this is the adddress to which unspent amount is sent
                         min_weight_magnitude=9, # in case of Devnet it is 9
                         security_level=2) # you need to specify security level to be sure library generate compatible addresses

# you may be wondering why there is imputs=None and change_address=None.
# It means it will be taken care by library and so make sure correct seed / security level was added while api initialization

print("\nIt has been sent. Now let's see transactions that were sent:")
# let's check transactions that were sent in fact

print("Here is the bundle hash: %s" % (SentBundle['bundle'].hash))
for tx in SentBundle['bundle']:
    print("\n")
    pprint(vars(tx))

```

    Sending iotas... Please wait...

    It has been sent. Now let's see transactions that were sent:
    Here is the bundle hash: K9CRAOLBJCT9CEAKJVZIKUIIUSVKJIZGHXPJVYRDPJ9IFSUJPGRYECUCLIFKHLHVSE9ZSABLAUTXQ9HPD

    {'_legacy_tag': Tag(b'LUIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'BMFSMZMNBGKHAWPIZIOMJGRBXZETVSAYDSTDQCHLYTBWZMIXLNXF9XHLTMOCATFVFOMBQF9IOQGPEBPDC'),
     'attachment_timestamp': 1570539229755,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 3812798742493,
     'branch_transaction_hash': TransactionHash(b'FM9BAYPTXRETLTNOZJGDOZDVPNWTDFWHETXN9ALOXBOSJAKJZWCFIMAUNVFNEQHFCLELVBUKFKYIVO999'),
     'bundle_hash': BundleHash(b'K9CRAOLBJCT9CEAKJVZIKUIIUSVKJIZGHXPJVYRDPJ9IFSUJPGRYECUCLIFKHLHVSE9ZSABLAUTXQ9HPD'),
     'current_index': 0,
     'hash': TransactionHash(b'HELRSWQUGBEYVUYDHGHTTQRKHWPGVTTFCOCJUXPKTSTZIVKBNPKTFMUMWAYVRVRHEBBKCFFTWEOPTX999'),
     'is_confirmed': None,
     'last_index': 3,
     'nonce': Nonce(b'WONHBBPEDLHWRLGUPRFAWHDAEXB'),
     'signature_message_fragment': Fragment(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1570539041,
     'trunk_transaction_hash': TransactionHash(b'KXBVBYKXCKHNUWAWWINEENG9A9T99ZGRAPPKSZWCASHSENHTBGMHZYLHGLVXFNPYMPOGJUHRQXWLRJ999'),
     'value': 10}

    {'_legacy_tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'QYENROHVANIYBSIIMWGFDOUHXTMFOXIHOQXTJZLRFRJMOOINFTWCVVEJUFIITLBIHLVTESPVLUOSCFJDZ'),
     'attachment_timestamp': 1570539229722,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 3812798742493,
     'branch_transaction_hash': TransactionHash(b'FM9BAYPTXRETLTNOZJGDOZDVPNWTDFWHETXN9ALOXBOSJAKJZWCFIMAUNVFNEQHFCLELVBUKFKYIVO999'),
     'bundle_hash': BundleHash(b'K9CRAOLBJCT9CEAKJVZIKUIIUSVKJIZGHXPJVYRDPJ9IFSUJPGRYECUCLIFKHLHVSE9ZSABLAUTXQ9HPD'),
     'current_index': 1,
     'hash': TransactionHash(b'KXBVBYKXCKHNUWAWWINEENG9A9T99ZGRAPPKSZWCASHSENHTBGMHZYLHGLVXFNPYMPOGJUHRQXWLRJ999'),
     'is_confirmed': None,
     'last_index': 3,
     'nonce': Nonce(b'Q9AKQLCRMJCIHIBZCGJEFTFDCOY'),
     'signature_message_fragment': Fragment(b'FJVNAC9ELWJZKXB99BEWPEAYVWLTCERBQM9AQPLPMYUJTSLARUCASCOSZHMFXAYSMVTYHXFKZZODWCXIZIHOEFYO9YNSVUTIA9SAEMOUIJXIVUPDEAQLZPSP9JCREYPTDWMXTQYRQGDEW9QJJUBBIUEPUCEVMYTYPWPCETJAHHPUCSEGLIWQXNRNNGKEYFMVGTQZUDJJICXLQDUNDCWXIPAGXMAVUBSEYWRRYMFBNLPW9YAZJXXLTZJ9EUJREYMSWTYRHDLNZEIPEDFGYMATPOTAYGTYJVSMJQUFS99JTAPRELWRETRJSBNRCN9JQQFBBXPAGZSRDLPERRWKGCCYLBHWGNRNUYHQXKTMALZNCHFXEQLN9QYQYXJGTDINBGIECFNFQWTKCBELCSJYI9IB9TTNZILAOBKOGNERVGIZCUUNGUYLICKVVREVHEGTCLVCSRXLFUQUAQJUGP9QHOFYGSNLDVLDQKDPFSTOYZQEFFTPUNJQFSWKEWLZUKQTJ9DZHMPHRHY9ABEUMKFZBIS9OPBIU9GQJALZDISKAKWT9I9ZIJSIVMGIAGXYRHEYBQUMSXXZCUEOJKRKCEQWDXZJQRAKBCCVWSRQMSP9RUESTPHEY9XS9NVCHIJYZ9WMNDLKSZQWZHWZOKVRBEQECLOFORIK9DYUDNMXDZRPIEHGEBIORNRQAIFMZKFUYXMXRLTJMNDXEYTWC9OAJLRDFPDB9PVXDHETPFYLARGHCMFRYGKMXFQNCMN9NMNQXTEDLDKPAWCKOEK9KYCLVL9JTNUJCCNHJGDKAUZTJIXSKNFMMDFVGX9JHGDR9DNQQHYH9MEZAVXYJDDJAZWJRGVHBKLIVARKHBDECPH9ZTLSHDMLOWNMHLSFHAESHPACXYDQ9XCOXZGPORYL9DGYDLBDWQI9KYKCCAVB9SUIJIRWOCNWPZDFJLNRMERONTSJTXMRQHWDVERYITAHIF9YILTYDTUAJPAMDLPHNPZYCXYAAMXQUVLIYUKNKBFRBM99IYB9JJAREWYVKEOPPBNZAGHXYD9OVWYHBJKRYLTZLFQRNOBFVFEYSPZYHTEWRPPWMNGCRGVPZOYYDUFDLN9HCEWCFNZCTLFSRKJNPYEKRSDPDBHGHQTFMCRRGE9XSPVMWWHXSBPWNFJJMDLQVRNXLLJACLSWMEEMGDQANJRWPYSTEYYJPTGCVMTAIGZCPKTTZKOAXWYXYWUEUGB9PCCTEIDPLTYLGISOOPDGAHIMQSLPDYKEKWEQILLUPJUGOIT9THGR9LQAJQNAEDCCGEUQWJHDGRPDWNSLFHIU9RNHEUKEADSUMWUFESQTTCGBPYEAHKQLPGTPRQGQCL9BWHZKLFNLAVBIKQADHWNVIFLACAMXEKKSDPTDEW9DISRNXWTNMBRTGDOMZLDJBDKLLKJVCRXNCUBTW9OGF9QJCBQLZTLWDEFJN9EDFTPSYDPKMFUL9VDYYNBXPFDZCVYFLFCXXXOCETLOOUCWNKORHOSLDGLDXPUJRGH9YGWUKZUPHRBEQLLHQFLMZVWQGXXQCQTDYLWUPPSQTVBOHWQNAYZVZ9UAMBOUJEQIVLYPUCHVEEZPPEYIOUVBQJDSMREJS9FSBBNVHOMCASBTXVFINJFPMGQOKCIJZYNKNQFJ9NPQLCPM9BTCIVBUFWPUYYXWDGKDZEQBGEEFAEWWLZXQXASHVGY9BGFMFBGDSAKMZSQFCUJEKVQTEYKZ9TNXAXPWY9PIVGFFZJFDLDDWFALQANBF9BNGISCDUZNEDYVQ9GSIQAANIFCDHDKNPPKGPBATWZDJMTYKZPJFEXFM9EBDAGXPGUPUBXNKVXX9XWXUEVLRFUOVXKXURDK9ZG9FHLZZZ9JIM9HOHSMMRUOIP9AKPZRNAOOGIZYIOIMNPFLIRXURVGJZJVUIYQMNSSPOGEBBSUPEVZMUNDQSQCZCVVFEBIKUUZHMONG9DZMFSKOKENSPRQSKYIEKUXCPQGWVGWJEJNJEUFRRHOZJFFT9WGVUQCOURVLHIUELYFZOEFCCOKWNGDJYXBWNZFATDPZRDCXJD9YT9VRLAAPQXGWFNGFCUAFPUMGSNCJXPNCCGGBAZMWCVTQMEWZUYOVBQKICIWGXBSFWXGQYLPMGWHPHIQUASXNBQOGDXCTSZETRSGURCZJNTVEMTKRPGBKITGPHUXWRVFD'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1570539137,
     'trunk_transaction_hash': TransactionHash(b'DEKVWJZUMYHURTSQRZJMGZVZATELXYOGSUJTSSKNBPETPJZYCSN9WGCXQTANBAJDQQMXFMKJEITRBI999'),
     'value': -2979}

    {'_legacy_tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'QYENROHVANIYBSIIMWGFDOUHXTMFOXIHOQXTJZLRFRJMOOINFTWCVVEJUFIITLBIHLVTESPVLUOSCFJDZ'),
     'attachment_timestamp': 1570539229704,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 3812798742493,
     'branch_transaction_hash': TransactionHash(b'FM9BAYPTXRETLTNOZJGDOZDVPNWTDFWHETXN9ALOXBOSJAKJZWCFIMAUNVFNEQHFCLELVBUKFKYIVO999'),
     'bundle_hash': BundleHash(b'K9CRAOLBJCT9CEAKJVZIKUIIUSVKJIZGHXPJVYRDPJ9IFSUJPGRYECUCLIFKHLHVSE9ZSABLAUTXQ9HPD'),
     'current_index': 2,
     'hash': TransactionHash(b'DEKVWJZUMYHURTSQRZJMGZVZATELXYOGSUJTSSKNBPETPJZYCSN9WGCXQTANBAJDQQMXFMKJEITRBI999'),
     'is_confirmed': None,
     'last_index': 3,
     'nonce': Nonce(b'LYQCYVY9MIALVUHHTNQUAOVBZMZ'),
     'signature_message_fragment': Fragment(b'XJVSTWGWINBVVLAAZNSYQFAHKJIOVBBTHGHSFWXUKYO9QU9JYTXKCFCPLNHGAFHGYNRGP9ZIRLM9QI9JBPVYGGNUGWOO9LIYZRIPFRGQFDJBVPIMTBYDFVOHHAZXEHDY9ROBSOCCQEAMCODVAKJELMDA9SZFHXJWSXKLNXODY9GFGDPTTRSTJNIXRHUHVCJ99KPOVZVGDNBBJYIROBWJYIKKERYDPWLGBOGTPQEULYCD9JGBRQDBICHBNLBCSYFY9IT9PRKXCRGOVAF9XXXDM9ZHWYPNCSLYHMMKNPNBCWHTBAIDPJOZIFXMNPRLZTDHOGAYYBITYOSUQYTDUPLFCBXGQRWFQRPNNFZLGXERTPOORJZXJAXBIWRNOEOJKKKVTC9FLGKUVXQVRXOQQCDKXCEKMIKWWRLTKQBYHZMZZWLTAUHOUHXVFDSEHFTUHUYSLXXEGTZXLHKFUA9KACIQEHCVRVNWBZGFMOFSC9OWGPFATZMLYADGJYRARIRVYANWDVKMQCAAMVUOYDUIGQSZRRAUJSH9MDNIWZDQMTUSF9XGHZVCPBIQEJY9CEDYXROCPOQXF9XPUBYSIPBQDHB9QHJABIPILVIZMNGLWWGSOXLBICSMY9OHPBYKOBSXEFIYPOZLWDUXAWSLADZOF9SILPRYZKQKYKHTGZIJNJ9QBFIVFRNFNZAYYRAHMCHZJBMKUSDSKLEYXDIQASQPXLDAZDNVBXQZDADMQMYNHQQFXENTPRSBLBKFVFPPKNKXYIILMFWXYZZOLDFVAJCKQDDQNVYANQNG9DHKRSKMUOAYDDC9AHENC9RGHJXPH9OYLQZAKVRZFDOEQFQGBXZMKOEZQIYDJNNHHMDQXVEXBNBDDPQAJJDXIWFFGQATSW9WABRSYBPGGILGX9GSTJRXUNOTGPIFAUDATTFMXBCG9SGTIIIUGGMYNGKBDKSJXBIAIBFNR9TFEXLRCXTWWWMJIGCSGFAHRFFYACSWAGM9VZSHL9QZ9SSWMQGUPPFE9HWZWIXGHNACPTXRGPJUVK9DYPWEICZKPMCDAPYYPZJKLPWBKKT99APKTQICCKGZIWYNKPMNRYWVDBTEGJLCCIIXGXQVKOSUBJUPZJFCIMED9ROCOZQBDXEOTZAHJGHWUDGWBXCCUTMSMRREYPWJIQSGOIPHODFTUM9BSZGHPXYRJETJUEFXIICWFTWKXSKGKTWARKCQLYBIQHDDMVJF9LJOGBNZINDNUZQKNDAWZHBIISVCVDJGSJAQ9VASOSCDPMBLFSDHHAXMAKCJXIMVDNRYEPJFKJDICTRZDZWMQIZEPNWZDHZQHWWMMWFSDMRFSYLNNOMTAVKLEINGPYMFANWWLVYBTAGVSPJOMBWBZHEWXPBQUOWPUPACOQHPTA9DAHIRJKWTT9LLARKJIDMWXJNNGRPQQMFREIYXVLPELQAMIOGJ9CLOWRBYXWL9RUTDS9HQQWOFOSVWIQOYZBEDTBYLRL9SXPSCGDZJJWSBYBLKVIVVTTLIPVYZOCWMRYTTRYTA9UAIYMBPZZVJLVBJSRGKTMHCVAOSIFM99BQAUXKEWNCQLHGCUJSXLAJWAUMEYJZEEWATAGAWQPMMVTIPFQHXLORDHLOL9YMBUX9KWAZMFECXOLATKLVNYAOEYFBGTZDAZCJVSXLQIOZTHJXWDLOUBCOJFIVVRUIMXJHSRKPLBCQAAVVFYEHWKXXCMFUUP9VFU9EFFIDYUO9EVLPHIMOFDLTBVNRRLTLBDJOCWBZCSKXSIFZT9UZXQWTM9C9MLGRX9AIVCSAHEBGUBWPCCKBKUHQXDKYUQRK9NDTPPTRCBRGTIFNQCEEFFYNCDWINFPCNTISELIKFEF9CJBFDHOLKBVZNLJJFGLHAWMMURTNFLVJAOAOQEZKM9DQXEVNSPBMXGVCCWNKICEMJNWC9XDFLKVKZWPECGHOTIXG9ENJNBSQFKLKCNPG9LADRSOJIAEXPAQKUNQMMXM9ARQNT9GUWHJEEZNTQDVDNZOE9ABOTUWJTCYYOMSTOXXCBVEMODRKFKO9ANDKBYFRITYZ9LTJKELWSYCEYPOPGMUHJUYFVDLWMDZOKR9WDQLMIMH9IUXQJGQROXDJDJNJHQAYYURURTRHECNGPRUAQIK99YA9EU9MSEABDGJGLIHJDMQUSNTKZRCORVYIXWFPHKVX'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1570539137,
     'trunk_transaction_hash': TransactionHash(b'AYRWHKRNVKYQTPRBEOLHDBTIPEVNNGUJKKFHR9HZYUP9XZPMBTOKEXCJXLAWXODKBXGNGIWEUMEGX9999'),
     'value': 0}

    {'_legacy_tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'address': Address(b'MHJIRKPUVSXBZWUXKUBNT9MRSEG9CRR9DNKIVNSCBZVGEDIDYTXIAVJLSTKQGVGDBFHRCRHBEMMZXPUFZ'),
     'attachment_timestamp': 1570539229688,
     'attachment_timestamp_lower_bound': 0,
     'attachment_timestamp_upper_bound': 3812798742493,
     'branch_transaction_hash': TransactionHash(b'FM9BAYPTXRETLTNOZJGDOZDVPNWTDFWHETXN9ALOXBOSJAKJZWCFIMAUNVFNEQHFCLELVBUKFKYIVO999'),
     'bundle_hash': BundleHash(b'K9CRAOLBJCT9CEAKJVZIKUIIUSVKJIZGHXPJVYRDPJ9IFSUJPGRYECUCLIFKHLHVSE9ZSABLAUTXQ9HPD'),
     'current_index': 3,
     'hash': TransactionHash(b'AYRWHKRNVKYQTPRBEOLHDBTIPEVNNGUJKKFHR9HZYUP9XZPMBTOKEXCJXLAWXODKBXGNGIWEUMEGX9999'),
     'is_confirmed': None,
     'last_index': 3,
     'nonce': Nonce(b'MOFCEZUIRTEEDUOGYSKIQT9JIFC'),
     'signature_message_fragment': Fragment(b'999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'),
     'tag': Tag(b'HRIBEK999IOTA999TUTORIAL999'),
     'timestamp': 1570539226,
     'trunk_transaction_hash': TransactionHash(b'FM9BAYPTXRETLTNOZJGDOZDVPNWTDFWHETXN9ALOXBOSJAKJZWCFIMAUNVFNEQHFCLELVBUKFKYIVO999'),
     'value': 2969}

Let's review all transactions that has been prepared and sent eventually:
* The first transaction `current_index=0` is the `output TX` that basically adds tokens to some address
* Transactions `current_index=1` and `current_index=2` are two parts of the same transaction - `Input TX`. This transaction deducts tokens from the address(es). You can see negative `value` in the transaction `current_index=1`
* Why there are two parts? Since the transaction spends tokens it has to be signed in order to validate the ownership. Signature is generated from the private key and the signature can be observed in the field `signature_message_fragment`. Here is the thing. Do you remember when different `security levels` were discussed? There are three security levels available and the given level has the direct impact on length of the signature. Since `signature_message_fragment` is of the fixed size, if `SL>1` then the transaction has to be split to be able to accommodate full signature.
* The last transaction `current_index=3` moves unspent tokens to the first unused address of the given seed.

The following tasks have to be done behind the curtain in addition to the standard transaction preparation process:
* Search for address(es) with some balance until total amount of tokens available is large enough to be spent. You can use more input addresses if needed
* If there would be some unspent amount of tokens then also search for the first unused address
* Spending transactions (Input TX) has to be properly signed and split in case of `SL>1`
* There is also some quick check performed whether resulting number of tokens is zero (no more tokens, no less tokens. Number of tokens has to be balanced).

So basically all steps we tried in the chapter had to be done also behind the curtain while using `send_transfer` extended API call. You can also see that some of those operations may be quite expensive in terms of time while being completely stateless. In real world applications it would be better to save some states (index of last address, used addresses, etc.) to avoid too many expensive operations.

You can review the given broadcasted transactions also in the tangle explorer (for devnet):
* https://devnet.thetangle.org/address/BMFSMZMNBGKHAWPIZIOMJGRBXZETVSAYDSTDQCHLYTBWZMIXLNXF9XHLTMOCATFVFOMBQF9IOQGPEBPDC