Skip to main content
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
24 votes
Accepted

How can I slice bytes, strings, and arrays in Solidity?

Solidity 0.6.0 and Greater (Updated 2020) As of Solidity 0.6.0, there is array slice functionality built into Solidity. The syntax is similar to existing languages in that the array takes the ...
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
17 votes
Accepted

Is it possible to deploy a contract using create2 in Solidity?

Yes. Solidity version 0.6.2 introduced a high-level way to use the create2 opcode. From the release docs: When creating a contract, you can specify the salt as a "function call option": new ...
Shane Fontaine's user avatar
9 votes
Accepted

How to reset the length of array in solidity v6.0?

I think that'll do it. pragma solidity 0.6.1; contract TestNode { uint[] nodes; function createNode(uint data) public { delete nodes; // This should reset the length to zero ...
Rob Hitchens's user avatar
  • 55.4k
9 votes
Accepted

Can anyone explain how bytes memory can be converted to address type in solidity

The expression add(bys, 32): Returns a pointer to the actual data, which starts after the first 32 bytes in the bys array (those first 32 bytes contain the length of the bys array). The expression ...
goodvibration's user avatar
8 votes

Solidity ^0.6.0 Truffle Compile Error: Cannot read property ... of undefined

Turn out that Truffle v5 versions earlier than v5.1.5 won't successfully compile ^0.6.0 solidity contracts, because the solc wrapper Truffle used (directly from solc-js) was only compatible with ^0.5....
linoleparquet's user avatar
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
7 votes

How to reset the length of array in solidity v6.0?

Since v0.6.0 you can not resize array.length. Member-access to length of arrays is now always read-only, even for storage arrays. It is no longer possible to resize storage arrays by assigning a new ...
ARR's user avatar
  • 95
7 votes

Got scammed using bad code to create front running bot

I've seen this before, and I've already answered it. Check here: Missing Eth after sending to contract The UniswapFrontrunBot contract that you shared is a scam. Unfortunately, your funds are lost ...
Jeremy Then's user avatar
  • 4,619
5 votes
Accepted

Solidity 0.6.0 address(this).balance throws error invalid opcode

I managed to fix it by explicitly defining the EVM version in my truffle config file. It's still weird because Remix supports this (as seen in the attached image) as well but still fails. compilers:...
Chris's user avatar
  • 1,302
5 votes
Accepted

can anyone explain why call, delegateCall, staticCall functions in solidity are called low level functions?

They allow you to perform dynamic invocation (instead of static invocation) of a contract function. This is similar to reflection in Java, where you execute a function using the function name string. ...
goodvibration's user avatar
5 votes
Accepted

Is "type" a reserved keyword in Solidity?

Yes, type is a reserved keyword in Solidity, according to the source code. However, according to the docs, type is not a reserved keyword. With that said, the reason it is reserved is for deriving ...
Shane Fontaine's user avatar
5 votes

NotFoundError: Key not found in database [hn]

I encountered the same error when solving the same Ethernaut level. I'm using Remix IDE. When I changed from deploying with JavaScript VM to deploying with Injected Web3 (there's a dropdown menu in ...
SmilingHeretic's user avatar
4 votes

Error: Transaction was not mined within 750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!

This is a legitimate scenario, and it is typical to cases where transactions with a higher gas price than yours have been submitted around the same time as yours. You can extend your code to check ...
goodvibration'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
4 votes
Accepted

Calling super class external functions

Turns out this is not possible. Inheriting functions and attempting to call the parent class version is deemed as an internal call. Since an override would replace the entry point for the overridden ...
Shiri's user avatar
  • 796
4 votes

delegatecall call internal functions from caller contract

No, it's not possible. Delegatecall simply calls the function inside the context of the current contract. It's like saying "Run function A and do whatever you want in MY storage". It has ...
odysseas lamtzidis's user avatar
3 votes
Accepted

Overriding a function

The virtual function must be in a parent contract. The override function must be in a child contract. Now you have both the functions in the same contract.
Mikko Ohtamaa's user avatar
3 votes

Is it possible to deploy a contract using create2 in Solidity?

Yes. Solidity version 0.6.2 you can do it
kavlit's user avatar
  • 31
3 votes

Can anyone explain how bytes memory can be converted to address type in solidity

You may meet the following code in many projects: contract A { event Log(address addr); function() external { emit Log(bytesToAddress(msg.data)); } function bytesToAddress(...
k06a's user avatar
  • 3,036
3 votes
Accepted

Do we have 'null' keyword in solidity?

No not at the moment but this keyword is reserved in Solidity in latest document. They might become part of the syntax in the future. Check this link
Haseeb Saeed's user avatar
3 votes

getting data from events

Using events to get return values from functions is not the same as using return in view/pure functions. In fact you shouldn't use the keyword returns when declaring a function that results in a ...
Peri Kost's user avatar
  • 172
3 votes
Accepted

What is the ':= ' operator?

It is the the variable assignment operator in Yul. From the docs: Variables can be assigned to after their definition using the := operator. It is possible to assign multiple variables at the same ...
alberto's user avatar
  • 3,343
3 votes

I wonder where this hack started from

TLDR : cancel your allowance for WETH to contract 0x9bf475e0654ec615b473599c9d39ddd87b01e894 and it wont happen again. https://polygonscan.com/address/0x9bf475e0654ec615b473599c9d39ddd87b01e894#code ...
Foxxxey's user avatar
  • 4,337
2 votes
Accepted

How to convert uint95 to bytes32 in solidity > 5.0?

Try this: bytes32 b = bytes32(uint256(data));
goodvibration's user avatar
2 votes
Accepted

Public variable getter shows as transaction in Remix

The problem is related to the ABI JSON produced by the compiler and how the tools use it to determine if a function is view or pure. As you can see in the docs: The fields constant and payable ...
alberto's user avatar
  • 3,343

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