importosfromsymbolchain.Bip32importBip32fromsymbolchain.facade.NemFacadeimportNemFacade# Initialize the facade for the testnet networkfacade=NemFacade('testnet')# Use an existing mnemonic if provided, otherwise generate a random onebip32=Bip32(NemFacade.BIP32_CURVE_NAME)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{NemFacade}from'symbol-sdk/nem';importprocessfrom'process';// Initialize the facade for the testnet networkconstfacade=newNemFacade('testnet');// Use an existing mnemonic if provided, otherwise generate a random oneconstbip32=newBip32(NemFacade.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=NemFacade.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(NemFacade.BIP32_CURVE_NAME)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(NemFacade.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=NemFacade.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());