Solidity Flashcards

1
Q

Variable scope

A

public -> Can be used internally & externally. Automatically creates a getter function
external -> Meant to be called ONLY from other contracts ( state variables cannot be external )
internal -> Can only be called from within the contract or from derived ones
private -> Can only be called from within the contract - not even from derived ones

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

Pure function

A

int_a = 6

function square(uint 256 int_a) public pure {
       int_a * int_a
}

No cost to this functions; pure computation and not creating / changing any state variables. Not affecting the blockchain.

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

‘memory’ keyword

A

=> Only stored during execution of the function call

string person;

function assignName(string memory _name) public {
      person = name
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

mapping

A

A data structure -> hash table?

mapping(address => uint256) public addressToAmountFunded;

addressToAmountFunded[msg.sender] += msg.value;
// value associated with address increased every time. Not overwritten
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

‘payable’ keyword

A

In this function eth/wei is being transferred.

Whether it’s withdrawn or deposited.

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

‘msg’ keyword

A

In every contract. (Incoming call?)

msg. sender -> address from incoming function call [type address]
msg. value -> value associated with txn / call [type uint256]

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

nodes cannot do API calls because…

A

Because blockchains and smart contracts are deterministic systems. Nodes might call APIs at different times and get different results, and then wouldn’t be able to verify the other results.

Nodes can also not agree on a random number together

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

Oracle issue

A

An external oracle supplying data to the blockchain could represent a single point of failure - something which is completely avoided with blockchain otherwise

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

Variable types

A

State Variables − Variables whose values are permanently stored in a contract storage.

Local Variables − Variables whose values are present till function is executing.

Global Variables − Special variables exists in the global namespace used to get information about the blockchain.

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

Sender of the transaction [GV]

A

tx.origin (address payable)

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

Gas price of the transaction [GV]

A

tx.gasprice (uint)

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

Current block timestamp [GV]

A

now (uint)

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

First four bytes of the calldata (function identifier) [GV]

A

msg.sig (bytes4)

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

Complete calldata [GV]

A

msg.data (bytes calldata)

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

Remaining gas [GV]

A

gasleft() returns (uint256)

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

Current block timestamp as seconds since unix epoch [GV]

A

block.timestamp (uint)

17
Q

Current block number [GV]

A

block.number (uint)

18
Q

Current block gaslimit [GV]

A

block.gaslimit (uint)

19
Q

Current block difficulty [GV]

A

block.difficulty (uint)

20
Q

Current block miner’s address [GV]

A

block.coinbase (address payable)

21
Q

Hash of the given block - only works for 256 most recent, excluding current, blocks [GV]

A

blockhash(uint blockNumber) returns (bytes32)

22
Q

if (getConversionRate(msg.value) < minValueUSD) {
revert
}

=> Improve

A

require((getConversionRate(msg.value) < minValueUSD), “That ain’t enough dude!”);

2nd argument is error message

23
Q

‘this’ keyword

A

Refers to this contract.

E.g. address(this)
=> output address of the contract executing

24
Q

Globale variable: block
[list properties]

A

block.chainid => (uint): current chain id

block.number => (uint): current block number

block.timestamp => (uint): current block timestamp as seconds since unix epoch

25
Q
A