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());
//JAVA 21+//DEPS org.symbol:symbol-sdk:3.3.1importorg.symbol.sdk.Bip32;importorg.symbol.sdk.CryptoTypes;importorg.symbol.sdk.facade.SymbolFacade;importorg.symbol.sdk.symbol.Address;importorg.symbol.sdk.symbol.KeyPair;publicfinalclassCreateFromMnemonic{// Initialize the facade for the testnet networkprivatefinalSymbolFacadefacade=newSymbolFacade("testnet");publicstaticvoidmain(finalString[]args){newCreateFromMnemonic().run();}privatevoidrun(){// Use an existing mnemonic if provided,// otherwise generate a random one.finalBip32bip32=newBip32(SymbolFacade.BIP32_CURVE_NAME);Stringmnemonic=System.getenv("MNEMONIC");if(null!=mnemonic){System.out.println("Loading mnemonic phrase from environment variable...");}else{System.out.println("Generating random mnemonic phrase...");mnemonic=bip32.random();}System.out.printf("Mnemonic phrase: %s%n",mnemonic);// Load password from environment variable or use defaultfinalStringpassword=System.getenv().getOrDefault("PASSWORD","correcthorsebatterystaple");System.out.printf("Password: %s%n",password);// Derive a root Bip32 node from the mnemonic and a passwordfinalBip32.Bip32NoderootNode=bip32.fromMnemonic(mnemonic,password);// Derive a child Bip32 node for the account at index 0finalintaccountIndex=0;finalBip32.Bip32NodechildNode=rootNode.derivePath(facade.bip32Path(accountIndex));// Convert the Bip32 node to a signing key pairfinalKeyPairkeyPair=SymbolFacade.bip32NodeToKeyPair(childNode);// Derive the address from the public keyfinalCryptoTypes.PublicKeypublicKey=keyPair.getPublicKey();finalAddressaddress=facade.network.publicKeyToAddress(publicKey);// Output the account detailsSystem.out.printf("Address: %s%n",address);System.out.printf("Public key: %s%n",publicKey);System.out.printf("Private key: %s%n",keyPair.getPrivateKey());}}
# 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);
// Use an existing mnemonic if provided,// otherwise generate a random one.finalBip32bip32=newBip32(SymbolFacade.BIP32_CURVE_NAME);Stringmnemonic=System.getenv("MNEMONIC");if(null!=mnemonic){System.out.println("Loading mnemonic phrase from environment variable...");}else{System.out.println("Generating random mnemonic phrase...");mnemonic=bip32.random();}System.out.printf("Mnemonic phrase: %s%n",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);
// Load password from environment variable or use defaultfinalStringpassword=System.getenv().getOrDefault("PASSWORD","correcthorsebatterystaple");System.out.printf("Password: %s%n",password);// Derive a root Bip32 node from the mnemonic and a passwordfinalBip32.Bip32NoderootNode=bip32.fromMnemonic(mnemonic,password);
// Derive a child Bip32 node for the account at index 0finalintaccountIndex=0;finalBip32.Bip32NodechildNode=rootNode.derivePath(facade.bip32Path(accountIndex));
# 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());
// Convert the Bip32 node to a signing key pairfinalKeyPairkeyPair=SymbolFacade.bip32NodeToKeyPair(childNode);// Derive the address from the public keyfinalCryptoTypes.PublicKeypublicKey=keyPair.getPublicKey();finalAddressaddress=facade.network.publicKeyToAddress(publicKey);// Output the account detailsSystem.out.printf("Address: %s%n",address);System.out.printf("Public key: %s%n",publicKey);System.out.printf("Private key: %s%n",keyPair.getPrivateKey());
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