importosfromsymbolchain.Bip32importBip32fromsymbolchain.facade.SymbolFacadeimportSymbolFacade# Initialize the facade for the testnet networkfacade=SymbolFacade('testnet')# Use an existing mnemonic if provided, otherwise generate a random onebip32=Bip32()mnemonic=os.getenv('MNEMONIC')ifmnemonic:print("Loading mnemonic phrase from environment variable...")else:print("Generating random mnemonic phrase...")mnemonic=bip32.random()print(f'Mnemonic phrase: {mnemonic}')# Load password from environment variable or use defaultpassword=os.getenv('PASSWORD','correcthorsebatterystaple')print(f'Password: {password}')# Derive a root Bip32 node from the mnemonic and a passwordroot_node=bip32.from_mnemonic(mnemonic,password)# Derive a child Bip32 node for the account at index 0account_index=0child_node=root_node.derive_path(facade.bip32_path(account_index))# Convert the Bip32 node to a signing key pairkey_pair=facade.bip32_node_to_key_pair(child_node)# Derive the address from the public keyaddress=facade.network.public_key_to_address(key_pair.public_key)# Output the account detailsprint(f'Address: {address}')print(f'Public key: {key_pair.public_key}')print(f'Private key: {key_pair.private_key}')
import{Bip32}from'symbol-sdk';import{SymbolFacade}from'symbol-sdk/symbol';importprocessfrom'process';// Initialize the facade for the testnet networkconstfacade=newSymbolFacade('testnet');// Use an existing mnemonic if provided, otherwise generate a random oneconstbip32=newBip32(facade.constructor.BIP32_CURVE_NAME);letmnemonic=process.env.MNEMONIC;if(mnemonic){console.log('Loading mnemonic phrase from environment variable...');}else{console.log('Generating random mnemonic phrase...');mnemonic=bip32.random();}console.log('Mnemonic phrase:',mnemonic);// Load password from environment variable or use defaultconstpassword=process.env.PASSWORD||'correcthorsebatterystaple';console.log('Password:',password);// Derive a root Bip32 node from the mnemonic and a passwordconstrootNode=bip32.fromMnemonic(mnemonic,password);// Derive a child Bip32 node for the account at index 0constaccountIndex=0;constchildNode=rootNode.derivePath(facade.bip32Path(accountIndex));// Convert the Bip32 node to a signing key pairconstkeyPair=facade.constructor.bip32NodeToKeyPair(childNode);// Derive the address from the public keyconstaddress=facade.network.publicKeyToAddress(keyPair.publicKey);// Output the account detailsconsole.log('Address:',address.toString());console.log('Public key:',keyPair.publicKey.toString());console.log('Private key:',keyPair.privateKey.toString());
# Use an existing mnemonic if provided, otherwise generate a random onebip32=Bip32()mnemonic=os.getenv('MNEMONIC')ifmnemonic:print("Loading mnemonic phrase from environment variable...")else:print("Generating random mnemonic phrase...")mnemonic=bip32.random()print(f'Mnemonic phrase: {mnemonic}')
// Use an existing mnemonic if provided, otherwise generate a random oneconstbip32=newBip32(facade.constructor.BIP32_CURVE_NAME);letmnemonic=process.env.MNEMONIC;if(mnemonic){console.log('Loading mnemonic phrase from environment variable...');}else{console.log('Generating random mnemonic phrase...');mnemonic=bip32.random();}console.log('Mnemonic phrase:',mnemonic);
# Load password from environment variable or use defaultpassword=os.getenv('PASSWORD','correcthorsebatterystaple')print(f'Password: {password}')# Derive a root Bip32 node from the mnemonic and a passwordroot_node=bip32.from_mnemonic(mnemonic,password)
// Load password from environment variable or use defaultconstpassword=process.env.PASSWORD||'correcthorsebatterystaple';console.log('Password:',password);// Derive a root Bip32 node from the mnemonic and a passwordconstrootNode=bip32.fromMnemonic(mnemonic,password);
# Convert the Bip32 node to a signing key pairkey_pair=facade.bip32_node_to_key_pair(child_node)# Derive the address from the public keyaddress=facade.network.public_key_to_address(key_pair.public_key)# Output the account detailsprint(f'Address: {address}')print(f'Public key: {key_pair.public_key}')print(f'Private key: {key_pair.private_key}')
// Convert the Bip32 node to a signing key pairconstkeyPair=facade.constructor.bip32NodeToKeyPair(childNode);// Derive the address from the public keyconstaddress=facade.network.publicKeyToAddress(keyPair.publicKey);// Output the account detailsconsole.log('Address:',address.toString());console.log('Public key:',keyPair.publicKey.toString());console.log('Private key:',keyPair.privateKey.toString());
Generating random mnemonic phrase...
Mnemonic phrase: east actual egg series spot express addict always human swallow decrease turn surround direct place burst million curious dish divorce net nephew allow *****
Password: correcthorsebatterystaple
Address: TCHBDENCLKEBILBPWP3JPB2XNY64OE7PYHHE32I
Public key: 3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29
Private key: 0000000000000000000000000000000000000000000000000000000000000000