core.classes.erc_20
ERC20 Objects
class ERC20(BaseContract[TokenERC20])
get
def get() -> Currency
Get the token metadata including name, symbol, decimals, etc.
token = contract.get()
print(token)
Returns:
token metadata
balance
def balance() -> CurrencyValue
Get the token balance of the connected wallet.
balance = contract.balance()
print(balance)
Returns:
balance of the connected wallet
balance_of
def balance_of(address: str) -> CurrencyValue
Get the balance of the specified wallet
address = "{{wallet_address}}"
balance = contract.balance_of(address)
print(balance)
Arguments:
address
: wallet address to check the balance of
Returns:
balance of the specified wallet
total_supply
def total_supply() -> CurrencyValue
Get the total minted supply of the token.
Returns:
total minted supply of the token
allowance
def allowance(spender: str) -> CurrencyValue
Get a specific spenders allowance of this token for the connected wallet.
spender = "{{wallet_address}}"
allowance = contract.allowance(spender)
Arguments:
spender
: wallet address to check the allowance of
Returns:
allowance of the connected wallet
allowance_of
def allowance_of(owner: str, spender: str) -> CurrencyValue
Get the allowance of the specified spender for a specified owner.
# Address of the wallet who owns the funds
address = "{{wallet_address}}"
# Address of the wallet to check the token allowance
spender = "0x..."
allowance = contract.allowance_of(address, spender)
print(allowance)
Arguments:
owner
: wallet address whose assets will be spentspender
: wallet address to check the allowance of
Returns:
allowance of the specified spender for the specified owner
is_transfer_restricted
def is_transfer_restricted() -> bool
Check whether transfer is restricted for tokens in this module.
Returns:
True if transfer is restricted, False otherwise
transfer
def transfer(to: str, amount: Price) -> TxReceipt
Transfer a specified amount of tokens from the connected wallet to a specified address.
# Address to send tokens to
to = "0x...
# Amount of tokens to transfer
amount = 0.1
contract.transfer(to, amount)
Arguments:
to
: wallet address to transfer the tokens toamount
: amount of tokens to transfer
Returns:
transaction receipt of the transfer
transfer_from
def transfer_from(fr: str, to: str, amount: Price) -> TxReceipt
Transfer a specified amount of tokens from one specified address to another.
# Address to send tokens from
fr = "{{wallet_address}}"
# Address to send tokens to
to = "0x..."
# Amount of tokens to transfer
amount = 0.1
contract.transfer_from(fr, to, amount)
Arguments:
fr
: wallet address to transfer the tokens fromto
: wallet address to transfer the tokens toamount
: amount of tokens to transfer
Returns:
transaction receipt of the transfer
set_allowance
def set_allowance(spender: str, amount: Price) -> TxReceipt
Sets the allowance of the specified wallet over the connected wallets funds to
a specified amount.
spender = "0x..."
amount = 100
contract.set_allowance(spender, amount)
Arguments:
spender
: wallet address to set the allowance ofamount
: amount to set the allowance to
Returns:
transaction receipt of the allowance set
transfer_batch
def transfer_batch(args: List[TokenAmount])
Transfer tokens from the connected wallet to many wallets.
from thirdweb.types.currency import TokenAmount
data = [
TokenAmount("{{wallet_address}}", 0.1),
TokenAmount("0x...", 0.2),
]
contract.transfer_batch(data)
Arguments:
args
: list of token amounts and addressed to transfer to
Returns:
transaction receipt of the transfers
burn
def burn(amount: Price) -> TxReceipt
Burn a specified amount of tokens from the connected wallet.
amount = 0.1
contract.burn(amount)
Arguments:
amount
: amount of tokens to burn
Returns:
transaction receipt of the burn
burn_from
def burn_from(holder: str, amount: Price) -> TxReceipt
Burn a specified amount of tokens from a specified wallet.
holder = "{{wallet_address}}"
amount = 0.1
contract.burn_from(holder, amount)
Arguments:
holder
: wallet address to burn the tokens fromamount
: amount of tokens to burn
Returns:
transaction receipt of the burn