Skip to content

Instantly share code, notes, and snippets.

View CJ42's full-sized avatar

Jean Cvllr CJ42

View GitHub Profile
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract TryCatchNewContract {
string public hello;
function tryDeployingContract() public {
try new Target() returns (Target newContract) {
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract TryCatchExamples {
function tryCatchExternalCall(address target) public {
try Target(target).doSomething() returns (string memory) {
} catch {
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract UnimplementedFeatureError {
struct Vote {
uint256 optionId;
string value;
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract DeployedContract {
uint public result = 0;
function add(uint256 input) public {
result = result + input;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Warnings {
// all the lines below will return a warning
// ---
// Warning: This declaration shadows a builtin symbol.
string gasleft;
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
// We are missing to put the `requested` parameter name next to the `@param` tag.
// ---
// DocstringParsingError: Documented parameter "an" not found in the parameter list of the function.
/**
* @dev error when trying to transfer more `requested` amount than `available
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract PanicErrorExample {
function countTrailingZeroBytes(bytes32 data) public pure returns (uint256) {
uint256 index = 31;
// CHECK each bytes of the key, starting from the end (right to left)
// skip each empty bytes `0x00` to find the first non-empty byte
Compiler Error Description
Warning Warnings around potential bugs or security that can occur in the contract
ParserError Solidity code does not conform to the Solidity language rule
DocstringParsingError Cannot parse Natspec comments or Natspec blocks
SyntaxError Invalid Solidity syntax, such as using built-in keywords in the wrong lace
DeclarationError Cannot resolve to a variable, function or built-in symbol
TypeError Invalid types when assigning values to variables or variables to function or return parameters
UnimplementedFeatureError Occurs when using a syntax that is not yet supported by the Solidity compiler but planned to be in the future
error type error signature bytes4 error selector
String Error Error(string) 0x08c379a0
Panic Panic(uint256) 0x4e487b71
Custom Errors custom, based on the custom error definition based on the custom error name + its parameter types (if any)
Invalid none none
Error Code
(as uint256 hex number)
Description
0x00 Used for generic compiler inserted panics.
0x01 If you call assert with an argument that evaluates to false.
0x11 If an arithmetic operation results in underflow or overflow outside of an unchecked { ... } block.
0x12 If you divide or modulo by zero (e.g. 5 / 0 or 23 % 0)
0x21 If you convert a value that is too big or negative into an enum type.
0x22 If you access a storage byte array that is incorrectly encoded.
0x31 If you call .pop() on an empty array.
0x32 If you access an array, bytesN or an array slice at an out-of-bounds or negative index (i.e. x[i] where i >= x.length or i < 0).