Skip to content

Commit 49b7bce

Browse files
GarmashAlexonbjerg
andauthored
docs: Add EIP-712 usage example to README (#975)
* Add EIP-712 usage example to README * Update crates/dyn-abi/README.md Co-authored-by: onbjerg <[email protected]> * Update README.md * Apply suggestion from @onbjerg * Apply suggestion from @onbjerg --------- Co-authored-by: onbjerg <[email protected]>
1 parent 69d5353 commit 49b7bce

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

crates/dyn-abi/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,35 @@ assert_eq!(encoded, my_data);
4848
EIP-712:
4949

5050
```rust,ignore
51-
todo!()
51+
use alloy_dyn_abi::eip712::TypedData;
52+
use alloy_sol_types::sol;
53+
54+
sol! {
55+
struct Person {
56+
string name;
57+
address wallet;
58+
}
59+
60+
struct Mail {
61+
Person from;
62+
Person to;
63+
string contents;
64+
}
65+
}
66+
67+
let sender = Person {
68+
name: "Cow".to_string(),
69+
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826".parse().unwrap(),
70+
};
71+
let recipient = Person {
72+
name: "Bob".to_string(),
73+
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB".parse().unwrap(),
74+
};
75+
let mail = Mail { from: sender, to: recipient, contents: "Hello, Bob!".to_string() };
76+
77+
let typed_data = TypedData::from_struct(&mail, None);
78+
let hash = typed_data.eip712_signing_hash().unwrap();
79+
assert_eq!(hash, b256!("25c3d40a39e639a4d0b6e4d2ace5e1281e039c88494d97d8d08f99a6ea75d775"));
5280
```
5381

5482
## How it works

0 commit comments

Comments
 (0)