# Derive stacks address from keys

{% code fullWidth="false" expandable="true" %}

```typescript
import { getPublicKeyFromPrivate } from "@stacks/encryption";
import { 
  getAddressFromPrivateKey, 
  getAddressFromPublicKey 
} from "@stacks/transactions";

// Derive address from private key
const privateKey = process.env.PRIVATE_KEY; // Keep this secret!
const addressFromPrivate = getAddressFromPrivateKey(privateKey, "testnet");

// Derive public key and address
const publicKey = getPublicKeyFromPrivate(privateKey);
const addressFromPublic = getAddressFromPublicKey(publicKey, "testnet");

console.log("Address:", addressFromPrivate);
console.log("Public key:", publicKey);
console.log("Same address:", addressFromPrivate === addressFromPublic); // true
```

{% endcode %}

### Description

Generate Stacks addresses from private or public keys using multiple methods

### Use Cases

* Wallet address generation
* Key pair validation
* Address recovery from backup keys
* Multi-signature wallet setup

### Key Concepts

* **Private key** - 32-byte random number (keep secret!)
* **Public key** - Derived from private key using ECDSA
* **Address** - Base58check-encoded hash of public key
* **Network** - Different prefixes for mainnet (SP/SM) vs testnet (ST/SN)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stacks.co/cookbook/stacks.js/accounts-and-addresses/derive-stacks-address-from-keys.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
