xian-network / xian-js

Tools for interacting with the Xian blockchain using javascript / typescript
1 stars 1 forks source link

query: how to create a wallet using a mnemonic? #1

Open rosmcmahon opened 4 months ago

rosmcmahon commented 4 months ago

as per title!

duelingbenjos commented 4 months ago

https://github.com/XianChain/xian-js/blob/7fbe26d1debdfe5ca9af933996260078c30eb7ca/src/lib/wallet.ts#L132

This can be imported from wallet. I'll be sure to update the docs and add types for this in the future

duelingbenjos commented 4 months ago

Might have closed this prematurely, does this answer your question ?

rosmcmahon commented 4 months ago

well, i was able to do it this way:

import Xian from '../src'
import * as bip39 from 'bip39'

/* create wallet from mnemonic */
const createWalletFromMnemonic = async () => {
    console.info('Create wallet from mnemonic...')

    const mnemonic = 'document energy must purpose coach viable student dragon domain catalog list price garden tongue keen exile beauty young token celery lumber board eye bind'

    const seed = (await bip39.mnemonicToSeed(mnemonic)).toString('hex')

    //@ts-ignore
    const mnemonicWallet = Xian.Wallet.new_wallet_bip39(seed)
    console.log(JSON.stringify(mnemonicWallet, null, 2))
}
createWalletFromMnemonic()

happy to create a PR for a new wallet function so that folks don't have to use bip39 directly, i've actually got a fork going already

duelingbenjos commented 4 months ago

Awesome, you figured it out. PR's welcome <3