Skip to main content

Ethereum EIP20 Token Interface

Project description

This is a tiny library leveraging web3.py to make an interface for working with EIP20 tokens on Ethereum. (formerly ERC20)

It is currently in Alpha, with 0 automated tests

Usage

Install

virtualenv -p python3 venv
. venv/bin/activate
pip install --pre ethtoken

Initialize

from ethtoken import token

# Use the ENS name that points to your token contract here:
omg = token("omg.thetoken.eth")

Use standard EIP20 methods

Most EIP20 methods are optional. ethtoken makes no attempt to verify which methods are implemented by a token contract.

Here’s an example with all the read functions working:

>>> omg.name()
'OMGToken'

>>> omg.symbol()
'OMG'

>>> omg.decimals()
18

>>> omg.totalSupply()
140245398245132780789239631

# Use the ENS name of the owner address here:
>>> omg.balanceOf('ethereumfoundation.eth')
308744633639977714804

Custom methods

ethtoken has a single custom method not in the EIP20 spec: token_balance.

>>> omg.token_balance("ethereumfoundation.eth")
Decimal('308.744633639977714804')

It returns the balance of an address, with the decimal point shifted according to the decimals() value on the contract. In other words, it is the human-readable number of tokens that the given address owns.

Completely Untested: Transfers

In theory, you could use this to send a token. I haven’t even tried it once yet. Just don’t use it. If you’re going to ignore me, don’t blame me if you lose tokens or ether.

This should theoretically transfer 1 giga units from 0x0 to 0xdead. (That’s 1 nanotoken, at 18 decimals). Of course, this won’t work if you don’t control the 0x0 address. (hint: you don’t)

from web3 import Web3

>>> omg.transfer(
  '0x000000000000000000000000000000000000dEaD',
  10 ** 9,
  transact={
    'from': '0x0000000000000000000000000000000000000000',
    'gasPrice': Web3.toWei('0.1', 'gwei'),
  },
)

Ownership Disclosure

I own some OmiseGo tokens, because anyone who had some ether during their airdrop got some. I don’t have any opinions on the company or token.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ethtoken-0.0.1a3.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

ethtoken-0.0.1a3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file ethtoken-0.0.1a3.tar.gz.

File metadata

  • Download URL: ethtoken-0.0.1a3.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ethtoken-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 9e3781c084f6b4b54c9bb74db3d1f3cea909140ad6a832bf9f83870ca9588558
MD5 0e84f6bd5f7efd03e1cae1a38ab1be73
BLAKE2b-256 6f98f4cecb1e60df21532457d61304f5aa338707f73dfa8b5b98fa816c735a19

See more details on using hashes here.

File details

Details for the file ethtoken-0.0.1a3-py3-none-any.whl.

File metadata

File hashes

Hashes for ethtoken-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 5cb9b9360e9e4e4c6fc26997976c8f7b7a6e44dc35b7ce9964d10140e718ee6d
MD5 3e0c24056d0b2edab2f5b04fe7689d29
BLAKE2b-256 7b7977367fdc54e397cdf7e62d746b944628927907edbdeb04bd3adcd46bf187

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page