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
636 stars 324 forks source link

Hi help me create code please #1586

Open jaylinlucero opened 2 months ago

jaylinlucero commented 2 months ago

Good afternoon, can you help me, I use the @cosmjs/proto-signing library to generate Agoric coins, after generating phrases from seed (possible buyer peanut auto assist powder draft hidden lunch that first evoke ) I get the address address - agoric1jh4jnpedwmfn3wvut4adnt6xqy2pj2km0xuz63

and when I add a seed phrase to Keplr I get the address - agoric15fr4ptrgfv5k200k94epahk3q226g2dkujdhp9

Having checked everything, I realized that the address generation is based on the derivative m/44'/118'/ and you need m/44'/564'/

added to the code

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {prefix: "agoric", hdPath: ("m/44'/564'"),}); but the address is still generated at 118 help me solve this issue or give an example of a script with correct generation please

jaylinlucero commented 2 months ago

if I add it like this

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {hdPaths: [stringToPath("m/44'/564")], prefix: "agoric"});

then it writes an error

ReferenceError: stringToPath is not defined

Node version v20.11.0

0xpatrickdev commented 1 month ago

The following should work:

const hdPath = (coinType = 118, account = 0) =>
  stringToPath(`m/44'/${coinType}'/${account}'/0/0`);

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
    prefix: Agoric.Bech32MainPrefix,
    hdPaths: [hdPath(564, 0)],
  });