You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: smart-contracts/for-eth-devs/accounts.md
+60-7Lines changed: 60 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,20 +55,57 @@ The conversion process is implemented through the [`to_address`](https://parityt
55
55
**Stateful Mapping for Reversibility** : Since the conversion from 32-byte to 20-byte addresses is inherently lossy, the system provides an optional stateful mapping through the [`OriginalAccount`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/pallet/storage_types/struct.OriginalAccount.html){target=\_blank} storage. When a Polkadot account registers a mapping (via the [`map`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.map){target=\_blank} function), the system stores the original 32-byte account ID, enabling the [`to_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_account_id){target=\_blank} function to recover the exact original account rather than falling back to a default conversion.
56
56
57
57
58
+
### Interacting with Unmapped Substrate Accounts
59
+
60
+
Native Polkadot accounts (32-byte format) that haven't been explicitly mapped have limited interaction capabilities with the Ethereum-compatible smart contract layer. Understanding these limitations and when mapping is required is essential for developers working with the Polkadot Hub.
61
+
62
+
#### Limitations of Unmapped Accounts
63
+
64
+
Unmapped Substrate accounts (those created with Ed25519 or Sr25519 keypairs) face the following restrictions:
65
+
66
+
-**Cannot initiate transactions** through Ethereum-compatible interfaces (like MetaMask or other EVM-compatible wallets)
67
+
-**Cannot directly call smart contracts** using Ethereum RPC methods
68
+
-**Cannot transfer funds** to or from 20-byte Ethereum-compatible addresses without proper mapping
69
+
-**Limited interoperability** with Ethereum tooling and existing EVM infrastructure
70
+
71
+
The system can *receive* funds at the hashed 20-byte address derived from the 32-byte account, but the original account owner cannot control or access those funds through Ethereum-compatible methods without first establishing a proper mapping.
72
+
73
+
#### When Mapping is Required
74
+
75
+
Account mapping is **required** when:
76
+
77
+
1. You want to interact with smart contracts using Ethereum-compatible tools (MetaMask, Web3.js, Ethers.js)
78
+
2. You need to transfer funds using 20-byte address format
79
+
3. You want your existing Polkadot account to be accessible through EVM-compatible interfaces
80
+
4. You need bidirectional compatibility between Polkadot and Ethereum address formats
81
+
82
+
Account mapping is **not required** when:
83
+
84
+
- Using native Polkadot addresses (32-byte) exclusively with Substrate-native interfaces
85
+
- Interacting with parachains that don't use the Ethereum-compatible layer
86
+
- Using accounts that were originally created with secp256k1 keys (Ethereum-compatible from the start)
87
+
58
88
### Account Mapping for Native Polkadot Accounts
59
89
60
90
If you have a native Polkadot account (32-byte format) that was created with a Polkadot/Substrate keypair (Ed25519/Sr25519) rather than an Ethereum-compatible keypair (secp256k1), you'll need to map your account to enable Ethereum compatibility.
61
91
62
92
To map your account, call the [`map_account`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/pallet/dispatchables/fn.map_account.html){target=\_blank} extrinsic of the [`pallet_revive`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/index.html){target=\_blank} pallet using your original Substrate account. This creates a stateful mapping that allows your 32-byte account to interact with the Ethereum-compatible smart contract system.
63
93
94
+
**Mapping Process:**
95
+
96
+
1.**Call the extrinsic**: Use your Substrate wallet to call `pallet_revive.map_account()`
97
+
2.**Pay the deposit**: A deposit is required and held while the mapping exists (refundable upon unmapping)
98
+
3.**Receive confirmation**: Once mapped, your account can be used with both Polkadot and Ethereum interfaces
99
+
64
100
Once mapped, you'll be able to:
65
101
66
-
- Transfer funds between 20-byte format addresses.
67
-
- Interact with smart contracts using Ethereum-compatible tools like MetaMask.
68
-
- Maintain full reversibility to your original 32-byte account format.
102
+
- Transfer funds between 20-byte format addresses
103
+
- Interact with smart contracts using Ethereum-compatible tools like MetaMask
104
+
- Maintain full reversibility to your original 32-byte account format
105
+
- Access funds at both your 32-byte Polkadot address and the mapped 20-byte Ethereum address
69
106
70
107
!!! warning "Mapping Requirement"
71
-
Without this mapping, native Polkadot accounts cannot transfer funds or interact with the Ethereum-compatible layer on the Hub.
108
+
Without this mapping, native Polkadot accounts cannot transfer funds or interact with the Ethereum-compatible layer on the Hub. Attempting to send funds to an unmapped account's hashed Ethereum address may result in funds being inaccessible through standard Ethereum tools.
72
109
73
110
## Account Registration
74
111
@@ -83,9 +120,25 @@ The registration process is implemented through the [`map`](https://paritytech.g
83
120
84
121
The fallback mechanism is integrated into the [`to_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_account_id){target=\_blank} function. It provides a safety net for address conversion by:
85
122
86
-
- First, attempting to retrieve stored mapping data.
87
-
- Falling back to the default conversion method if no mapping exists.
88
-
- Maintaining consistency in address representation.
123
+
- First, attempting to retrieve stored mapping data from [`OriginalAccount`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/pallet/storage_types/struct.OriginalAccount.html){target=\_blank} storage
124
+
- Falling back to the default conversion method (Keccak-256 hash) if no explicit mapping exists
125
+
- Maintaining consistency in address representation across the system
126
+
127
+
### How Fallback Works with Unmapped Accounts
128
+
129
+
When an unmapped 32-byte Polkadot account needs to be represented as a 20-byte Ethereum address, the system:
130
+
131
+
1.**Checks for explicit mapping**: First looks in the `OriginalAccount` storage to see if the account has been explicitly mapped via `map_account`
132
+
2.**Applies fallback conversion**: If no mapping exists, automatically converts the 32-byte account to a 20-byte address by:
133
+
- Hashing the full 32-byte account with Keccak-256
134
+
- Taking the last 20 bytes of the resulting hash
135
+
3.**Uses the derived address**: This fallback address can receive funds, but the account owner cannot spend those funds through Ethereum-compatible interfaces without explicit mapping
136
+
137
+
**Important Considerations:**
138
+
139
+
- The fallback mechanism is **one-way for unmapped accounts** - while you can derive the 20-byte address from a 32-byte account, you cannot recover the original 32-byte account from the 20-byte hash without the stored mapping
140
+
- Funds sent to a fallback address of an unmapped account are not lost, but require explicit mapping to be accessible through Ethereum tools
141
+
- For security and usability, it's recommended to establish explicit mappings rather than relying on fallback addresses for accounts that need Ethereum compatibility
0 commit comments