python for blockchain fuel official wallet, suport use mnemonic seeds generate fuel address and private key
pip install bip_utils
# use this project dir`s bech32m.py
from bech32m import encode # a little different with bitcoin bech32m
from hashlib import sha256
from bip_utils import Bip39SeedGenerator
from bip_utils import Bip32Secp256k1
from bech32m import encode # a little different with bitcoin bech32m
class FuelWallet():
def __init__(self, mnemonic, password='', wallet_index=0) -> None:
self.mnemonic = mnemonic.strip()
self.password = password # if have password
self.derive_default_path = f"m/44'/1179993420'/{wallet_index}'/0/0"
self.prefix = 'fuel'
def get_address_pk(self):
seed_bytes = Bip39SeedGenerator(self.mnemonic).Generate(self.password)
bip32_mst_ctx = Bip32Secp256k1.FromSeed(seed_bytes)
bip32_der_ctx = bip32_mst_ctx.DerivePath(self.derive_default_path)
pk: bytes = bip32_der_ctx.PrivateKey().Raw().ToBytes()
extended_key = Bip32Secp256k1.FromPrivateKey(pk)
pubkey = extended_key.PublicKey().RawUncompressed().ToBytes().hex()[2:]
pubkey_bytes = bytes.fromhex(pubkey)
sha256_bytes = sha256(pubkey_bytes).digest()
address = encode(self.prefix, sha256_bytes)
return pk.hex(), address
if __name__ == '__main__':
mnemonic = 'seek clean tell token spread parrot pear tray beef desk sponsor plate'
print(f'mnemonic seeds: {mnemonic}')
for wallet_index in range(5):
fl = FuelWallet(mnemonic=mnemonic, wallet_index=wallet_index)
pk, address = fl.get_address_pk()
print(f'address index {wallet_index}, address: {address}, pk: 0x{pk}')
mnemonic seeds: seek clean tell token spread parrot pear tray beef desk sponsor plate
address index 0, address: fuel1gu47yf32mq2khczewvw04el088y34f49fh3vqp4vn8p9yrc28uaqrr3t85, pk: 0x1ef91ec4b2a39d652091f6f217029f5a33eea7e9913da4fa26eb0a79d6663bee
address index 1, address: fuel1pqkzasvy0x2vpvn3humwyq492ccrgqt9t0mvlpdnpkw09tnu9u9sn7hrcq, pk: 0xa9da58f2169d88ea98fff6367c7c6fdcb153c3eef5d8d07881e5f10a8fe55e1a
address index 2, address: fuel142lr9rsntee7lnsxvck7m49fdpfca3vvcmqqvvtfzqwtuuge2qdq5gj259, pk: 0x6af82b17141a6793bc7fb703e98a256e1a446ce0e03c1d8884e3592ad21333a2
address index 3, address: fuel1n0zstx2dntgp64v29wgzsqc4jumcgtse30ws4s3zphpn8rjhzs5s3ttfyf, pk: 0x4423c07fc04d7d73ff34f46bc6b652ed759896bdb689fff1930fc4de98e82d53
address index 4, address: fuel1vqn9mu84v8keec0u8fge8295epr5mn6c74nwekyqn5yspgn8hqdqsg6ryh, pk: 0x0056a68f643de783298adf4ca3269a15110fb02a52937adeef36f53f43ed0b72
![](https://private-user-images.githubusercontent.com/30144807/309497508-bbbd2a8b-8814-41a5-814c-bc0d4b843ab0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMzE2MjYsIm5iZiI6MTcyNDAzMTMyNiwicGF0aCI6Ii8zMDE0NDgwNy8zMDk0OTc1MDgtYmJiZDJhOGItODgxNC00MWE1LTgxNGMtYmMwZDRiODQzYWIwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE5VDAxMzUyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZlOWY5ZjM3NjRiNzFkYmEwM2Q3MGY2MGU0YmU3YTk1NTJjOGYzZTQ3NmU1MDBmODIzZWM1NDA1YWZmYjE1ZTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.VcYONrPTk74W8u-JV8hNlE9w8PakNExd5CwXpqHnHOI)
- test the result and compare it with main web wallet app(such as: metamask, mathwallet, trustwallet...) before you deposit crypto assets to the address
- some wallet may get diffrent result, because it may use diffrent derive path to generate wallet
- learn about hd-wallet principle by your self