Skip to content

Commit 1debc46

Browse files
committed
Add description to differentiate between token count / balance
1 parent aa951fc commit 1debc46

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

docs/examples.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,26 +329,33 @@ Fetch various data about the current state of the ERC20 contract.
329329

330330
.. code-block:: python
331331
332-
name = erc20.functions.symbol().name()
333-
# -> 🦄
332+
name = erc20.functions.name().call()
333+
# -> "Unicorns"
334334
symbol = erc20.functions.symbol().call()
335-
# -> 🦄
335+
# -> "🦄"
336336
decimals = erc20.functions.decimals().call()
337337
# -> 1
338338
total_supply = erc20.functions.totalSupply().call()
339339
# -> 2038 (at time of writing)
340340
341-
Get the balance of an account address. (token balance is *always* an integer)
341+
Get the balance of an account address.
342342

343343
.. code-block:: python
344344
345345
balance = erc20.functions.balanceOf('0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb').call()
346346
# -> 1
347347
348-
Calculate the token count from the token balance of an account address. (token count *may* be a fraction)
348+
Calculate the token count from the token balance of an account address.
349349

350350
.. code-block:: python
351+
352+
from decimal import Decimal
351353
352-
count = balance / (10 ** decimals)
354+
# Most applications expect *exact* results, so using the Decimal library,
355+
# with default precision of 28, is usually sufficient to avoid any rounding error.
356+
count = balance / Decimal(10 ** decimals)
353357
# -> 1
354358
359+
Balance is *always* an integer in the currency's smallest natural unit (i.e. `wei` for ether). Token balance is typically used only for backend calculations.
360+
361+
Token count *may* be a integer or fraction in the currency's primary unit (i.e. `eth` for ether). Token count is typically displayed to the user on the front-end since it is more readable.

0 commit comments

Comments
 (0)