Derive Macro ethers_contract_derive::EthCall

source ·
#[derive(EthCall)]
{
    // Attributes available to this derive:
    #[ethcall]
}
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 = "...": Overrides the generated function name. Defaults to the struct’s name;
  • abi = "...": The ABI signature of the function.

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_contract_derive::EthCall;
use ethers_core::abi::{Address, FunctionExt};

#[derive(EthCall)]
#[ethcall(name = "my_call")]
struct MyCall {
    addr: Address,
    old_value: String,
    new_value: String,
}

assert_eq!(
    MyCall::abi_signature(),
    "my_call(address,string,string)"
);

Call with struct inputs

use ethers_core::abi::{Address, EventExt};
use ethers_contract_derive::EthCall;

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

#[derive(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(),
    "foo(address,(address,string),string)"
);