foundry
foundry copied to clipboard
feat(cast run): try custom error decode from openchain signature database
Motivation
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract OwnerControlled {
address public owner;
uint256 private value;
event ValueChanged(uint256 newValue);
error Unknown(string str);
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
if(msg.sender != owner) {
revert Unknown("only Owner");
}
_;
}
function setValue(uint256 _newValue) public onlyOwner {
value = _newValue;
emit ValueChanged(_newValue);
}
function getValue() public view returns (uint256) {
return value;
}
}
in this contract, when tx revert by using custom error.
cast run result:
Executing previous transactions from the block.
Traces:
[2462] 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9::setValue(1)
└─ ← [Revert] custom error 7c45b126:
only Owner
Transaction failed.
Solution
I think we can make it more readable by using openchain's signature database online.
In this pr, custom err would look like:
Executing previous transactions from the block.
Traces:
[2462] 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9::setValue(1)
└─ ← [Revert] Unknown("only Owner")
Transaction failed.