diff --git a/examples/src/main/java/com/hedera/hashgraph/sdk/examples/GenerateKeyExample.java b/examples/src/main/java/com/hedera/hashgraph/sdk/examples/GenerateKeyExample.java index 4ff31845b2..d0bcc47a48 100644 --- a/examples/src/main/java/com/hedera/hashgraph/sdk/examples/GenerateKeyExample.java +++ b/examples/src/main/java/com/hedera/hashgraph/sdk/examples/GenerateKeyExample.java @@ -1,25 +1,34 @@ // SPDX-License-Identifier: Apache-2.0 package com.hedera.hashgraph.sdk.examples; +import com.hedera.hashgraph.sdk.EvmAddress; import com.hedera.hashgraph.sdk.PrivateKey; import com.hedera.hashgraph.sdk.PublicKey; /** - * How to generate ED25519 key pair. + * How to generate an ECDSA (secp256k1) key pair and derive the EVM address from the public key. + * + *

ECDSA keys with an EVM address derived from the public key are the recommended choice for new + * Hedera accounts when you want compatibility with Ethereum tooling (wallets, Hardhat, ethers.js, + * etc.). For legacy Hedera-only flows you can still use {@link PrivateKey#generateED25519()}. */ class GenerateKeyExample { public static void main(String[] args) { - System.out.println("Generate ED25519 Private And Public Key Pair Example Start!"); + System.out.println("Generate ECDSA key pair and EVM address example start"); - System.out.println("Generating the ED25519 private key..."); - PrivateKey privateKey = PrivateKey.generateED25519(); - System.out.println("Private Key: " + privateKey); + System.out.println("Generating an ECDSA (secp256k1) private key..."); + PrivateKey privateKey = PrivateKey.generateECDSA(); + System.out.println("Private key: " + privateKey); - System.out.println("Deriving a public key from the above private key"); + System.out.println("Deriving the public key from the private key"); PublicKey publicKey = privateKey.getPublicKey(); System.out.println("Public key: " + publicKey); - System.out.println("Generate ED25519 Private And Public Key Pair Example Complete!"); + System.out.println("Deriving the EVM address (last 20 bytes of Keccak-256 of the uncompressed public key)"); + EvmAddress evmAddress = publicKey.toEvmAddress(); + System.out.println("EVM address: 0x" + evmAddress); + + System.out.println("Generate ECDSA key pair and EVM address example complete"); } }