Skip to main content

ERC20

Functionality available for contracts that implement the IERC20 interface.

allowance

Get the allowance of another wallet address over the connected wallet's funds.

"Allowance" refers to the number of tokens that another wallet is allowed to spend on behalf of the connected wallet.

# Address of the wallet to check token allowance
spender = "0x7fDae677aA6f94Edff9872C4b91D26407709c790"
allowance = contract.erc20.allowance(spender)
print(allowance)
Configuration

spender

The address of the wallet to check the allowance of.

Must be a string.

allowance = contract.erc20.allowance(
"{{wallet_address}}"
)

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

class CurrencyValue(Currency):
value: PriceWei
display_value: Price

allowance_of

The same as allowance, but allows you to specify the owner wallet to check, instead of using the connected wallet.

# Address of the wallet who owns the funds
address = "0x7fDae677aA6f94Edff9872C4b91D26407709c790"

# Address of the wallet to check the token allowance
spender = "0x..."

allowance = contract.erc20.allowance_of(address, spender)
print(allowance)
Configuration

owner

The address of the wallet that owns the funds.

Must be a string.

allowance = contract.erc20.allowance_of(
"{{wallet_address}}", # owner
"{{wallet_address}}" # spender
)

spender

The address of the wallet to check the allowance of.

Must be a string.

allowance = contract.erc20.allowance_of(
"{{wallet_address}}", # owner
"{{wallet_address}}" # spender
)

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

class CurrencyValue(Currency):
value: PriceWei
display_value: Price

balance

View the balance (i.e. number of tokens) the connected wallet has in their wallet from this contract.

balance = contract.erc20.balance()
print(balance)
Configuration

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

class CurrencyValue(Currency):
value: PriceWei
display_value: Price

balance_of

The same as balance, but allows you to specify the wallet address to check, instead of using the connected wallet.

# Address of the wallet to check token balance
address = "0x7fDae677aA6f94Edff9872C4b91D26407709c790"
balance = contract.erc20.balance_of(address)
print(balance)
Configuration

address

The address of the wallet to check the balance of.

Must be a string.

balance = contract.erc20.balance_of(
"{{wallet_address}}"
)

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

class CurrencyValue(Currency):
value: PriceWei
display_value: Price

get

Get the metadata of the token smart contract, such as the name, symbol, and decimals.

token = contract.erc20.get()
print(token)
Configuration

Return Value

class Currency:
name: str
symbol: str
decimals: int

set_allowance

Grant allowance to another wallet address to spend the connected wallet's funds (of this token).

# Address of the wallet to allow transfers from
spender = "0x...
# The number of tokens to give as allowance
amount = 100
contract.erc20.set_allowance(spender, amount)
Configuration

spender

The address of the wallet to grant allowance to.

Must be a string.

contract.erc20.set_allowance(
"{{wallet_address}}",
100
)

amount

The number of tokens to give as allowance.

Must be of type float.

contract.erc20.set_allowance(
"{{wallet_address}}",
100
)

total_supply

Get the number of tokens in circulation for this contract.

supply = contract.erc20.total_supply()
print(supply)
Configuration

Return Value

A CurrencyValue object is returned with the allowance available in the value property.

class CurrencyValue(Currency):
value: PriceWei
display_value: Price

transfer

Transfer tokens from the connected wallet to another wallet.

# Address to send tokens to
to = "0x...

# Amount of tokens to transfer
amount = 0.1

contract.erc20.transfer(to, amount)
Configuration

to

The address of the wallet to send the tokens to.

Must be a string.

contract.erc20.transfer(
"{{wallet_address}}",
0.1
)

amount

The amount of tokens to send.

Must be a float.

contract.erc20.transfer(
"{{wallet_address}}",
0.1
)

transfer_from

The same as transfer, but allows you to specify the wallet address to send the tokens from, instead of using the connected wallet.

This is only possible if the wallet initiating this transaction has been given allowance to transfer the tokens of the fromAddress.

# Address to send tokens from
fr = "0x7fDae677aA6f94Edff9872C4b91D26407709c790"

# Address to send tokens to
to = "0x..."

# Amount of tokens to transfer
amount = 0.1

contract.erc20.transfer_from(fr, to, amount)
Configuration

from

The address of the wallet to send the tokens from.

Must be a string.

contract.erc20.transfer_from(
"{{wallet_address}}",
"{{wallet_address}}",
1.2
)

to

The address of the wallet to send the tokens to.

Must be a string.

contract.erc20.transfer_from(
"{{wallet_address}}",
"{{wallet_address}}",
1.2
)

amount

The amount of tokens to send.

Can be a float.

contract.erc20.transfer_from(
"{{wallet_address}}",
"{{wallet_address}}",
1.2
)

transfer_batch

Transfer multiple tokens from the connected wallet to multiple wallets.

from thirdweb.types.currency import TokenAmount

data = [
TokenAmount("{{wallet_address}}", 0.1),
TokenAmount("0x...", 0.2),
]

tx_result = contract.erc20.transfer_batch(data)
Configuration
#### args

An array of objects, each containing a `toAddress` and an `amount` property.

- The `toAddress` property must be a `string`, and is the wallet address you want to send the tokens to.
- The `amount` property must be a `float`, and is the amount of tokens you want to send to the `toAddress`