Solidity Fast Track 2: Continue Learning Solidity Fast
Continuing to learn Solidity fast with the advanced basics
Previously we learned all of the basics in 20 minutes. If you are a complete beginner, start there and then come back here. Now we'll explore some more advanced concepts, but again as fast as possible.

1. Saving money with events
We all know gas prices are out of control right now, so it's more important than ever that you learn the basics of how to use events. Events are not stored in a contract like regular storage, but rather in a special logs section of a transaction. So what is this special logs section?
Under the hood of events: Logs in Ethereum
Logs are an efficient way in Ethereum to check for specific data that's not required for the contract itself, but only for logging purposes. Examples on how those logs could be used are the web3.eth.subscribe functionality or The Graph. A bloom filter is used to improve the performance for Ethereum nodes. It basically works by hashing the specific log data, then computing modulo 2048. This is done for all logs in a given transaction (there's no limit to how many logs can exist in a single transaction).
The result will be a bunch of numbers in the range of 0 to 2047. You can create a bit array (bitmap) with mostly 0's, except on those indices where you got a number for in the previous step. Given this bitmap, a node can very efficiently check for logs in a transaction:
Looking for a specific event? Hash the event, compute the hash modulo 2048 and check if there's a 1 at this index in the bitmap. Most of the times there will be a 0, so we can quickly filter out most of the non-relevant transactions. If there's indeed a 1, we have to inspect the full logs array in detail. Since a max of 2047 numbers will mean some logs give us the same number, we'll have a 0.048% chance for a false positive. That's very low, so the overhead for false positives is close to 0.
After looking through the full logs array, we either find a match to the event we we're looking for and return the data or we don't and ignore this transaction.

Events in Solidity
Now that we understand the fundamentals behind events, how do you use them in Solidity?
contract MyContract {
event MyEvent(address indexed sender, uint256 timestamp);
function sendTransactionWithEvent() external {
emit MyEvent(msg.sender, block.timestamp);
}
}
You declare any event definitions at the beginning of the contract. Later you can emit events using the emit
keyword and passing all parameters to it. Pretty simple and cost effective.
What's the indexed
keyword?
You can add up to three parameters with the indexed keyword in one event type. Any indexed parameter will receive its own hashed place in the bitmap, meaning you'll be able to efficiently search for events with specific data in those three parameters.
2. Improving code readability with structs
A very important concept in Solidity are structs. They will allow you to greatly improve the readability of your code. Also since Solidity 0.7 the ABIEncoderV2 is the new default which fully supports structs, so you don't need to worry about passing structs to functions.
Consider our escrow example in the first fast track. It works only for one trade. We can change it to work for any number of traders by keeping the data separately using structs:
Before:
address public seller;
address public buyer;
address public arbitrator;
uint256 public purchasePrice;
uint256 public purchaseConfirmationCount;
uint256 public refundConfirmationCount;
mapping(address => bool) public hasConfirmedPurchase;
mapping(address => bool) public hasConfirmedRefund;
After:
struct EscrowTrade {
address seller;
address buyer;
address arbitrator;
uint256 purchasePrice;
uint256 purchaseConfirmationCount;
uint256 refundConfirmationCount;
mapping(address => bool) hasConfirmedPurchase;
mapping(address => bool) hasConfirmedRefund;
}
mapping(uint256 => EscrowTrade) public escrowTrades;
We can now create and access trades conveniently using a trade id. For example you may access the seller via escrowTrades[tradeId].seller
. Alternatively you can store the whole trade struct data in its own variable first and later use the data directly:
EscrowTrade memory escrowTrade = escrowTrades[tradeId];
address seller = escrowTrade.seller;
You'll see this pattern all the time in contracts, so make sure to get comfortable with it.
3. From EIPs to ERCs with the most popular example: ERC-20
One thing to understand is the difference between EIPs and ERCs. But first what are EIPs?
They stand for Ethereum Improvement Proposal and are just a repository on Github. Anyone can create such an EIP which is supposed to be for proposals regarding the core protocol specifications and client APIs. Very similar to that the ERC stands for Ethereum Request for Comments, the name coming from the RFCs internet standards. Those are proposals for smart contract standards.
As a beginner you probably don't need to care about EIPs too much. Some of them can have significant effects, such as EIP-1559, but only when it's actually implemented and used on Ethereum. By then you will likely read dozens of articles about it and what its implications are.
More interestingly are the ERC's which are standards that would be a good idea to follow in your contracts. Granted there are hundreds if not thousands of ERCs and not all of them are important. It can be tricky to find out which one to use.

Tthe Openzeppelin contracts are always a good reference. Let's now explore the most popular ERC of them all: ERC-20.
We already learned all the concepts in this and the previous post to build an ERC-20 contract. An ERC-20 contract is just a simple second currency (token) implementation on top of Ethereum where Ether is an existing implementation. Most popular might be the DAI token, which is a decentralized stable coin worth always about 1 USD.
At its core the the ERC-20 implementation is just this:
contract MyERC20Token {
mapping(address => uint256) public balanceOf;
function transfer(address to, uint256 amount) external returns (uint256) {
require(balanceOf[msg.sender] >= amount, "Not enough balance");
balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;
return true;
}
}
Pretty simple right? Now the actual standard further contains events, an approval mechanism, a totalSupply
function and a few optional fields. Take a look at the standard for the details. Most importantly here the approval mechanism allows to use tokens in smart contract calls:
Imagine Alice wants to use the SuperSmartContract which requires users to pay 10 DAI. Alice can approve the DAI calling DaiToken.approve(SuperSmartContract.address, 10)
and subsequently SuperSmartContract.use()
. Inside the use()
function, the contract can all DaiToken.transferFrom(msg.sender, address(this), 10)
and since Alice set the allowance previously, this call is now allowed to transfer money on behalf of Alice to himself.
- How to implement an ERC-20 using latest frameworks: https://soliditydeveloper.com/erc-2020/
- How to securely interact with existing ERC-20 contracts: https://soliditydeveloper.com/safe-erc20/
- Other token standards: https://soliditydeveloper.com/blog?tag=ERC-20
4. Libraries

Libraries are special contracts that have no storage, but can be used only for implementation code. There's two different forms of libraries, those with public functions and those only with internal functions. They both serve very different purposes.
First let's talk about libraries with only internal functions. This is the most common form for libraries. You'll see them in packages like Openzeppelin contracts, Uniswap's own library repo or the quite popular ds-math lib.. This is the kind of library that you would use to make your code more readable and I highly recommend you do this yourself whenever it makes sense. Combine this with the using for syntax for maximum benefits.
The simplest example, which with Solidity 0.8+ new safe math feature wouldn't be necessary anymore, would be:
contract MyContract {
using MyMathLib for uint256;
function returnSub(uint256 a, uint256 b) external returns (uint256) {
return a.safeSub(b);
}
}
The second form with public functions allows for reusability. To quote the Solidity documentation: 'Libraries are similar to contracts, but their purpose is that they are deployed only once at a specific address and their code is reused using the DELEGATECALL
.'
So in other words, those libraries can be reused by many projects. After all you might have a lot of standard code that would just be duplicated logic in the blockchain if each contract would have its own version of it. That's at least the theory, in practice honestly the use of reusable libraries hasn't really taken off. There is at least one project aiming to provide those: https://github.com/modular-network/ethereum-libraries. Otherwise, external libraries can also help to stay below the contract size limit.
Congratulations. You've mastered level 2.
- Inheritance: Solidity supports inheritance including polymorphism. A great way to structure your contracts.
- Hacks: Always a great way to learn about smart contract security.
- Downsizing contracts to keep below the max contract size (its own EIP-170 btw)
- Avoiding stack too deep errors
- Toolings
- Study more ERC's (+ EIPs)
- Best coding practices in general! My colleague has a great blog post about naming (important) and another great resource currently 66% discounted is the book Dive Into DESIGN PATTERNS. Or really any other book you can find. Solidity might be a bit strange due to running on the blockchain, but most programming concepts still apply of course.
Solidity Developer
More great blog posts from Markus Waas
How to use ChatGPT with Solidity
Using the Solidity Scholar and other GPT tips
How to integrate Uniswap 4 and create custom hooks
Let's dive into Uniswap v4's new features and integration
How to integrate Wormhole in your smart contracts
Entering a New Era of Blockchain Interoperability
Solidity Deep Dive: New Opcode 'Prevrandao'
All you need to know about the latest opcode addition
How Ethereum scales with Arbitrum Nitro and how to use it
A blockchain on a blockchain deep dive
The Ultimate Merkle Tree Guide in Solidity
Everything you need to know about Merkle trees and their future
The New Decentralized The Graph Network
What are the new features and how to use it
zkSync Guide - The future of Ethereum scaling
How the zero-knowledge tech works and how to use it
Exploring the Openzeppelin CrossChain Functionality
What is the new CrossChain support and how can you use it.
Deploying Solidity Contracts in Hedera
What is Hedera and how can you use it.
Writing ERC-20 Tests in Solidity with Foundry
Blazing fast tests, no more BigNumber.js, only Solidity
ERC-4626: Extending ERC-20 for Interest Management
How the newly finalized standard works and can help you with Defi
Advancing the NFT standard: ERC721-Permit
And how to avoid the two step approve + transferFrom with ERC721-Permit (EIP-4494)
Moonbeam: The EVM of Polkadot
Deploying and onboarding users to Moonbeam or Moonriver
Advanced MultiSwap: How to better arbitrage with Solidity
Making multiple swaps across different decentralized exchanges in a single transaction
Deploying Solidity Smart Contracts to Solana
What is Solana and how can you deploy Solidity smart contracts to it?
Smock 2: The powerful mocking tool for Hardhat
Features of smock v2 and how to use them with examples
How to deploy on Evmos: The first EVM chain on Cosmos
Deploying and onboarding users to Evmos
EIP-2535: A standard for organizing and upgrading a modular smart contract system.
Multi-Facet Proxies for full control over your upgrades
MultiSwap: How to arbitrage with Solidity
Making multiple swaps across different decentralized exchanges in a single transaction
The latest tech for scaling your contracts: Optimism
How the blockchain on a blockchain works and how to use it
Ultimate Performance: The Aurora Layer2 Network
Deploying and onboarding users to the Aurora Network powered by NEAR Protocol
What is ecrecover in Solidity?
A dive into the waters of signatures for smart contracts
How to use Binance Smart Chain in your Dapp
Deploying and onboarding users to the Binance Smart Chain (BSC)
Using the new Uniswap v3 in your contracts
What's new in Uniswap v3 and how to integrate Uniswap v3
What's coming in the London Hardfork?
Looking at all the details of the upcoming fork
Welcome to the Matrix of blockchain
How to get alerted *before* getting hacked and prevent it
The Ultimate Ethereum Mainnet Deployment Guide
All you need to know to deploy to the Ethereum mainnet
SushiSwap Explained!
Looking at the implementation details of SushiSwap
What's coming in the Berlin Hardfork?
Looking at all the details of the upcoming fork
Using 1inch ChiGas tokens to reduce transaction costs
What are gas tokens and example usage for Uniswap v2
Openzeppelin Contracts v4 in Review
Taking a look at the new Openzeppelin v4 Release
EIP-3156: Creating a standard for Flash Loans
A new standard for flash loans unifying the interface + wrappers for existing ecosystems
Tornado.cash: A story of anonymity and zk-SNARKs
What is Tornado.cash, how to use it and the future
High Stakes Roulette on Ethereum
Learn by Example: Building a secure High Stakes Roulette
How to implement generalized meta transactions
We'll explore a powerful design for meta transactions based on 0x
Utilizing Bitmaps to dramatically save on Gas
A simple pattern which can save you a lot of money
Using the new Uniswap v2 as oracle in your contracts
How does the Uniswap v2 oracle function and how to integrate with it
Smock: The powerful mocking tool for Hardhat
Features of smock and how to use them with examples
How to build and use ERC-721 tokens in 2021
An intro for devs to the uniquely identifying token standard and its future
Trustless token management with Set Protocol
How to integrate token sets in your contracts
Exploring the new Solidity 0.8 Release
And how to upgrade your contracts to Solidity 0.8
How to build and use ERC-1155 tokens
An intro to the new standard for having many tokens in one
Leveraging the power of Bitcoins with RSK
Learn how RSK works and how to deploy your smart contracts to it
Solidity Fast Track: Learn Solidity Fast
'Learn X in Y minutes' this time with X = Solidity 0.7 and Y = 20
Sourcify: The future of a Decentralized Etherscan
Learn how to use the new Sourcify infrastructure today
Integrating the 0x API into your contracts
How to automatically get the best prices via 0x
How to build and use ERC-777 tokens
An intro to the new upgraded standard for ERC-20 tokens
COMP Governance Explained
How Compound's Decentralized Governance is working under the hood
How to prevent stuck tokens in contracts
And other use cases for the popular EIP-165
Understanding the World of Automated Smart Contract Analyzers
What are the best tools today and how can you use them?
A Long Way To Go: On Gasless Tokens and ERC20-Permit
And how to avoid the two step approve + transferFrom with ERC20-Permit (EIP-2612)!
Smart Contract Testing with Waffle 3
What are the features of Waffle and how to use them.
How to use xDai in your Dapp
Deploying and onboarding users to xDai to avoid the high gas costs
Stack Too Deep
Three words of horror
Integrating the new Chainlink contracts
How to use the new price feeder oracles
TheGraph: Fixing the Web3 data querying
Why we need TheGraph and how to use it
Adding Typescript to Truffle and Buidler
How to use TypeChain to utilize the powers of Typescript in your project
Integrating Balancer in your contracts
What is Balancer and how to use it
Navigating the pitfalls of securely interacting with ERC20 tokens
Figuring out how to securely interact might be harder than you think
Why you should automatically generate interests from user funds
How to integrate Aave and similar systems in your contracts
How to use Polygon (Matic) in your Dapp
Deploying and onboarding users to Polygon to avoid the high gas costs
Migrating from Truffle to Buidler
And why you should probably keep both.
Contract factories and clones
How to deploy contracts within contracts as easily and gas-efficient as possible
How to use IPFS in your Dapp?
Using the interplanetary file system in your frontend and contracts
Downsizing contracts to fight the contract size limit
What can you do to prevent your contracts from getting too large?
Using EXTCODEHASH to secure your systems
How to safely integrate anyone's smart contract
Using the new Uniswap v2 in your contracts
What's new in Uniswap v2 and how to integrate Uniswap v2
Solidity and Truffle Continuous Integration Setup
How to setup Travis or Circle CI for Truffle testing along with useful plugins.
Upcoming Devcon 2021 and other events
The Ethereum Foundation just announced the next Devcon in 2021 in Colombia
The Year of the 20: Creating an ERC20 in 2020
How to use the latest and best tools to create an ERC-20 token contract
How to get a Solidity developer job?
There are many ways to get a Solidity job and it might be easier than you think!
Design Pattern Solidity: Mock contracts for testing
Why you should make fun of your contracts
Kickstart your Dapp frontend development with create-eth-app
An overview on how to use the app and its features
The big picture of Solidity and Blockchain development in 2020
Overview of the most important technologies, services and tools that you need to know
Design Pattern Solidity: Free up unused storage
Why you should clean up after yourself
How to setup Solidity Developer Environment on Windows
What you need to know about developing on Windows
Avoiding out of gas for Truffle tests
How you do not have to worry about gas in tests anymore
Design Pattern Solidity: Stages
How you can design stages in your contract
Web3 1.2.5: Revert reason strings
How to use the new feature
Gaining back control of the internet
How Ocelot is decentralizing cloud computing
Devcon 5 - Review
Impressions from the conference
Devcon 5 - Information, Events, Links, Telegram
What you need to know
Design Pattern Solidity: Off-chain beats on-chain
Why you should do as much as possible off-chain
Design Pattern Solidity: Initialize Contract after Deployment
How to use the Initializable pattern
Consensys Blockchain Jobs Report
What the current blockchain job market looks like
Provable — Randomness Oracle
How the Oraclize random number generator works
Solidity Design Patterns: Multiply before Dividing
Why the correct order matters!
Devcon 5 Applications closing in one week
Devcon 5 Applications closing
Randomness and the Blockchain
How to achieve secure randomness for Solidity smart contracts?