Namely, could somebody shed some light on how the following things are implemented? What are the cornerstones of the implementation?

1) A piece of software (e.g., a wallet) finds out what the current balance of a particular address is.

2) A piece of software (e.g., a wallet) sends some amount of tokens from address A to address B, which results in this amount being subtracted from balance A and added to balance B.

2 Answers 2


The theory

IOTA uses the UTXO model to represent transactions. It means that the balance of a given address is defined as:

balance of address ADR = (sum of all "inputs" to ADR) - (sum of all "outputs" tx from ADR)

In practice, IOTA network make snapshots. After a snapshot: transaction history is lost (or at least the fullnode don't need to keep it in it's database). Instead of the full history: the balance of every address at snapshot time is the new starting point. Every address with non-zero balance is then seen as a genesis address. Therefore the balance of an address is :

balance of address ADR = 
      (initial amount on ADR at snapshot time) 
    + (sum of all "inputs" to ADR) 
    - (sum of all "outputs" tx from ADR)

The implementation

Be sure to understand that a snapshot (from a coding perspective) is as simple as a huge Map (i.e. a set of key-value pairs) where keys are the addresses, and values are the amount of iota on the address.

Implementation details can be found in code but, as far as I understand, the idea is to update the snapshot (locally on the full node) by applying all transactions approved by a milestone every time a milestone is received.

So getting the balance of an address is as simple as looking into the updated snapshot

(of course this is done on a fullnode, the light-wallet simply use the GetBalances API to request this data)

  • Ok, and how can all outputs from a particular address be obtained? From what data structure are they extracted? Because it seems unlikely they’re extracted directly from the tangle…
    – new_xxx
    Commented Feb 1, 2018 at 12:23
  • @new_xxx This data is in the database of the fullnode. The database of the fullnode IS the tangle (or at least the local view of the tangle since last snapshot). So getting those values is just a query on this DB (if you look into details, there are "in memory caching" mechanisms to avoid too many database access).
    – ben75
    Commented Feb 1, 2018 at 12:32
  • If this data is retrieved directly from the tangle, it means that the tangle should be stored in such a way that it's efficient to retrieve this data from it... Obviously, it requires certain optimizations of the storage. Ok, if so, I get it.
    – new_xxx
    Commented Feb 1, 2018 at 13:09
  • A small remark: in my first comment above, the phrase “all outputs from a particular address” should’ve been replaced with “all unspent outputs of a particular address”.
    – new_xxx
    Commented Feb 1, 2018 at 13:19
  • Also, should an unspent output be represented by a “confirmed” transaction for this output to be taken into consideration while calculating the balance (meaning an “unconfirmed” transaction won’t work in this context)? If so, what does “confirmed” mean in this context: just directly confirmed by some newer transaction or sufficiently deep in the tangle (that is, directly confirmed by some newer transaction and indirectly confirmed by other more recent transactions)? If it’s the former, isn’t it too insecure?
    – new_xxx
    Commented Feb 1, 2018 at 13:20

Current Balance of an Address

1) Get all the transaction that is addressed to Address A (confirmed) and add them up.

2) For example Address A (Bob's wallet) has two deposit 10 iota and 20 iota. Send 5 iota to address B (Alice wallet).

The Transaction Bundle should look like this

  1. Withdraw 10 Iota from Address A, Withdraw 20 Iota from Address A
  2. Sent/Deposit 5 Iota to Address B (Alice's wallet)
  3. Send 0 Iota to Address A.
  4. Send 15 Iota to Address X (this is a new address that belongs to Bob's wallet).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.