Skip to content

Conversation

@RandomCoderTinker
Copy link

Fixes incorrect EVM wallet derivation logic — now compatible with MetaMask/TrustWallet

Summary

The original WalletManager was generating wallet data (mnemonic, private key, public key, address), but it wasn't EVM-compatible — meaning when importing the generated keys into services like MetaMask or TrustWallet, it would result in a different address or a failed import.

Problem

  • The wallet derivation logic was custom or partial, and didn't follow the BIP-44 standard for Ethereum wallets.
  • As a result, addresses and private keys were not matching what EVM-based services expect.

What I Changed

  • Implemented a new HDWallet class to handle BIP-44 derivation path m/44'/60'/0'/0/0 — the standard for Ethereum.
  • Updated KeyPair::fromMnemonic() logic to derive the correct private/public key pair and address.
  • Verified the output using a test script and successfully imported the wallet into MetaMask.
  • Added a test file (TestWallet.php) to demonstrate correct key generation and compatibility.

Example Output (after fix)

address: 0x64d002589b9e42f57bdbc6cbd8f39071436a2087
public_key: 03b54c... (valid compressed key)
private_key: 5ba34f... (valid 64-character hex string)
mnemonic: giraffe kidney home unlock ...

Result

✅ Wallets generated from mnemonics are now:

  • Valid
  • EVM-compatible
  • Importable into MetaMask, TrustWallet, and other Ethereum wallets.

- Replaced custom wallet generation with BIP-44-compliant HD wallet logic (m/44'/60'/0'/0/0)
- Added HDWallet class for correct private/public key and address derivation
- Verified compatibility with MetaMask and TrustWallet
- Added test script to demonstrate valid mnemonic-based wallet generation
@RandomCoderTinker
Copy link
Author

Still new to using GitHub properly - only ever used it to store code, so I apologise for all the requests.

This update allows EVM compatible wallet generation that can be imported into services like metamask, when i was testing the codebase you created, upon importing the private key and Mnemonic into MetaMask it was showing a different address.

This update follows all BIP standards and creates compatible address/keys/Mnemonics that can be tested with https://chaintool.tech/generateWallet/evmWallet and imported correctly.

@infosave2007
Copy link
Owner

Yes, I’ve reached the stage of integration with wallets like MetaMask, and I’ve implemented compatibility along with full API integration. When a network is added, the wallet is automatically added to the database, and balance synchronization is performed. Please wait a bit — I’ll finish debugging everything and complete the synchronization with mempool nodes. Try RPC https://wallet.coursefactory.pro/wallet/wallet_api.php id - 20250808 VFLW

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.

2 participants