Solidity Flashcards

1
Q

What is Solidity?

A

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/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the basic syntax of a solidity contract?

A

pragma solidity VERSION_HERE;

contract CONTRACT_NAME {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the basic syntax of a function in solidity?

A

function FUNCTION_NAME() public returns(DATA_TYPE memory) {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which keyword is used if a function is not changing any data in solidity?

A

view is used to ensure that a function won’t change any value e.g.

function get() public view returns(string memory) {
     return "test";
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s the syntax of constructor in solidity?

A

constructor() public {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to define constants in solidity?

A

By using constant keyword e.g. string public constant value = “my value”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some other basic datatypes in solidity?

A

boolean as bool, integer as int, unsigned integer as uint, unsigned 8 int as uint8, unsigned 256 int as uint256

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to create an enum in solidity?

A

enum State { Waiting, Running, Active }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to create structs in solidity?

A

struct Person {
string firstName;
string lastName;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to create an array in solidity?

A

DATA_TYPE[] public NAME; e.g. Person[] public people;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to add an item in array in solidity?

A

array. push(DATA_HERE);
e. g.
people. push(Person(“Shakeel”, “Shahzad”));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to create an associate array in solidity?

A

mapping(DATA_TYPE => VALUE) public NAME;

e.g.

mapping(uint => Person) public people;
people[1] = Person(“Shakeel”, “Shahzad”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly