Solidity Flashcards

1
Q

How to create a mapping

Solidity

A
mapping(_KeyType => _ValueType) myMapping;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are modifiers

A

Modifiers can automatically check a condition prior to executing the function.

function close() onlyOwner {
    selfdestruct(owner);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Types of functions

A

View or Constant Functions
- Functions can be declared view or constant in which case they promise not to modify the state, but can read from them.

Pure Functions
- Functions can be declared pure in which case they promise not to read from or modify the state.
- Operate on argument only.

Payable Functions
- Functions that receive Ether are marked as payable function.

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

Variable storage options

A

storage
- variable is a state variable (store on blockchain).

memory
- variable is in memory and it exists while a function is being called.
- Allocated by the callee and their value can be modified inside the function (they’re mutable).
- You can declare a variable inside a function memory located as well as it’s parameters.

calldata
- special data location that contains function arguments, only available for external functions.
- Value is allocated by the caller.
- No variables declared inside the function and no parameters of a function which is not external.

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

What are events

A
  • EVM logging facilities
  • Can be used to “call” JavaScript callbacks in the user interface of a dapp, which listen for these events.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe error handling

A
  • assert(bool condition): throws if the condition is not met - to be used for internal errors.
  • require(bool condition): throws if the condition is not met - to be used for errors in inputs or external components.
  • revert(): abort execution and revert state changes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly