General Solidity I Flashcards

1
Q

What is a mapping variable

A

A mapping is a data structure in solidity that associates a key with a value. Mappings can be used to store and retrieve data efficiently in smart contracts on the blockchain.

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

What is a struct

A

A struct is a user-defined data type that groups together variables of different data under the same name.
Struct Guns {
Bool Ak47;
Uint shots fired;
}

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

What is the difference between a uint and an int?

A

Unassigned intergers can only store positive values while signed intergers can store both a negative and positive value.

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

What is the visibility of public functions/variables in solidity?

A

Public functions/variables can be accessed externally or internally.

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

What is the visibility of internal functions/variables in solidity?

A

Internal functions/variables can be accessed internally or by derived/inherited contracts.

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

In solidity, what is a transaction? (writing)

A

A transaction is a message sent from one contract or account to another that modifies the state of the blockchain.

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

In solidity, what is a call? (Reading)

A

A call is a message sent from one smart contract to another that does not modify the state.

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

What is a “receive” function?

A

A recieve function is a payable function that is used to send value with no data attached.
recieve() external payable {

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

What is “unchecked {“ in solidity

A

It is used to disable run time checks for mathematical operations (over/underflow). Less relevant in new versions where patched.

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

What is over/under flow in solidity

A

Over/under flow was a feature in older versions of solidity that allowed numbers to wrap around after breaching their maximum/minimum value. It has uses, such as saving on gas in certain cases, but can also open contracts up to malicious attacks. In versions 0.8+, you can activate this feature by entering in “unchecked {“.

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

What is a “require” statement inside of solidity

A

A conditional statement that requires something to be true or it will revert, throw an error, and can add a string to let the user understand why the transaction failed. If triggered, the user will only lose the gas used up to the requirement.

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

What is an invariant violation in solidity?

A

An invariant violation occurs when a condition that should always be true is not true. For example, if a contract assumes that a certain variable will always have a value within a certain range, if it ends up somehow outside of that range, this would be an invariant violation.

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

What is assert in solidity, and when should it be used?

A

Assert checks for a condition to be true. If it is false, it will revert all changes made to the state of the contract. Unlike require, it will not return any gas. Assert would best be used to check for internal errors or invariant violations. It should not be used in any situation where it can be accidentally triggered. If we are setting parameters to validate user inputs or set function preconditions, we should use require instead.

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

When does Solidity automatically generate a getter function for a mapping variable?

A

When a mapping is declared to be public. If our mapping is private or internal, we must make our own. The automatically generated getter function will have the same name as the original mapping variable.
Ex: mapping(address => unit) public balances;
•The getter function generated would be called “balances” and take an address argument.

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

How can we access specific variables from a struct?

A

As an example:
struct Funder {
address addr;
uint amount;
}
We could then say:
Funder public _funder;
_funder.addr = 0x123
_funder.amount= 50000
(_funder.var inside of function tho)

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

What are instances in solidity

A

Instances are new instances of a contract with their own state and behavior/address added to the blockchain and interacted by, with other contracts or external users.
Typically utilizing the “new” keyword.

17
Q

What does changing the state mean?

A

In general, it refers to modifying the data stored on the blockchain. It costs more gas than reading from the chain.

18
Q

What is the difference between revert and require?

A

A require statement will return all gas not used after the require statement. A revert statement will consume all gas before and after.

19
Q

What are the differences between EOA’s and contract accounts?

A

•EOA’s are regular externally owned accounts controlled by a private key. EOA’s have a balance of eth and can initiate transactions on their own.
•Contract accounts are special accounts associated with a smart contract. They could be the owner of a token, for example, who might use this for the obvious added functionality. Or normal people who want to trade on a DEX.

20
Q

How can we tell the difference between an EOA and a smart contract address?

A

•EOA addresses will always start with a non-zero character. •Smart contract addresses may start with a 0 but do not have to. •In practice, when interacting with the eth network, most wallets/tools can automatically distinguish between the two. Some wallets and blockchain explorers may also provide additional relevant details to help identify the address type.

21
Q

What is the gas price in solidity? How does this affect a transaction?

A

The gas price is how much ether you are willing to spend to process a transaction. The more transactions being processed and the number of available miners at any given time will also affect the gas price. The more gas you are willing to pay to process a transaction, the quicker it will go through.

22
Q

Why do writing transactions not return a value? How can we still include a return value?

A

Writing transactions do not return a value because their transactions are not instantaneous. Considering confirmation time on a transaction may vary on network activity and other factors, it is difficult to know exactly when a transaction will be confirmed, or if it will simpily fail. We can still get a return value externally by using and emitting events. This will log the data where we can access the values elsewhere.

23
Q

What are the differences between ERCs and EIPs regarding Ethereum?

A

Ethereum Request for Comments is a formalized process for suggesting token standards to ensure interoperabillity/compatabillity with other Eth contracts/wallets.
Ethereum Improvement Proposals are proposals for Improving Ethereum protocal itself. Outlining changes/improvements/features at the protocal level to improve aspects of the Eth network itself.

24
Q

What is the difference between an “ownable” token contract and a token contract with “roles”?

A

Ownable contracts allow us to specify a single owner address with special privileges and access to certain restricted operations (IE: Transferring/Renouncing ownership)
Token contracts with roles, allow us to specify multiple different addresses to specific tasks/roles. We could declare a “minter” role to an address for instance, who has the abillity to mint new tokens.

25
Q

What are Open Zeppelin audited smart contracts? What are their purpose?

A

Open Zeppelin audited smart contracts essentially amount to reuseable smart contracts that have undergone an extensive security audit by independent experts. These reuseable smart contracts offer bug/exploit free code developers can use while developing their own project.

26
Q

What are ERC721 tokens?

A

The token standard for Non-Fungible Tokens (NFTs) where unlike an ERC20 token each ERC721 token is unique. Allowing each token in the contract to represent something specific.

27
Q

What are ERC20 tokens

A

Technical standard for implementing tokens on the Eth blockchain formalized in 2015. The ERC20 token was the 20th Ethereum Request for Comments introduced by a team of devs to encourage token interoperabillity/compatibillity across eth contracts/wallets. Each token is identical and the token is treated like it’s own entity running off the Ethereum network.

28
Q

What is a “library” for in solidity?

A

A seperate type of contract inside of a contract, that is internal in visibillity and stateless in nature. The functions inside of a library (Ex: SafeMath) .add + .sub, act as reusable bits of code, that can be reused in inherited contracts in the same/seperate file. While internal functions can do this also, Libraries save on gas in that, they are deployed seperately from the “parent contract” and are only ever deployed once. The code is never duplicated even when inherited in a new file.

29
Q

What are named imports, and how are they written?

A

Named imports allow us to import specific smart contracts from a file.
* import {contract1} from “src/groupOfContracts.sol”;

30
Q

What are ERC1155 contracts?

A

A token structure allowing developers to mint a theoretically unlimited amount of fungible and NFTs within the same contract.