Skip to content

Instantly share code, notes, and snippets.

@CJ42
Created April 9, 2023 18:12
Show Gist options
  • Save CJ42/657e6b917b668c735a44ae0f3bd329b0 to your computer and use it in GitHub Desktop.
Save CJ42/657e6b917b668c735a44ae0f3bd329b0 to your computer and use it in GitHub Desktop.
Code snippet to show the different type of Solidity errors when debugging their selector (first 4 bytes of keccak256 hash of the error type string)
pragma solidity ^0.8.0;
contract SolidityErrors {
error InsufficientBalance(
uint256 amount,
uint256 balance
);
function testRevertErrorEmpty()
public
pure
{
revert();
}
function testRevertError()
public
pure
{
revert("something went wrong!");
}
function testPanicError(uint256 a)
public
pure
returns (uint256)
{
return 10 / a;
}
function testCustomError(uint256 amount)
public
view
{
revert InsufficientBalance(
amount,
address(this).balance
);
}
function testInvalid()
public
pure
{
assembly {
invalid()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment