Solidity CheatSheet
Solidity CheatSheet
Solidity CheatSheet
online IDE called Remix. With Remix, you can load the
about how Solidity works, this cheat sheet will give you
Boolean
Logical:
! Logical negation
&& AND
|| OR
Comparisons:
== equality
!= inequality
Data Types
Bitwise operators
& AND
| OR
^ Bitwise XOR
~ Bitwise negation
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- Decrement
Data Types
Relational Operators
== equal to
!= Not equal to
= Simple Assignment
+= Add Assignment
-= Subtract Assignment
*= Multiply Assignment
/= Divide Assignment
%= Modulus Assignment
Value Types
Boolean
This data type accepts only two values.
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.
Value Types
Bytes and Strings
Bytes are used to store a fixed-sized character
set while the string is used to store the
character set equal to or more than a byte. The
length of bytes is from 1 to 32, while the string
has a dynamic length.
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.
Reference Types
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;
Reference Types
Struct
Solidity allows users to create and define their
own type in the form of structures. The structure
is a group of different types even though it’s not
possible to contain a member of its own type.
The structure is a reference type variable which
can contain both value type and reference type
struct Book {
string title;
string author;
uint book_id;
}
Reference Types
Mapping
Mapping is a most used reference type, that
stores the data in a key-value pair where a key
can be any value types. It is like a hash table or
dictionary as in any other programming
language, where data can be retrieved by key.
import "filename";
or
return true;
public
variables)
private
external
internal
view
payable
anonymous
virtual
override
immutable
block.chainid (uint)
current chain id
block.difficulty (uint)
block.gaslimit (uint)
block.timestamp (uint)
remaining gas
msg.data (bytes
complete calldata
msg.sender (address)
tx.gasprice (uint)
tx.origin (address)
assert(bool condition)
revert()
this
<address>.balance (uint256)
type(C).name (string)
type(I).interfaceId (bytes4)
type(T).min (T)
type(T).max (T)
Equivalent to
abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)
Global Variables
bytes.concat(...) returns (bytes memory)
alias
apply
auto
byte
case
copyof
default
Reserved Keywords
define
final
implements
in
inline
let
macro
match
Reserved Keywords
mutable
null
of
partial
promise
reference
relocatable
sealed
Reserved Keywords
sizeof
static
supports
switch
typedef
typeof
var
Important Note
That’s all for this cheat sheet. This is not all the
things that Solidity offers, it offers a lot more.
- JavaScript Mastery
jsmasterypro javascriptmastery