Hedera
Search…
Generate a new key pair

Ed25519

Create a new Ed25519 key pair used to sign transactions and queries on the Hedera network. The private key is kept confidential and is used to sign transactions that modify the state of an account, topic, token, smart contract, or file entity on the network. The public key can be shared with other users on the network.
V2
V1
​
Method
Type
Description
PrivateKey.generateED25519()
PrivateKey
Generates an Ed25519 private key
PrivateKey.generateED25519().getPublicKey()
PublicKey
Derive a public key from this Ed25519 private key
PrivateKey.generateED25519().publicKey()
PublicKey
Derive a public key from this Ed25519 private key
PrivateKey.generateED25519().publicKey().toAccountId(<shard>,<realm>)
long, long
Contruct an alias account ID from a alias public key address
[DEPRECATED] PrivateKey.generate()
PrivateKey
Generates an Ed25519 private key
Java
1
PrivateKey privateKey = PrivateKey.generateED25519();
2
PublicKey publicKey = privateKey.getPublicKey();
3
​
4
System.out.println("private = " + privateKey);
5
System.out.println("public = " + publicKey);
Copied!
JavaScript
1
const privateKey = await PrivateKeyED25519.generate();
2
const publicKey = privateKey.publicKey;
3
​
4
console.log("private = " + privateKey);
5
console.log("public = " + publicKey);
Copied!
Go
1
privateKey, err := hedera.GenerateEd25519PrivateKey()
2
if err != nil {
3
panic(err)
4
}
5
​
6
publicKey := privateKey.PublicKey()
7
​
8
fmt.Printf("private = %v\n", privateKey)
9
fmt.Printf("public = %v\n", publicKey)
Copied!

Sample Output:

1
private key = 3030020100300706052b8104000a04220420818c50766e025db403416421cb4a16d26ab0044b7f1a1e45513cef2c86123b91
2
public key = 302d300706052b8104000a0322000224d3700dc68fc9061457c5f50b66442c73367f7d0b1d5a7e3a1903e352ca217c
Copied!
Method
Type
Description
Ed25519PrivateKey.generate()
Ed25519PrivateKey
Generates a Ed25519 private key
Ed25519PrivateKey.generate().publicKey
Ed25519PublicKey
Gets the corresponding public key to the generated private key
Java
1
Ed25519PrivateKey newKey = Ed25519PrivateKey.generate();
2
Ed25519PublicKey newPublicKey = newKey.publicKey;
3
​
4
System.out.println("private key = " + newKey);
5
System.out.println("public key = " + newPublicKey);
6
​
7
//v1.3.2
Copied!
JavaScript
1
const privateKey = await PrivateKey.generate();
2
const publicKey = privateKey.publicKey;
3
​
4
console.log("private = " + privateKey);
5
console.log("public = " + publicKey);
6
​
7
//v1.4.4
Copied!

ECDSA (secp256k1)

Create a new ECDSA (secp256k1) key pair used to sign transactions and queries on a Hedera network. The private key is kept confidential and is used to sign transactions that modify the state of an account, topic, token, smart contract, or file entity on the network. The public key can be shared with other users on the network.
V2
V1
​
Method
Type
Description
PrivateKey.generateECDSA()
PrivateKey
Generates an ECSDA private key
PrivateKey.generateECDSA().getPublicKey()
PublicKey
Derive a public key from this ECDSA private key
PrivateKey.generateECDSA().publicKey()
PublicKey
Derive a public key from this ECDSA private key
PrivateKey.generateECDSA().publicKey().toAccountId(<shard>, <realm>)
long, long
Contructs an account ID from an account alias public key
Java
1
PrivateKey privateKey = PrivateKey.generateECDSA();
2
PublicKey publicKey = privateKey.getPublicKey();
3
​
4
System.out.println("private = " + privateKey);
5
System.out.println("public = " + publicKey);
Copied!
JavaScript
1
const privateKey = PrivateKey.generateECDSA();
2
const publicKey = privateKey.publicKey();icKey;
3
​
4
console.log("private = " + privateKey);
5
console.log("public = " + publicKey);
6
​
Copied!
Go
1
privateKey, err := hedera.GenerateEcdsaPrivateKey()
2
if err != nil {
3
panic(err)
4
}
5
​
6
publicKey := privateKey.PublicKey()
7
​
8
fmt.Printf("private = %v\n", privateKey)
9
fmt.Printf("public = %v\n", publicKey)
Copied!

Sample Output:

1
private key = 302e020100300506032b657004220420b9c3ebac81a72aafa5490cc78111643d016d311e60869436fbb91c73307ed35a
2
public key = 302a300506032b65700321001a5a62bb9f35990d3fea1a5bb7ef6f1df0a297697adef1e04510c9d4ecc5db3f
Copied!
Not supported

​

Last modified 1mo ago
Copy link