Skip to main content

Lightweight Module to get Ethereum and ERC20 token balances

Project description

PyEtherBalance

pyetherbalance is a python module for getting Ethereum and er20 token balances. There are other modules like web3py out there, however the goal of this module is to be super light weight and not depend on too many other modules.

Installation

Simply clone the project and run python setup.py install - or install via pip pip install pyetherbalance.

This module only depends on the 'requests' library in python to send post requests

Basic Usage:

import pyetherbalance 
# Sign up for https://infura.io/, and get the url to an ethereum node
infura_url = 'https://mainnet.infura.543254324532543254345'
ethereum_address = '0xeb9f035dd1211af75976427d68d2d6dc549c458e'
# Create an pyetherbalance object , pass the infura_url
ethbalance = pyetherbalance.PyEtherBalance(infura_url)
# get ether balance
balance_eth = ethbalance.get_eth_balance(ethereum_address)
print(balance_eth)
# get token balance 
balance_omg = ethbalance.get_token_balance('OMG', ethereum_address)
print(balance_omg)

Advanced Usage:

Adding tokens

Currently the module uses https://github.com/ethereum-lists/tokens for a list of tokens. If you want to add your own custom token, you can follow the steps below. This will also work for overwriting internal token contract addresses.

import pyetherbalance 
# Sign up for https://infura.io/, and get the url to an ethereum node
infura_url = 'https://mainnet.infura.543254324532543254345'
ethereum_address = '0xeb9f035dd1211af75976427d68d2d6dc549c458e'
# Create an pyetherbalance object , pass the infura_url
ethbalance = pyetherbalance.PyEtherBalance(infura_url)
# New token symbol
token = "OMG"
# Token details. The fields below are all required
details = {'symbol': 'OMG', 'address': '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', 'decimals': 18, 'name': 'OmiseGO'}
# Add token 
erc20tokens = ethbalance.add_token(token, details)
# print list of all internal tokens
print(erc20tokens['OMG'])

Getting all tokens:

import pyetherbalance 
# Sign up for https://infura.io/, and get the url to an ethereum node
infura_url = 'https://mainnet.infura.543254324532543254345'
# Create an pyetherbalance object , pass the infura_url
ethbalance = pyetherbalance.PyEtherBalance(infura_url)
# Get a dictionary with all tokens and details 
erc20tokens = ethbalance.get_erc20_tokens()
print(erc20tokens)

Testing:

Test You can test on either Ropsten, Kovan, Rinkeby or local testnets by providing the url of your corresponding ethereum node, while initializing pyetherbalance object.

Copyright

MTI License - See LICENSE for details.

Changelog

Version 0.0.1

New

  • First Working Version

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

pyetherbalance-0.0.1.tar.gz (124.8 kB view details)

Uploaded Source

Built Distribution

pyetherbalance-0.0.1-py3-none-any.whl (129.9 kB view details)

Uploaded Python 3

File details

Details for the file pyetherbalance-0.0.1.tar.gz.

File metadata

  • Download URL: pyetherbalance-0.0.1.tar.gz
  • Upload date:
  • Size: 124.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for pyetherbalance-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3ab72404e32790f69ed4207f388f8693b50a41756c3102a615cbfe3a53d287c0
MD5 7c29d127b5feac3c856588433761822f
BLAKE2b-256 9ca56bab3ba914cc4af0835c5ddc2049b66bc119b3a486f0e0703932da0759bf

See more details on using hashes here.

File details

Details for the file pyetherbalance-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyetherbalance-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 129.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for pyetherbalance-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05776a268d3fe0077a000c7f0e3df0411177743f5316ded40f74218292346316
MD5 18d6f80f52358356a7ee0c20cc074438
BLAKE2b-256 3a61a22d94e286f12297b3427bfd32d6f3eb1531cf3aa3407ebc8ceca62d6be8

See more details on using hashes here.

Supported by

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