Skip to main content

Solidity Syntax Playground

Write, parse, and analyze Solidity smart contracts in your browser with real-time syntax highlighting and code analysis.

Solidity Editor23 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Countersolidity ^0.8.19
Functions(3)
increment()publicnonpayable
decrement()publicnonpayable
getCount()publicviewuint256
Events(1)
CountChanged(uint256 newCount)
State Variables(1)
countuint256public
Smart Analysis6 items
Consider `immutable` for count

The state variable "count" appears to be set only once. Marking it as `immutable` saves gas by embedding the value in bytecode.

Use `external` for increment()

"increment" appears to only be called externally. Using `external` instead of `public` saves gas because external functions can read arguments directly from calldata.

Use `external` for decrement()

"decrement" appears to only be called externally. Using `external` instead of `public` saves gas because external functions can read arguments directly from calldata.

Use `external` for getCount()

"getCount" appears to only be called externally. Using `external` instead of `public` saves gas because external functions can read arguments directly from calldata.

Use Custom Errors Instead of Require Stringsline 15

Custom errors (introduced in Solidity 0.8.4) are cheaper than require strings and provide better error information.

Contract Summary

Counter has 3 functions, 1 event, 1 state variable, and 5 total elements.

Fun Fact

Solidity function selectors are the first 4 bytes of the keccak256 hash of the function signature. That's how the EVM knows which function to call!