Skip to main content

Ethereum EIP20 Token Interface

Project description

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

It is currently in Alpha, with 0 automated tests



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


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.symbol()

>>> omg.decimals()

>>> omg.totalSupply()

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

Custom methods

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

>>> omg.token_balance("ethereumfoundation.eth")

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(
  10 ** 9,
    '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.

Files for ethtoken, version 0.0.1a4
Filename, size File type Python version Upload date Hashes
Filename, size ethtoken-0.0.1a4-py3-none-any.whl (4.1 kB) File type Wheel Python version 3.6 Upload date Hashes View
Filename, size ethtoken-0.0.1a4.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page