Derive Macro ethers_contract_derive::EthAbiCodec
source · #[derive(EthAbiCodec)]
Expand description
Derives the AbiEncode
, AbiDecode
and traits for the labeled type.
This is an addition to EthAbiType
that lacks the AbiEncode
, AbiDecode
implementation.
The reason why this is a separate macro is the AbiEncode
/ AbiDecode
are ethers
generalized codec traits used for types, calls, etc. However, encoding/decoding a call differs
from the basic encoding/decoding, ([selector + encode(self)]
)
Example
ⓘ
use ethers_contract::{EthAbiCodec, EthAbiType};
use ethers_core::types::*;
#[derive(Debug, Clone, EthAbiType, EthAbiCodec)]
struct MyStruct {
addr: Address,
old_value: String,
new_value: String,
}
let val = MyStruct {..};
let bytes = val.encode();
let val = MyStruct::decode(&bytes).unwrap();