182
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 ...
70
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. ...
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() ...
33
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, ...
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 ...
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 ...
15
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 ...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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. ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
keyword × 17solidity × 16
solidity-0.6.x × 5
contract-development × 4
immutable × 3
transactions × 2
contract-invocation × 2
fallback-function × 2
state-variable × 2
virtual × 2
go-ethereum × 1
truffle × 1
remix × 1
tokens × 1
wallets × 1
addresses × 1
arrays × 1
mapping × 1
hash × 1
payable × 1
memory × 1
solidity-0.5.x × 1
timestamp × 1
calldata × 1
revert-opcode × 1