create_token

Documentation for eth_defi.token.create_token function.

create_token(web3, deployer, name, symbol, supply, decimals=18)[source]

Deploys a new test token.

Uses ERC20Mock contract for the deployment.

See Web3.py documentation on Contract instances.

Example:

# Deploys an ERC-20 token where 100,000 tokens are allocated ato the deployer address
token = create_token(web3, deployer, "Hentai books token", "HENTAI", 100_000 * 10**18)
print(f"Deployed token contract address is {token.address}")
print(f"Deployer account {deployer} has {token.functions.balanceOf(user_1).call() / 10**18} tokens")

TODO: Add support for tokens with non-18 decimals like USDC.

Parameters
  • web3 (web3.main.Web3) – Web3 instance

  • deployer (str) – Deployer account as 0x address

  • name (str) – Token name

  • symbol (str) – Token symbol

  • supply (int) – Token supply as raw units

  • decimals (int) – How many decimals ERC-20 token values have

Returns

Instance to a deployed Web3 contract.

Return type

web3.contract.Contract