Skip to main content
180 votes
Accepted

When should I use calldata and when should I use memory?

memory and calldata (as well as storage) are keywords that define the data area where a variable is stored. To answer your question directly, memory should be used when declaring variables (both ...
Shane Fontaine's user avatar
67 votes
Accepted

What are the virtual and override keywords in Solidity?

As of Solidity 0.6.0, the keywords virtual and override are available natively in Solidity for function overriding. The purpose of these keywords is to be more explicit when overriding a function. ...
Shane Fontaine's user avatar
60 votes
Accepted

What is the receive keyword in solidity?

TL;DR receive is a new keyword in Solidity 0.6.x that is used as a fallback function that is only able to receive ether. receive() external payable — for empty calldata (and any value) fallback() ...
Shane Fontaine's user avatar
32 votes
Accepted

What is the difference between the constant and immutable keywords in Solidity?

Both immutable and constant are keywords that can be used on state variables to restrict modifications to their state. The difference is that constant variables can never be changed after compilation, ...
Shane Fontaine's user avatar
28 votes
Accepted

What is the immutable keyword in Solidity?

The immutable keyword was added to Solidity in 0.6.5. State variables can be marked immutable which causes them to be read-only, but assignable in the constructor. The value will be stored directly in ...
Shane Fontaine's user avatar
23 votes
Accepted

Is it possible to perform a try-catch in Solidity?

Solidity 0.6.0 and Greater (Updated 2020) As of Solidity 0.6.0, there is try-catch functionality built into the language. The syntax is similar to existing languages, however functionality is limited ...
Shane Fontaine's user avatar
14 votes

When should I use calldata and when should I use memory?

memory variables are 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 ...
R01010010's user avatar
  • 281
7 votes

What is the difference between the constant and immutable keywords in Solidity?

In both cases, the variables cannot be modified after the contract has been constructed. a) For constant variables, the value has to be fixed at compile-time. b) For immutable, value can be assigned ...
Daniel Pham's user avatar
5 votes
Accepted

What is the difference between the abstract and virtual keywords in Solidity?

The abstract and virtual keywords signify that the associated code will be implemented or overridden elsewhere in the code. The main difference is that abstract applies to contracts and virtual ...
Shane Fontaine's user avatar
4 votes

What is the immutable keyword in Solidity?

The answer of the Shane is pretty accurate. To answer the question of the Qwerty: I was confusing the immutable with the constant. Here is the brief summary directly from the official Solidity ...
Oğuzhan ÖZTÜRK's user avatar
3 votes
Accepted

Are immutable variables part of the contract storage?

You are correct. The bar in this example will be stored in slot 0. The reason for this is because the compiler doesn't reserve a storage slot for constant/immutable variables, rather than copying the ...
Akall's user avatar
  • 463
1 vote

How to send Ethereum to smart contract address without using keyword "payable"?

In order for a smart contract to receive Ether from any kind of account, it has to have a payable function, otherwise it won't be able to receive coins.
Satoshi Nakamoto's user avatar
1 vote
Accepted

Is there an "in" keyword in Solidity similar to Python?

'in' is a Reserved Keyword. This keyword are reserved in Solidity. They might become part of the syntax in the future.Check this link But you can loop through an array/list in different way. Compared ...
Haseeb Saeed's user avatar
1 vote
Accepted

Why does Solidity not use the years keyword?

Solidity had the year keyword in all versions prior to 0.5.0. It was removed due to complications and confusions about leap years. From the Time Units section of the docs: Take care if you perform ...
Shane Fontaine's user avatar
1 vote

What is the difference between the constant and immutable keywords in Solidity?

about this: "b) For immutable, value can be assigned at construction time. They cannot be read during construction time and can only be assigned once." I can do this without problems. ...
Fernando López's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible