Build your own minimal token.
MinimalToken
. Add a mapping
to relate user addresses to the number of tokens they possess. Finally, add a variable to track totalSupply
:
Reveal code
constructor
that initializes the totalSupply
at 3000 and assigns ownership to the contract creator:
Reveal code
Reveal code
function
called transfer
that accepts an address
of _to
and a uint
for the _amount
. You don’t need to add anything for _from
, because that should only be msg.sender
. The function should subtract the _amount
from the msg.sender
and add it to _to
:
Reveal code
Note:
here is misleading. In the EVM, payable
only refers to transfers of the primary token used to pay gas fees: ETH, Base ETH, Sepolia ETH, Matic, etc. It does not refer to the balance of our simple token.
Instead, the transaction is reverting because of the built-in overflow/underflow protection. It’s not a great programming practice to depend on this, so add an error for InsufficientTokens
that returns the newSenderBalance
.
error
.
A
to B
. You’ll get an error:
0x0000000000000000000000000000000000000000
. This address is unowned and unownable, making it mathematically impossible to retrieve any tokens that are sent to it. Redeploy and try it out by sending 1000 tokens to the zero address.
The totalSupply
remains unchanged, and the balance of the zero address is visible, but those tokens are stuck there forever.