How to get the balance of an EOA address in sway

In std library, there are only methods to get the token balance of a ContractId with context::balance_of
How to get the balance of an Address in sway?


Great question! There is not a method to get the balance on an EOA address in Sway. However, this method is available in the Rust and TypeScript SDKs.

An EOA “balance” is just the sum over all UTXOs whose owner is the EOA in question. This cannot be queried in Sway, because it is not possible to inspect the UTXO set. You can, however, see the amount of coins sent in the transaction using the context::msg_amount method from the std library.


thank you!
another question. why is possible to get the contract balance in sway with context::balance_of?


Contract balances are stored in the contract’s balance tree (a sparse Merkle tree with asset IDs as keys and balances as leaf values). This can be thought of as contracts => account model, and EOA => UTXO model.


I am curious to know about the basics of fuel network:

  1. if contract’s balance data can be stored in a sparse merle tree with with the assetsIDs as keys and balances as leaf why not making an EOA sparse merkle tree then?

  2. I am not too familiar with the basic design of the EOA on fuel → is there any recommended starting point for a better understanding of fuel network setting (starting point of repos).

  1. The UTXO model has many advantages over the account model, like the ability to have multiple native assets (no need for approve+transferFrom, etc. ). You can read more about this in the Fuel Book:
    Parallel Transaction Execution - The Fuel Book
    VS EVM - The Fuel Book
  2. Can you clarify what you mean by “design of the EOA”? Are you referring to the UTXO model, or more practically like in a Sway contract? This section in the Sway Book might be helpful: Blockchain Types - The Sway Programming Language

I think i got it, bascially, for EOA since each EOA has many UTXOs thus its very hard to query the balance

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.