paritytech / txwrapper

Helper funtions for offline transaction generation.
Apache License 2.0
58 stars 27 forks source link

address Different #396

Closed CoinInn-Aries closed 3 years ago

CoinInn-Aries commented 3 years ago

paritytech/txwrapper create address: const mnemonic = mnemonicGenerate(); console.log(" memonic: ", mnemonic); // fringe history shy cupboard orbit supreme skin ladder soup shallow unaware wasp console.log(keyring.createFromUri(mnemonic).address); // 5GgrbTa5op5Xkv1wY6PAVNFdCyS5BLPhErYLGGiywskBSV8K

use import polkadot{.js} extension The address generated by importing mnemonic words is: 5Gj1TdhEP1TSrcEYwUMUqFS8XwMUqgxDcMCGeW9pxXgyKfRS

why?

emostov commented 3 years ago

They are using different crypto types - one is using sr25519 while the other is using ed25519

To illustrate here a code snippet - the comments are what gets logged to the console:

import { Keyring } from '@polkadot/api';
import { cryptoWaitReady } from '@polkadot/util-crypto';

async function main(): Promise<void> {
    await cryptoWaitReady();
    const m =
        'fringe history shy cupboard orbit supreme skin ladder soup shallow unaware wasp';

    const keyring1 = new Keyring({ ss58Format: 42, type: 'sr25519' });
    const keypair1 = keyring1.addFromUri(m);
    console.log(keypair1.address); 
         // 5Gj1TdhEP1TSrcEYwUMUqFS8XwMUqgxDcMCGeW9pxXgyKfRS

    const keyring2 = new Keyring({ ss58Format: 42, type: 'ed25519' });
    const keypair2 = keyring2.addFromUri(m);
    console.log(keypair2.address);
        // 5GgrbTa5op5Xkv1wY6PAVNFdCyS5BLPhErYLGGiywskBSV8K
}

main().catch(console.log);
CoinInn-Aries commented 3 years ago

Thanks, solved my problem