Accounts & Addresses

Learn how to get an address from an account.


Stacks uses the concept of an "account" to represent a user's identity on the blockchain. An account is identified by a unique address. The address is derived from the account's public key, which is derived from the account's private key.

A normal mainnet address starts with SP, and a testnet address starts with ST. For example:

Mainnet: SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159

Testnet: ST2F4BK4GZH6YFBNHYDDGN4T1RKBA7DA1BJZPJEJJ

Getting an address

Using Stacks Connect

1
import { showConnect } from '@stacks/connect';
2
3
showConnect({
4
appDetails,
5
userSession,
6
onFinish: () => {
7
const user = userSession.loadUserData();
8
const address = user.profile.stxAddress.mainnet;
9
// 'SP1MXSZF4NFC8JQ1TTYGEC2WADMC7Y3GHVZYRX6RF'
10
},
11
});

Using a seed phrase / mnemonic / private key

1
import { randomSeedPhrase, generateWallet } from "@stacks/wallet-sdk";
2
import { privateKeyToAddress } from "@stacks/transactions";
3
4
const seed = randomSeedPhrase();
5
6
const wallet = await generateWallet({
7
secretKey: seed,
8
password: 'secret',
9
});
10
11
const address = privateKeyToAddress(wallet.accounts[0].stxPrivateKey, 'mainnet');
12
// 'SP1MXSZF4NFC8JQ1TTYGEC2WADMC7Y3GHVZYRX6RF'

Using a public key

1
import { publicKeyToAddress } from '@stacks/transactions';
2
3
const address = publicKeyToAddress(publicKey, 'mainnet');
4
// 'SP1MXSZF4NFC8JQ1TTYGEC2WADMC7Y3GHVZYRX6RF'