From 6242e31d325144f3f64a64c99e5362eaf129cb02 Mon Sep 17 00:00:00 2001 From: Mulandi <89155182+CECILIA-MULANDI@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:47:28 +0300 Subject: [PATCH] fix(docs): Fix event type definitions to use H160 for ink! v6 compatibility ## Summary Corrects the Events documentation to use `H160` type for account addresses, resolving type mismatch errors when developers follow the examples in ink! v6. ## Problem The current documentation shows event definitions using `AccountId`: ```rust #[ink(event)] pub struct Transferred { from: Option, // Causes compilation error to: Option, value: Balance, } ``` When developers follow this example with ink! v6, they encounter a type mismatch error: ``` error[E0308]: mismatched types expected `AccountId`, found `H160` ``` This occurs because `Self::env().caller()` returns `H160` in ink! v6's default environment (pallet-revive), not `AccountId`. ## Changes Made ### Event Type Definitions - Changed `Option` to `Option` in all event examples - Updated signature topic example from `blake2b("Transferred(Option,Option,u128)")` to `blake2b("Transferred(Option,Option,u128)")` - Ensured consistency across all code snippets in the Events documentation ### Files Modified - `docs/basics/events.md` ## Why H160 in ink! v6? ink! v6 migrated from `pallet-contracts` to `pallet-revive`, which prioritizes Ethereum/Solidity compatibility: - **pallet-revive uses H160** (20-byte addresses) instead of traditional 32-byte AccountId for Ethereum compatibility - **`Address` is a type alias for `H160`** in ink_primitives (both are interchangeable) - **Enables compatibility** with Ethereum tooling like MetaMask, Hardhat, and Solidity contracts - **`Self::env().caller()`** now returns `H160` by default ## Verification **Matches official example**: The [official ERC20 example](https://github.com/use-ink/ink-examples/blob/main/erc20/lib.rs) uses `Address` (alias for `H160`) **Compiles successfully**: Code examples now compile without type mismatch errors in ink! v6 **Consistent with pallet-revive**: Aligns with [pallet-revive's H160 address type](https://docs.rs/pallet-revive/latest/pallet_revive/struct.H160.html) ## References - [pallet-revive documentation](https://docs.rs/pallet-revive/latest/pallet_revive/) - [Official ERC20 example using Address which is a type alias for H160](https://github.com/use-ink/ink-examples/blob/main/erc20/lib.rs) ## Testing - [x] Tested code examples locally with ink! v6 - [x] Verified examples compile without errors - [x] Cross-referenced with official ink-examples like the ERC20 example in the repository --- docs/basics/events.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/basics/events.md b/docs/basics/events.md index 38aba8c248..59080c20b8 100644 --- a/docs/basics/events.md +++ b/docs/basics/events.md @@ -26,8 +26,8 @@ mod erc20 { /// every time value is transferred. #[ink(event)] pub struct Transferred { - from: Option, - to: Option, + from: Option, + to: Option, value: Balance, } @@ -76,9 +76,9 @@ use ink::primitives::AccountId; #[ink::event] pub struct Transferred { #[ink(topic)] - from: Option, + from: Option, #[ink(topic)] - to: Option, + to: Option, amount: u128, } ``` @@ -148,7 +148,7 @@ blake2b("Event(field1_type,field2_type)")` ``` So for our `Transferred` example it will be: ``` -blake2b("Transferred(Option,Option,u128)")` +blake2b("Transferred(Option,Option,u128)")` ``` :::note @@ -234,7 +234,7 @@ In a message events are emitted via `self.env().emit_event()`: ```rust #[ink(message)] -pub fn transfer(&mut self, to: AccountId, amount: Balance) -> Result { +pub fn transfer(&mut self, to: H160, amount: Balance) -> Result { let from = self.env().caller(); // implementation hidden self.env().emit_event(Transferred {