0% found this document useful (0 votes)
884 views1 page

Solidity Cheat Sheet

Solidity is a contract-oriented programming language for implementing smart contracts on the Ethereum blockchain. It is influenced by C++, JavaScript, and Python. Solidity supports data types like booleans, integers, addresses, and contracts. Contracts in Solidity are similar to classes in object-oriented languages and can inherit features from other contracts. Important concepts include ABI, WEI, global variables, and functions like transfer() for sending Ether.

Uploaded by

Rahan Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
884 views1 page

Solidity Cheat Sheet

Solidity is a contract-oriented programming language for implementing smart contracts on the Ethereum blockchain. It is influenced by C++, JavaScript, and Python. Solidity supports data types like booleans, integers, addresses, and contracts. Contracts in Solidity are similar to classes in object-oriented languages and can inherit features from other contracts. Important concepts include ABI, WEI, global variables, and functions like transfer() for sending Ether.

Uploaded by

Rahan Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Solidity Solidity Compiler

•Boolean:
Data Types

Important Terms
Voting: When the contract is quiet complex, it uses voting

C H E AT S H E E T true or false contract, it shows how delegated voting can be done so that vote
Logical: ! (Logical negation), && (AND) , || (OR) counting is automatic and completely transparent at the same time
Comparisons: == (equality), != (inequality) • Delegate call: It is a reusable library code that can be applied to a
contracts storage in solidity.
Solidity •Integer: Unsigned Integer, and Signed integer • Logs: A feature called logs is used in solidity to implement events.
Comparisons: <= (Less than or equal to), < (Less than), == (equal to), • NPM: It is a convenient and portable way to install Solidity
It is a contract-oriented high level language for implementing smart
!= (Not equal to), >= (Greater than or equal to), > (Greater than) compiler.
contracts. It was influenced by C++, JavaScript and Python and is
Arithmetic Operators: + (Addition), - (Subtraction), Unary –, Unary +, • Truffle: It is a test bed that will allow to easily test and compile the
designed to target the EVM
*(Multiplication), %( Division), ** (Exponential), << (Left shift), smart contract.
>>(Right shift) • Inheritance: In solidity inheritance is more syntactic. In the final
Contracts compilation the compiler copies the parent class members to
• Address: Holds an Ethereum address (20 byte value). create the bytecode of the derived contract with the copied
Contracts in solidity are similar to classes in object oriented ABI & WEI members.
language.
• ABI: A data encoding scheme called “Application Binary Operators: Comparisons: <=, <, ==, !=, >= and > • This: This is a keyword that refers to the instance of the contract
A contract can be created using “new” keyword.
Interface” (ABI) is used in for working with smart contracts. Balance: where the call is made.
• WEI: The smallest denomination or base unit of Ether • <address>.balance (unit256): balance of address in WEI • msg.sender: This function refers to the address where the contract
contract L {
Transfer and send: is being called from.
function add(uint _p, uint _q) returns (uint) {
• <address>.transfer(uint256 amount): send given amount of Wei • Pure: It is a modifier which assures not to be read from or modified
return _p + _q; Global Variables to Address, throws on failure • View: In solidity, view is a function that promises to not modify the
}
• <address>.send(uint256 amount) returns (bool): send given state of the contract.
} block.blockhash(uint numberOfBlock) returns (bytes32): hash
amount of Wei to Address, returns false on failure • Suicide: It is a alias for self destruct function, that is used to destroy
contract M { function of the given block which works for the 256 most recent
the current contract.
address p; blocks excluding the current block
•Global functions: • Delete: Delete is used to delete all elements in an array.
function f(uint _p) { block.coinbase (address): shows miner’s address of current block
• Block.coinbase(address): It refers to the miner’s address of the
p = new L(); block.number (uint): number of current block
• keccak256(…) returns (bytes32)- computes the ethereum SHA-3 current block.
} block.gaslimit (uint): gaslimit of the current block
hash associated with the arguments • Address(contractVar).send(amount): If a built-in send function
} block.timestamp (uint): timestamp of current block
• sha256(…) returns (bytes32) – Computes the SHA-256 argument needs to be used, it can be accessed using this function.
msg.gas (uint): the gas that remains
hash • Super: It is used to refer the contract that is higher by one level in
msg.value (uint): the amount of WEI sent along with the message
Smart Contracts • mulmod( uint a, uint b, uint c) returns (unit) : It computes the inheritance hierarchy.
msg.sender (address): address of the message sender (current call)
msg.sig (bytes4): first four bytes of the call data (a*b)%c, if the multiplication gets executed using arbitrary
It is a computer protocol which is used to streamline the process of precision, thus not wrapping around 2**256
contracts by digitally enforcing, verifying and managing them.
now (uint): timestamp for the current block Transaction Example
tx.origin (address): the sender of the transaction (whole call chain) • addmod(uint p, uint q, uint m) returns (uint): Computes
(p+q)%m
Remix, Solium& Doxity • ecrecover(bytes32 _hash, uint8 _v, bytes32 _r, bytes32 _s) Block<blocknumber>
Pragma returns (address): recovers the address linked with the public
• Remix: It is a browser based IDE with integrated compiler and key and if an error occurs, zero is returned Msg Msg
Used to specify certain conditions under which the source files can
solidity run-time environment without server side components. • ripemd160(…) returns (bytes20): computes the RIPEMD-160 tx.origin- 0x712 tx.origin – 0x712
or cannot run. msg.sender-0x712 msg.sender – 0x712
• Solium: A linter to identify and fix style security issues in solidity. Example:
(tightly packed) argument hash
msg.gas-10 msg.gas – 5
• Doxity: Used in solidity as a documentation generator. • <address>.balance (uint256) : Returns the balance of the
• pragma solidity ^0.2.32 From- 0x712 msg.value msg.value
specified address in WEI msg.data- 0x614 msg.data
This code compiles with a compiler function >=0.2.32 To-0x145
• <address>.send(uint256 amount) returns (bool): It sends the
Solograph & Assembly • A pseudocode example for pragma syntax Data -0x614
specified number of WEI to the address given, on failure it
'pragma' Identifier ([^;]+) ';'
returns false as an output
• Solograph: Used to visualize solidity control flow and highlight
• <address>.transfer(uint256 amount): Sends specified number of Contract 0x145 Contract2
potential security vulnerabilities.
WEI to the particular address, on failure throws { function
• Solidity Assembly: An assembly language which is used without Interface Contract2.myFuncti myFunction() {
solidity & inline assembly inside solidity source code on --
Interface in solidity are defined as contracts, but the function bodies •Access Modifiers:
are omitted for the functions. } }

Gas & Block Gas Limit Example: • Public: Accessible from the current contract, inherited contracts
pragma solidity ^0.22; and externally
• Gas: A measurement roughly equivalent to the computational interface Token • Private: Accessible only from the current contract
steps { • Internal: Accessible only from current contract and contracts
• Block Gas limit: It is used to control the amount of gas function transfer(address recipient, uint amount); inheriting from it
consumed during the transactions } • External: Can be accessed externally only FURTHERMORE:
Blockchain Certification Training

You might also like