Derive Macro SolErrorMetadata

Source
#[derive(SolErrorMetadata)]
Expand description

Derives an implementation of ink::metadata::sol::SolErrorMetadata for the given struct or enum.

§Note

  • All field types (if any) must implement [ink::SolEncode].
  • The error representation derived is a Solidity custom error (or multiple Solidity custom error in the case of an enum, i.e. one for each enum variant).

§Example

use ink_macro::SolErrorMetadata;

// Represented as a Solidity custom error with no parameters
#[derive(SolErrorMetadata)]
struct UnitError;

// Represented as a Solidity custom error with parameters
#[derive(SolErrorMetadata)]
struct ErrorWithParams(bool, u8, String);

// Represented as a Solidity custom error with named parameters
#[derive(SolErrorMetadata)]
struct ErrorWithNamedParams {
    status: bool,
    count: u8,
    reason: String,
}

// Represented as multiple Solidity custom errors
// (i.e. each variant represents a Solidity custom error)
#[derive(SolErrorMetadata)]
enum MultipleErrors {
    UnitError,
    ErrorWithParams(bool, u8, String),
    ErrorWithNamedParams {
        status: bool,
        count: u8,
        reason: String,
    }
}