Derive Macro ethers_contract::EthCall

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

Derives the EthCall and Tokenizeable trait for the labeled type.

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

For the struct:

  • name, name = "...": Overrides the generated EthCall function name, default is the struct’s name.
  • abi, abi = "...": The ABI signature for the function this call’s data corresponds to.

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

Example

use ethers_contract::EthCall;

#[derive(Debug, Clone, EthCall)]
#[ethcall(name ="my_call")]
struct MyCall {
    addr: Address,
    old_value: String,
    new_value: String,
}
assert_eq!(
    MyCall::abi_signature().as_ref(),
    "my_call(address,string,string)"
);

Example

Call with struct inputs

use ethers_core::abi::Address;

#[derive(Debug, Clone, PartialEq, EthAbiType)]
struct SomeType {
    inner: Address,
    msg: String,
}

#[derive(Debug, PartialEq, EthCall)]
#[ethcall(name = "foo", abi = "foo(address,(address,string),string)")]
struct FooCall {
    old_author: Address,
    inner: SomeType,
    new_value: String,
}

assert_eq!(
    FooCall::abi_signature().as_ref(),
    "foo(address,(address,string),string)"
);