cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
654 stars 343 forks source link

DirectSecp256k1HdWallet.fromMnemonic error #1582

Open snailAlice opened 7 months ago

snailAlice commented 7 months ago

The account restored through the mnemonic phrase is inconsistent with the wallet generated by importing it into the keprl wallet. The crossfi chain is used and the address produced by cosmos is consistent. What do I need to do to get the correct address?

import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"

const generateKey = async (): Promise => { console.log(await (await DirectSecp256k1HdWallet.fromMnemonic("material have exile coconut family trick load door soldier feel busy depth glad seed turtle",{prefix: "mx",})).getAccounts()) console.error("Mnemonic with 1st account:", accounts[0].address) } generateKey()

run result: mx1ts9mz7p5p8yqwx84t2sucv3h6et2f8gj3s20hu import keprl wallet: mx18hxcz64d0v5msqwqcm9dtfwgzqhwmnzuslc0sr

What do I need to do to get the correct address?

webmaster128 commented 7 months ago

Just a guess, but you might need a different path than the Cosmos Hub derivation path. In the second argument, fromMnemonic has an hdPath option

{
    prefix: "mx",
    hdPath: stringToPath("m/1/1/1"), // what does your chain typically use here?
}