Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derrived address different then expected #21

Open
Abhimanyu121 opened this issue Jul 6, 2021 · 2 comments
Open

Derrived address different then expected #21

Abhimanyu121 opened this issue Jul 6, 2021 · 2 comments

Comments

@Abhimanyu121
Copy link

Hey, I am using this library to derive accounts from the deprivation path of m/44'/60'/0'/0/0 which works fine, but when I derive path with m/44'/60'/0'/0/1 it is inconsistent with what we get from metamask or other applications.

I am using this mnemonic company loud estate century olive gun tribe pulse bread play addict amount

0th address if fine which is 0x2Ee331840018465bD7Fe74aA4E442b9EA407fBBE
from 1st address it gives different account then expected, it should give 0x97F5aE30eEdd5C3c531C97E41386618b1831Cb7b but its giving 0xeeed912ce027042b94ea6288001c27541d2cc59b
You can check accounts with this site https://iancoleman.io/bip39/

I am using this snippet to derive account

    final root = bip32.BIP32.fromSeed(HEX.decode(seed));
    final child1 = root.derivePath("m/44'/60'/0'/0/1");
    final privateKey = HEX.encode(child1.privateKey);
    final private = EthPrivateKey.fromHex(privateKey);
    final address = await private.extractAddress();```
@liviuls
Copy link

liviuls commented Jul 8, 2021

Hey, this code works for your usecase

  import 'package:bip39/bip39.dart';
  import 'package:web3dart/web3dart.dart'; 
  import 'package:bip32/bip32.dart' as bip32;
  import 'package:hex/hex.dart';

  final mnemonic = "company loud estate century olive gun tribe pulse bread play addict amount";  
  final root = bip32.BIP32.fromSeed(mnemonicToSeed(mnemonic));  
  final child1 = root.derivePath("m/44'/60'/0'/0/1");  
  final privateKey = HEX.encode(child1.privateKey!);  
  final private = EthPrivateKey.fromHex(privateKey);  
  final address = await private.extractAddress();  
  print(address);

Result: "0x97f5ae30eedd5c3c531c97e41386618b1831cb7b"

@Abhimanyu121
Copy link
Author

Thanks a lot, so I didn't have to hex decode that seed, and everything else was correct?

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

No branches or pull requests

2 participants