0

Faced a problem, I have a crypto wallet written in Python, there is a code that creates a wallet address from a mnemonic phrase (In this case, BTC address). But if I enter this mnemonic phrase into the Trust Wallet mobile app, it will give me a completely different Bitcoin address. Why? How to fix it? Here is the code:

from bipwallet import wallet
from bipwallet.utils import *

Seed = wallet.generate_mnemonic()

WalletBTC = wallet.create_wallet(network="BTC", seed=Seed, children=0)

AddressBTC = WalletBTC.get("address")

print("BTC Address: ", AddressBTC)

RedGrittyBrick
  • 26,841
  • 3
  • 25
  • 51
Андрей
  • 11
  • 1
  • 2

3 Answers3

2

I assume both the Python library and Trustwallet implement BIP32 to create hierarchical deterministic (HD) wallets.

The address you get depends on the derivation path. If your Python library and Trustwallet use different derivation paths, you will get different addresses.

An HD wallet will produce multiple addresses, a different one each time you request an address. So you must be careful not to compare the 1st address from one wallet with the 2nd address from another.

RedGrittyBrick
  • 26,841
  • 3
  • 25
  • 51
1

Thank you. I independently found libraries that generate the same address as Trust Wallet, as well as Cryptoneed (Mobile Apps). Who needs my code, copy and customize for yourself:

from hdwallet import BIP44HDWallet
from hdwallet.utils import generate_mnemonic
from hdwallet.derivations import BIP44Derivation
from hdwallet.cryptocurrencies import BitcoinMainnet, EthereumMainnet
from bip_utils import Bip84, Bip84Coins, Bip44Changes, Bip39SeedGenerator

LanguageInMnemonic = "english"

Mnemonic = generate_mnemonic(language = LanguageInMnemonic, strength = 128) Seed = Bip39SeedGenerator(Mnemonic).Generate()

print(Mnemonic)

if IsCheckBTC == "+":
    if IsCheckBTCBip44 == "+":
        CheckedWalletBTCBip44 = BIP44HDWallet(cryptocurrency=BitcoinMainnet)
        CheckedWalletBTCBip44.from_mnemonic(mnemonic = Mnemonic, language = LanguageInMnemonic, passphrase = None)
        CheckedWalletBTCBip44.clean_derivation()
        CheckedWalletBTCBip44Derivation = BIP44Derivation(cryptocurrency = BitcoinMainnet, account = 0, change = False, address = 0)
        CheckedWalletBTCBip44.from_path(path = CheckedWalletBTCBip44Derivation)

        CheckedAddressBTCBip44 = CheckedWalletBTCBip44.address()
        print(CheckedAddressBTCBip44)

    if IsCheckBTCBip84 == "+":
        CheckedWalletBTCBip84 = Bip84.FromSeed(Seed, Bip84Coins.BITCOIN)
        CheckedWalletBTCBip84Step1 = (CheckedWalletBTCBip84.Purpose().Coin().Account(0)).Change(Bip44Changes.CHAIN_EXT)
        CheckedWalletBTCBip84Step2 = CheckedWalletBTCBip84Step1.AddressIndex(0)

        CheckedAddressBTCBip84 = CheckedWalletBTCBip84Step2.PublicKey().ToAddress()
        print(CheckedAddressBTCBip84)

if IsCheckETH == "+":
    CheckedWalletETH = BIP44HDWallet(cryptocurrency = EthereumMainnet)
    CheckedWalletETH.from_mnemonic(mnemonic = Mnemonic, language = LanguageInMnemonic, passphrase = None)
    CheckedWalletETH.clean_derivation()
    CheckedWalletETHDerivation: BIP44Derivation = BIP44Derivation(cryptocurrency = EthereumMainnet, account = 0, change = False, address = 0)
    CheckedWalletETH.from_path(path=CheckedWalletETHDerivation)

    CheckedAddressETH = CheckedWalletETH.address()
    print(CheckedAddressETH)

(P. S. I used google translate)

RedGrittyBrick
  • 26,841
  • 3
  • 25
  • 51
Андрей
  • 11
  • 1
  • 2
0

Please you i get a php version of this code instead of Python. I have a seed Phrase. I want the BTC address that correspond with Blockchain. I want code in PHP so that i can modify to suit my project

EHIS E
  • 1