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

import { showConnect } from '@stacks/connect';

showConnect({
  appDetails,
  userSession,
  onFinish: () => {
    const user = userSession.loadUserData();
    const address = user.profile.stxAddress.mainnet;
    // 'SP1MXSZF4NFC8JQ1TTYGEC2WADMC7Y3GHVZYRX6RF'
  },
});

Using a seed phrase / mnemonic / private key

import { randomSeedPhrase, generateWallet, privateKeyToAddress } from "@stacks/wallet-sdk";

const seed = randomSeedPhrase();

const wallet = await generateWallet({
  secretKey: seed,
  password: 'secret',
});

const address = privateKeyToAddress(wallet.accounts[0].stxPrivateKey, 'mainnet');
// 'SP1MXSZF4NFC8JQ1TTYGEC2WADMC7Y3GHVZYRX6RF'

Using a public key

import { publicKeyToAddress } from '@stacks/transactions';

const address = publicKeyToAddress(publicKey, 'mainnet');
// 'SP1MXSZF4NFC8JQ1TTYGEC2WADMC7Y3GHVZYRX6RF'