Module: token
A simple class to interact with ERC20 tokens.
Public Methods
balance_of(address: ChecksumAddress) -> Wei
: Get the balance of an address.transfer(to: ChecksumAddress, amount: Wei) -> TxReceipt
: Transfer tokens to an address.
Example
from web3.types import ChecksumAddress, Wei
from infernet_client.chain.rpc import RPC
from infernet_client.chain.token import Token
async def main():
rpc = RPC("http://localhost:8545")
token = Token("0x123456789012345678901234567890123, rpc)
balance = await token.balance_of("0x123456789012345678901234567890123")
token.transfer("0x123456789012345678901234567890123", Wei(100))
print(balance)
Token
Source code in src/infernet_client/chain/token.py
__init__(address, rpc)
Create a new Token instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
ChecksumAddress
|
The address of the token contract. |
required |
rpc |
RPC
|
The RPC instance to use for interacting with the chain. |
required |
Returns:
Type | Description |
---|---|
A new Token instance. |
Source code in src/infernet_client/chain/token.py
balance_of(address)
async
Get the balance of an address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
ChecksumAddress
|
The address to get the balance of. |
required |
Source code in src/infernet_client/chain/token.py
transfer(to, amount)
async
Transfer tokens to an address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to |
ChecksumAddress
|
The address to transfer tokens to. |
required |
amount |
Wei
|
The amount of tokens to transfer. |
required |
Returns:
Type | Description |
---|---|
TxReceipt
|
The transaction receipt. |