Erc20

class Erc20

Abstract

A subclass of SLContract specialized to handle contracts which conform to the Erc20 standard.

Integer vs. Decimal values

Integer values are the base denomination of a token, similar to Wei. Decimal values are the human readable denomination of a token, similar to Ether.

You can convert using Erc20.convert_to_decimal() or Erc20.convert_to_integer()

Constructor

Erc20(node, address=None)

Initialize an Erc20 by passing it the Node object.

The Erc20 must be fed an address, but you have options for how to do this:

Usually you will pass the string keyword arg address to the constuctor, or optionally you can subclass Erc20 and assign the address to constants such as MAINNET, ROPSTEN, KOVAN, and other etherum network names.

Example 1
contract_address='0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359'
''' then, get the node and...'''
token = Erc20(node, address=contract_address)

Properties

Erc20.decimal_balance

Returns the current address holder’s token balance, normalized in a human-readable Decimal. This is like getting the balance in Ether instead of in Wei.

Methods

Erc20.my_balance()

Returns the current address holder’s token balance, as an integer. This is like getting the balance in Wei instead of in Ether.

Erc20.totalSupply()

Returns integer value of the total supply.

Erc20.allowance(owner, proxy)

Returns integer value of tokens that address proxy is allowed to access on behalf of address owner.

Erc20.self_allowance(proxy)

Returns integer value of tokens that address proxy is allowed to access on behalf of the user’s current address.

Erc20.symbol()

Returns string symbol of token.

Erc20.decimals()

Returns integer number of decimals supported by token.

Erc20.balanceOf(target)

Returns integer value of tokens owned by address target.

Erc20.my_balance()

Returns integer value of tokens owned by user’s current address.

Erc20.convert_to_decimal(amount)

Returns decimal token value of integer amount

Erc20.convert_to_integer(amount)

Returns integer token value of decimal amount

Erc20.my_balance_str(length=18)

Returns string interpretation of user’s decimal token value, truncated to length characters.

Tx function generators

Erc20.approve(proxy_address, value)

Returns Tx function that will approve proxy_address to spend integer value amount of tokens on behalf of the current user address.

Erc20.approve_unlimited(proxy_address)

Returns Tx function that will approve proxy_address to spend an unlimited amount of tokens on behalf of the current user address.

Erc20.transfer(target, value)

Returns Tx function that will transfer integer value amount of tokens to address target