Class-19
Class 19 – Blockchain & Smart Contract Basics
Class Slides: Class 19.1
This lecture explores Ethereum addresses, their types, and associated functions, along with mappings in Solidity, which are crucial for efficient data storage and retrieval in smart contracts.
Key Topics Covered:
1. Ethereum Addresses
- An Ethereum address is a 20-byte unique identifier that represents an account or contract.
- It can hold either Externally Owned Accounts (EOAs) or contract account addresses.
- Addresses in Solidity have a
balanceproperty that shows the available funds in wei.
2. Types of Ethereum Addresses
- address: Standard Ethereum address.
- address payable: Special type that allows sending and receiving Ether.
3. Sending Ether in Solidity
Two key functions facilitate Ether transfers in Solidity:
- send(): Sends Ether but does not revert on failure, returning
falseinstead. - transfer(): Sends Ether and reverts the transaction if the transfer fails.
4. Mappings in Solidity
- Mappings are used to store key-value pairs, similar to hash tables or dictionaries.
- They allow quick lookups based on a unique key and are commonly used for storing user balances, permissions, and other contract data.
- Mappings do not have a length or iteration function, making them efficient but limited in terms of retrieval.
5. Nested Mappings
- Solidity allows mappings inside mappings, enabling more complex data structures.
- Example use cases include storing user permissions, ownership details, and role-based access control.
This lecture provides an understanding of Ethereum addresses, the mechanics of sending transactions, and the role of mappings in Solidity. These concepts are essential for developing efficient, secure, and scalable smart contracts.
