0

I tried the following code, using method generate.

https://paritytech.github.io/substrate/master/sp_core/crypto/trait.Pair.html#method.generate

use sp_core::{
    sr25519,
    ed25519,
    Pair,
};

use std::str;

fn main() {
    let pair_seed = <sp_core::ed25519::Pair as Pair>::generate();
    let (pair, seed)  = pair_seed;
    println!("{:?}", str::from_utf8(&seed).unwrap());    
}

Not sure seed is the mnemonic phrase. How to get the mnemonic phrase?

1

1 Answer 1

0

The generate method generates a new random keypair and does not accept a seed as input. If you want to generate a new account with a specific seed, you can use the from_seed method instead.

use sp_core::{sr25519, ed25519, Pair};

fn main() {
    let mnemonic_phrase = "word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12";
    let seed = sp_core::ed25519::Seed::from_phrase(mnemonic_phrase, "")
        .expect("Invalid mnemonic phrase");
    let pair = <sp_core::ed25519::Pair as Pair>::from_seed(&seed);
    println!("{:?}", pair);
}

This will generate a new account using the given seed, which should be a 12-word mnemonic phrase.

Note that the Seed type is specific to the ed25519 implementation of the Pair trait, so you may need to use a different type if you are using a different curve (e.g. sr25519::Seed for the sr25519 curve).

3

Not the answer you're looking for? Browse other questions tagged or ask your own question.