Derive Macro SolidityError

Source
#[derive(SolidityError)]
Expand description

Allows an error enum to be used in method signatures.

sol! {
    error InsufficientBalance(address from, uint256 have, uint256 want);
    error InsufficientAllowance(address owner, address spender, uint256 have, uint256 want);
}

#[derive(SolidityError)]
pub enum Erc20Error {
    InsufficientBalance(InsufficientBalance),
    InsufficientAllowance(InsufficientAllowance),
}

#[public]
impl Contract {
    pub fn fallible_method() -> Result<(), Erc20Error> {
        // code that might revert
    }
}

Under the hood, the above macro works by implementing From<Erc20Error> for Vec<u8> along with printing code for abi-export.