Solidity CheatSheet
Solidity CheatSheet
CheatSheet
Created by JS Mastery
Boolean
Logical:
! Logical negation
&& AND
|| OR
Comparisons:
== equality
!= inequality
& AND
| OR
^ Bitwise XOR
~ Bitwise negation
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- Decrement
== equal to
!= Not equal to
= Simple Assignment
+= Add Assignment
-= Subtract Assignment
*= Multiply Assignment
/= Divide Assignment
%= Modulus Assignment
True or False.
Integer
This data type is used to store integer values,
int and uint are used to declare signed and
unsigned integers respectively.
Address
Address hold a 20-byte value which represents
the size of an Ethereum address. An address
can be used to get balance or to transfer a
balance by balance and transfer method
respectively.
Enums
It is used to create user-defined data types,
used to assign a name to an integral constant
which makes the contract more readable,
maintainable, and less prone to errors. Options
of enums can be represented by unsigned
integer values starting from 0.
Arrays
An array is a group of variables of the same
data type in which variable has a particular
location known as an index. By using the index
location, the desired variable can be accessed.
uint[] dynamicSizeArray;
uint[7] fixedSizeArray;
struct Book {
string title;
string author;
uint book_id;
import "filename";
or
return true;
public
variables)
private
external
internal
view
payable
anonymous
virtual
override
immutable
block.basefee (uint)
block.chainid (uint)
current chain id
block.difficulty (uint)
block.gaslimit (uint)
block.number (uint)
block.timestamp (uint)
remaining gas
msg.data (bytes
complete calldata
msg.sender (address)
msg.value (uint)
tx.gasprice (uint)
tx.origin (address)
assert(bool condition)
require(bool condition)
condition is false
condition is false
revert()
condition is false
this
or address payable
super
inheritance hierarchy
<address>.balance (uint256)
<address>.codehash (bytes32)
type(C).name (string)
type(I).interfaceId (bytes4)
type(T).min (T)
integer type T
type(T).max (T)
integer type T
argument
arguments.
four-byte selector
Equivalent to
abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)