# Use Crypto Utilities
Before working with the Private Key, Public Key, or Address, include the following initialization snippet at the beginning of each script:
// Required imports.
using WavesLabs.Node.Transactions.Common;
using WavesLabs.Node.Transactions.Utils;
using WavesLabs.Node.Transactions;
using WavesLabs.Node.Client;
# Private Key
You can create a private key from:
- Seed phrase.
- Randomly generated seed phrase.
- Randomly generated seed phrase with nonce 2.
- Seed bytes.
- Randomly generated seed bytes.
- Bytes.
- Encoded string.
# Create Private Key from Seed
// Create a private key from a seed phrase.
var senderPrivateKey = PrivateKey.FromSeed("PASTE_YOUR_SEED_PHRASE_HERE");
# Generate Random Seed Phrase and Private Key
// Generate a random seed phrase.
var seed = Crypto.GenerateRandomSeedPhrase();
// Create the private key from the generated seed phrase.
var senderPrivateKey = PrivateKey.FromSeed(seed);
# Generate Random Seed Phrase with Nonce 2
// Generate a random seed phrase.
var seed = Crypto.GenerateRandomSeedPhrase();
// Create the private key from the generated seed phrase with a nonce of 2.
var senderPrivateKey = PrivateKey.FromSeed(seed, 2);
# Create a Private Key from Seed Bytes
// Create a seed phrase represented as bytes.
byte[] seedBytes = { 21, 55, 87, 117, 8, 81, 77, 77, 99, 87, 23, 7, 116, 99, 20, 12, 4 };
// Generate the private key from the seed phrase bytes.
var senderPrivateKey = PrivateKey.FromSeed(seedBytes);
# Create a Private Key from Randomly Generated Seed Bytes
// Generate a random seed phrase as bytes.
byte[] randomSeedBytes = Crypto.GenerateRandomSeedBytes();
// Create the private key from the generated seed phrase bytes.
var senderPrivateKey = PrivateKey.FromSeed(randomSeedBytes);
# Create a Private Key from Bytes
// Define a byte array.
byte[] bytes = { 56, 3, 37, 64, 2, 38, 78, 37, 98, 45, 23, 117, 14, 88, 20, 42, 9, 21, 55, 87, 117, 8, 81, 77, 77, 99, 87, 23, 7, 116, 99, 20 };
// Create the private key from the byte array.
var senderPrivateKey = PrivateKey.As(bytes);
# Create a Private Key from an Encoded String
// Define a Base58 encoded string.
var base58PhraseEncoded = "PASTE_YOUR_BASE58_ENCODED_STRING_HERE";
// Create the private key from the Base58 encoded string.
var senderPrivateKey = PrivateKey.As(base58PhraseEncoded);
# Public Key
You can create a public key from a private key:
// Specify the sender private key.
var senderPrivateKey = "PASTE_THE_SENDER_PRIVATE_KEY_HERE";
// Derive the public key from the private key.
var senderPublicKey = senderPrivateKey.PublicKey;
# Address
You can create an address from a public key:
// Specify the sender public key.
var senderPublicKey = "PASTE_THE_SENDER_PUBLIC_KEY_HERE";
/*
Get the account address from the public key.
NOTE: Ensure the specified network matches the node instance configuration:
- `MainNet`.
- Or `TestNet`.
- Or `StageNet`.
*/
var senderAddress = Address.FromPublicKey(
ChainIds.TestNet,
senderPublicKey
);