ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.96k stars 1.69k forks source link

Add an ERC20 balance check example to the docs #951

Closed carver closed 6 years ago

carver commented 6 years ago

What was wrong?

ERC20 is one of the most common use cases, and there are no explicit examples for interacting with them.

How can it be fixed?

Add a section to the Examples section of the docs that shows how to check the balance of a given token. The new section can be added at the end of this source: https://github.com/ethereum/web3.py/blob/master/docs/examples.rst

This section should show someone how to check their Unicorn token balance.

Rough approach:

  1. Show how to create a python contract object bound to the ERC20 Unicorn token (you can use the ABI from ethtoken linked below)
  2. Retrieve the token balance for an address 0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb appears to be the first address to have received a unicorn, so could be a good candidate.
  3. Show how to retrieve the decimals(), and how to adjust the token balance to get the token count: dividing by 10^decimals plus a brief explainer of the difference between the token balance and token count (token balance is always an integer, token count may be a fraction)

This repository has some example code that might be helpful if you're not sure how to connect to an ERC20 token: https://github.com/carver/ethtoken.py (You can footnote the repo if you want, but it's best to copy in anything that the reader might need).

ERC20 probably deserves its own whole page with different use case examples, but that is out of scope.

carver commented 6 years ago

@Karla-Isabel-Sandoval here is an idea for something that would help improve our docs.

pipermerriam commented 6 years ago

cc @njgheorghita as there should eventually be examples of how to do this with the ethpm tooling.