-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ERC20 example #995
Add ERC20 example #995
Conversation
Should the ethpm example eventually go here? or under the |
22285a7
to
aa951fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once eth-pm is on a stable release, then it can go in the general examples page. Until then, it should probably stay in the eth-pm-specific one.
docs/examples.rst
Outdated
.. code-block:: python | ||
|
||
name = erc20.functions.symbol().name() | ||
# -> 🦄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name should be Unicorns
docs/examples.rst
Outdated
|
||
.. code-block:: python | ||
|
||
count = balance / (10 ** decimals) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try Decimal()
instead of float
here, with a high enough precision to avoid any rounding error. Most applications expect exact results, even if fractional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finger slip, meant to explicitly request the Decimal
thing to be resolved.
1debc46
to
4070e94
Compare
docs/examples.rst
Outdated
|
||
Fetch various data about the current state of the ERC20 contract. | ||
|
||
.. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're willing to do this over an infura HTTP provider these could actually be doctested quite easily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool to get doctest against Infura working.
docs/examples.rst
Outdated
|
||
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. | ||
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of i.e.
(which means "in other words"). Since ether isn't an ERC20 token, this could be confusing. I would say something like (equivalent to 'eth' for ether)
aab8d43
to
46b0cc4
Compare
@carver I added doctest to the erc20 example, not sure if there's a better solution for using the Infura API key? Open to any suggestions or leaving as is. |
@njgheorghita Yeah, I assume you generated a fresh API key for this? Yeah, the key will have to be exposed somehow, in the source. But at least we can keep it from showing in the docs, by moving it to a test setup block: http://www.sphinx-doc.org/en/master/usage/extensions/doctest.html#directive-testsetup |
@njgheorghita you could also use an encrypted environment variable on circle-ci but that won't really save us since we allow CI to run on forks and thus, anyone can extract the environment variable simply by exporting it with custom code during a CI run.... |
docs/examples.rst
Outdated
>>> import os | ||
|
||
# Please play nice and don't use this key for any shenanigans, thanks! | ||
>>> os.environ['INFURA_API_KEY'] = "b2679bb624354d1b9a2586154651b51f" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to @carver suggestion to move this into a setup block so it doesn't show up in the actual documentation.
46b0cc4
to
c77a5db
Compare
c77a5db
to
7b50442
Compare
@carver Yup, generated a fresh key for this, happy to keep an eye on it for any abuse and regenerate if needed. Thanks for the setup tip, moved the key to a hidden block. Let me know if you'd like any other changes |
LGTM |
@carver 👍 If you're waiting on me, I don't have write access so pull the trigger anytime |
What was wrong?
No ERC20 example in docs.
fixes #951
How was it fixed?
Added an example showing how to interact with an erc20 contract.
Cute Animal Picture