Genereted Private key and address tron wallet from Mnemonic

PyMmdrza
2 min readFeb 28, 2023

--

How to Generated Private Key and Address wallet Tron from Mnemonic (words) in Python

convert mnemonic to private key and address tron wallet
convert mnemonic to private key and address tron wallet
  1. Generate a seed from the mnemonic phrase using a BIP39 library.
  2. Derive a master private key (xprv) from the seed using BIP32.
  3. Derive a child private key (xprv) from the master private key using BIP32.
  4. Derive a public key (xpub) from the child private key using BIP32.
  5. Derive a TRON address from the public key using TRON-specific address derivation algorithm.

Here’s an example Python code that generates a TRON address and private key from a mnemonic phrase using the mnemonic and secp256k1 libraries:

import hashlib
import hmac
import base58
import mnemonic
import secp256k1 # pip install secp256k1

# Set the mnemonic phrase
MnemonicPhrase = 'abandon method word home fire water pencil ruller book system smartabout'

# Generate a seed from the mnemonic phrase
SeedBytes = mnemonic.Mnemonic.to_seed(MnemonicPhrase)

# Derive a master private key (xprv) from the seed
MasterPrivateKey = hmac.new(b'TRON seed', SeedBytes, hashlib.sha256).digest()

# Derive a child private key (xprv) from the master private key
ChildPrivateKey = secp256k1.PrivateKey(MasterPrivateKey).derive(0)

# Derive a public key (xpub) from the child private key
PublicKeyBytes = secp256k1.PublicKey(ChildPrivateKey).serialize(compressed=False)[1:]

# Derive a TRON address from the public key
sha3_256 = hashlib.sha3_256(PublicKeyBytes).digest()
AddressBytes = b"\x41" + sha3_256[-20:]
Address = base58.b58encode_check(AddressBytes)

# Display the address and private key
print(f"TRON address: {Address.decode()}")
print(f"Private key: {ChildPrivateKey.secret.hex()}")

# More Detail's and Script in Official Professional Programming MMDRZA.COM

https://mmdrza.com

Can very easy use of Blockthon:

from Blockthon import Wallet, Tron

# mnemonic string
mnemonic_string = "ENTER YOUR MNEMONIC HERE"
# convert mnemonic to private key (hex)
privatekey = Wallet.Mnemonic_To_PrivateKey()
# convert private key to tron address
tron_Address = Tron.Address_From_PrivateKey(privatekey)

--

--

PyMmdrza
PyMmdrza

Responses (2)