This repository contains a minimalistic implementation of an ERC-20 token contract using Yul. The contract includes basic ERC-20 functionalities such as transferring tokens, approving allowances, and querying balances. It also has a minting function restricted to the contract owner.
The contract is written in Yul, an intermediate language for the Ethereum Virtual Machine (EVM). It leverages low-level operations to provide efficient and gas-optimized token functionality.
- Token Transfers: Transfer tokens to other addresses.
- Allowance Mechanism: Approve third-party addresses to transfer tokens on behalf of the token holder.
- Minting: Mint new tokens to any address, restricted to the contract owner.
- Query Functions: Check balances and allowances.
- Event Emissions: Emits standard ERC-20 events (
Transfer
andApproval
).
Returns the balance of the specified address.
- Selector:
0x70a08231
- Parameters:
address
- the address to query the balance for.
Returns the total supply of the token.
- Selector:
0x18160ddd
- Parameters: None
Transfers amount
tokens to the specified to
address.
- Selector:
0xa9059cbb
- Parameters:
to
- the recipient address.amount
- the amount of tokens to transfer.
Transfers amount
tokens from the from
address to the to
address using the allowance mechanism.
- Selector:
0x23b872dd
- Parameters:
from
- the address to transfer tokens from.to
- the recipient address.amount
- the amount of tokens to transfer.
Approves the spender
address to spend amount
tokens on behalf of the caller.
- Selector:
0x095ea7b3
- Parameters:
spender
- the address allowed to spend tokens.amount
- the amount of tokens to be approved for spending.
Returns the remaining number of tokens that the spender
will be allowed to spend on behalf of owner
.
- Selector:
0xdd62ed3e
- Parameters:
owner
- the address owning the tokens.spender
- the address allowed to spend tokens.
Mints amount
tokens to the account
address. Only callable by the contract owner.
- Selector:
0x40c10f19
- Parameters:
account
- the address to receive the minted tokens.amount
- the amount of tokens to mint.
To deploy the contract, use the following steps:
- Compile the Yul code to bytecode.
- Deploy the bytecode to the Ethereum network using a deployment tool (e.g., Remix, Hardhat, Truffle).
Emitted when tokens are transferred, including zero value transfers.
- Signature:
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
- Indexed Parameters:
from
- address sending the tokens.to
- address receiving the tokens.
- Non-Indexed Parameters:
amount
- the amount of tokens transferred.
Emitted when the allowance of a spender
for an owner
is set by a call to approve
.
- Signature:
0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925
- Indexed Parameters:
owner
- address that owns the tokens.spender
- address allowed to spend the tokens.
- Non-Indexed Parameters:
amount
- the amount of tokens approved.
- Slot 0: Contract owner address.
- Slot 1: Total supply of tokens.
- Slot 0x1000 and above: Token balances of addresses.
- Keccak256 hash of account and spender addresses: Allowances for each
owner
-spender
pair.
- Ownership: The mint function is restricted to the contract owner.
- Zero Address Checks: Transfers to the zero address are disallowed.
- Safe Arithmetic: Uses safe addition and subtraction to prevent overflow and underflow.
This project is licensed under the MIT License. See the LICENSE file for details.