Accounts & Addresses

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

circle-info

In Stacks, the terms address and principal are used interchangeably.

Address formats

Stacks addresses use different prefixes to indicate the network they belong to, making it easy to distinguish between mainnet and testnet addresses.

// Mainnet address starts with 'SP'
const mainnetAddress = 'SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159';

// Mainnet multisig address starts with 'SM'
const multisigMainnetAddress = 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4'

// Testnet multisig address starts with 'SN'
const multisigTestnetAddress = 'SNJSPGVBFZHPXGESC9ZQWVFSNF4RHNNRTW2HYYJ7'

// Testnet address starts with 'ST'
const testnetAddress = 'ST2F4BK4GZH6YFBNHYDDGN4T1RKBA7DA1BJZPJEJJ';

The address format ensures that tokens on testnet cannot be accidentally sent to mainnet addresses and vice versa.

Getting an address

There are several ways to obtain a Stacks address depending on your use case and what cryptographic material you have available.

1

Using Stacks Connect

When building user-facing applications, you'll typically get addresses from users who connect their wallets through Stacks Connect.

Stacks Connect stores the connected addresses in local storage, allowing your app to persist the connection across page reloads.

2

Using a seed phrase

For programmatic wallet generation or when restoring accounts from backup, you can derive addresses from a seed phrase (also known as a mnemonic).

Each wallet can contain multiple accounts, all derived from the same seed phrase using different derivation paths.

3

Using a private key

If you already have a private key, you can directly derive the corresponding address without going through the wallet generation process.

circle-info

Stacks-formatted private keys append a trailing 0x01 to the 32-byte private key to indicate that the derived public key must be encoded in compressed form.

The same private key will generate different addresses for mainnet and testnet due to the network-specific version bytes.

4

Using a public key

When you only have access to a public key (for example, in a watch-only wallet scenario), you can still derive the corresponding address.

This is useful for creating watch-only wallets or verifying addresses without access to private keys.

5

Using a bitcoin address

Bitcoin and Stacks share a similar address generation scheme based on the P2PKH format, which allows for both a Bitcoin & Stacks address to share the same public key hash. If you base58check decode a legacy bitcoin address, you can reveal the public key hash, which can then be used to generate its respective c32check encoded Stacks address.

Address validation

Before sending transactions, it's important to validate that addresses are properly formatted.

Always validate addresses before using them in transactions to prevent loss of funds due to typos or formatting errors.

Last updated

Was this helpful?