Skip to content

Conversation

@CECILIA-MULANDI
Copy link

@CECILIA-MULANDI CECILIA-MULANDI commented Nov 19, 2025

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:

#[ink(event)]
pub struct Transferred {
    from: Option<AccountId>,  // Causes compilation error
    to: Option<AccountId>,
    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<AccountId> to Option<H160> in all event examples
  • Updated signature topic example from blake2b("Transferred(Option<AccountId>,Option<AccountId>,u128)") to blake2b("Transferred(Option<H160>,Option<H160>,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 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

References

Testing

  • Tested code examples locally with ink! v6
  • Verified examples compile without errors
  • Cross-referenced with official ink-examples like the ERC20 example in the repository

…bility

## 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<AccountId>,  // Causes compilation error
    to: Option<AccountId>,
    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<AccountId>` to `Option<H160>` in all event examples
- Updated signature topic example from `blake2b("Transferred(Option<AccountId>,Option<AccountId>,u128)")` to `blake2b("Transferred(Option<H160>,Option<H160>,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
@CECILIA-MULANDI CECILIA-MULANDI changed the title fix(docs): Fix event type definitions to use H160 for ink! v6 compati… fix(docs): Fix event type definitions to use H160 for ink! v6 compatibility Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant