Solidity Flashcards
What is Solidity?
Solidity is a contract driven, object-oriented, high level language to write smart contracts. It’s inspired by C++, Python & JS and runs on Ethereum Virtual Machine (EVM).
It’s a static typed language and supports inheritance, libraries and complex user-defined types.
https://docs.soliditylang.org/
What’s the basic syntax of a solidity contract?
pragma solidity VERSION_HERE;
contract CONTRACT_NAME {
}
What is the basic syntax of a function in solidity?
function FUNCTION_NAME() public returns(DATA_TYPE memory) {
}
Which keyword is used if a function is not changing any data in solidity?
view is used to ensure that a function won’t change any value e.g.
function get() public view returns(string memory) { return "test"; }
What’s the syntax of constructor in solidity?
constructor() public {
}
How to define constants in solidity?
By using constant keyword e.g. string public constant value = “my value”;
What are some other basic datatypes in solidity?
boolean as bool, integer as int, unsigned integer as uint, unsigned 8 int as uint8, unsigned 256 int as uint256
How to create an enum in solidity?
enum State { Waiting, Running, Active }
How to create structs in solidity?
struct Person {
string firstName;
string lastName;
}
How to create an array in solidity?
DATA_TYPE[] public NAME; e.g. Person[] public people;
How to add an item in array in solidity?
array. push(DATA_HERE);
e. g.
people. push(Person(“Shakeel”, “Shahzad”));
How to create an associate array in solidity?
mapping(DATA_TYPE => VALUE) public NAME;
e.g.
mapping(uint => Person) public people;
people[1] = Person(“Shakeel”, “Shahzad”);