Derive Macro ethers_contract::EthError

source ·
#[derive(EthError)]
{
    // Attributes available to this derive:
    #[etherror]
}
Available on crate feature abigen only.
Expand description

Derives the EthError and Tokenizeable trait for the labeled type.

Additional arguments can be specified using the #[etherror(...)] attribute:

For the struct:

  • name = "...": Overrides the generated error name. Defaults to the struct’s name;
  • abi = "...": The ABI signature of the error.

NOTE: in order to successfully parse the abi (<name>(<args>,...)), <name> must match either the struct’s name or the name attribute: #[ethcall(name = "<name>"]

§Examples

use ethers_core::abi::{Address, ErrorExt};
use ethers_contract_derive::EthError;

#[derive(Clone, EthError)]
#[etherror(name = "my_error")]
struct MyError {
    addr: Address,
    old_value: String,
    new_value: String,
}

assert_eq!(
    MyError::abi_signature(),
    "my_error(address,string,string)"
);