Solidity·Solidity essentials

Small token

Combine state, events and functions into a minimal token.

Intermediate 10 min read Lesson 5 of 150 Challenge included
What you will be able to do
  • Map balances.
  • Emit a transfer event.
  • Check balances before transfer.

In plain English

Combine state, events and functions into a minimal token.

  • Map balances.
  • Emit a transfer event.
  • Check balances before transfer.
Token.solSOLIDITY
pragma solidity ^0.8.24;

contract Token {
    mapping(address => uint256) public balanceOf;
    event Transfer(address indexed from, address indexed to, uint256 value);
    function transfer(address to, uint256 value) external {
        require(balanceOf[msg.sender] >= value, "balance");
        balanceOf[msg.sender] -= value;
        balanceOf[to] += value;
        emit Transfer(msg.sender, to, value);
    }
}
Your turn

Explain it back

Easy

Answer from memory: Which structure maps addresses to balances?

TEXT · starter
Your answer…
Check your understanding before moving on.
Knowledge checkQuestion 1

Which structure maps addresses to balances?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 5 of 150 · 0% of course