0%
Overview page background
HomeOverviewsSolana
What is an Solana Associated Token Account on Solana?

What is an Solana Associated Token Account on Solana?

Petar Todorov headshot

Written by Petar Todorov

Brady Werkheiser headshot

Reviewed by Brady Werkheiser

Published on January 26, 20234 min read

The Solana Account Model organizes and stores all on-chain data, and Associated Token Accounts (ATAs) are one of the key pieces of that model. This article will explain what an ATA is, how it works, and how to create an Associated Token Account for yourself.

An Associated Token Account is created via the Solana Associated Token Account Program, which holds information about a specific token, its balance, and its owner. It is a variant of a Program Derived Address.

Here’s what each term means:

  • Associated Token Account - an account that is associated with a token (think of Solana Token Program)

  • Program Derived Address - an address that has been “derived” (created) from a Solana Program, namely, the Associated Token Account Program

Transfers between Associated Token Accounts occur directly between the accounts, and indirectly through their wallet addresses.

Token accounts are the equivalent of an ERC-20 token on Ethereum, but with a foundational difference: Ethereum smart contracts own its state and code, and a token account on Solana contains only its code and “exports” its state (e.g. token balance) into an Associated Token Account, which is created for each owner of that token.

Let’s quickly examine USDC for an overview of what we’ve learned so far:

  • USDC on Solana is a token account

  • A token account is created by the System Program but initialized as Token mint by the SPL Token Program

  • Once the USDC token has been initiated, users can start making transfers

  • Users with USDC tokens have Associated Token Accounts that are created through the Associated Token Account Program (ATP)

  • The exchange of USDC between two people happens between the users’ ATAs

Associated Token Account on Solana
Associated Token Account on Solana

USDC transfers directly occur between the users’ ATAs and indirectly between their wallet addresses on Solana nodes. These transfers must be between users, whose ATAs have been created with the same token mint seed.

Being part of the Solana Program Library, the Associated Token Account Program is the parent program for every ATA, that maps a user’s wallet to the ATAs that he has authority over. Additionally, the ATA Program ensures that if a user wants to send a token to another user, the recipient will get it, even if he does not have an ATA for the corresponding token. The program will automatically create an ATA account in this case while the smart contract is executed on an RPC node.

The source code for the Associated Token Account Program is written in Rust and can be checked on GitHub.

Here’s how an ATA is created under the hood on TypeScript:

Source code for creating the Associated Account Program on Solana
Source code for creating the Associated Account Program on Solana

Here's what is happening in the ATA program:

First, we get the `TOKEN_PROGRAM_ID` and `SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID` constants. A program ID is a fancier name for the program’s address.

Then, we proceed with the `findAssociatedTokenAddress` function, which returns publicKey, which will be the address of the newly created ATA.

In the body of the function, the `findProgramAddress` method is invoked and two arguments are passed to it:

  • An Array of Seeds

  • SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID

Since ATA is a form of a Program Derived Address (PDA), the account can be created by passing arguments to the program. The creation of a PDA involves passing seeds as arguments and in this case, they are:

  1. wallet_address - the address of the account, which will own the funds in the ATA (authority)

  2. token_program_id - the program ID of the SPL Token Program

  3. token_mint_address - the address of the Token account that will be stored in the ATA

The ID of the Associated Token Account Program is SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID.

Creating an Associated Token Account is as simple as calling create-token using the spl-token-cli on Solana. Creating an ATA also assumes that the token with which it will be “associated” already exists.

Creating an associated token account on Solana
Creating an associated token account on Solana

‍The code invokes the `create-account` command, which accepts `<TOKEN_MINT_ADDRESS>` as an argument.

To create an Associated Token Account, you must follow these four steps:

  1. Transfer SOL - the System Program initializes the ATA and makes it rent-exempt

  2. Create Free Space - the System Program assigns free space for the ATA.

  3. Transfer Ownership - he System Program transfers ownership of the account to the SPL Associated Token Account Program

  4. Initialize the Account - the process summarizes the account initialization and sets the token address, the newly created ATA address, and its owner

Owner is the type of Solana program that controls the ATA, while authority is the account (wallet), that sends a transaction to the owner program, which then changes the data in the ATA on behalf of the authority.

By default, Associated Token Accounts must be marked as rent-exempt upon their creation, so the minimum amount that an account must hold should be at least 0.00203928 SOL. The System Program transfers this SOL to the ATA, which is deducted from the account that initiating the transaction. 

Other than that initial fee, any further interaction will cost no more than an ordinary transaction on Solana.

You can check an Associated Token Account through clients like Phantom that automatically derive all the ATAs that a user’s wallet has authority over. Additionally, since the blockchain is public, you can also access this information with the help of an explorer like Solscan.io.

Paste the address of the wallet that you’d like to check and its ATAs will be visualized under Token Accounts:

Solscan.io interface to check ATAs of a wallet
Solscan.io interface to check ATAs of a wallet

Linking an Associated Token Account to an existing account is done by default behind the scenes. Due to the way an ATA is created, a program or a client can easily see the seeds of every account. They could be regarded as ‘links’ to:

  • the wallet that has authority over the ATA.

  • the address of the Token account (i.e. the token type that the ATA holds).

Learning about the Associated Token Account is one of the first steps to becoming a fully-fledged Solana developer. You can use our user-friendly Solana API to get a head start on building your first dApp once you've mastered Solana nodes and selected an RPC provider.

Overview cards background graphic
Desktop section background image

Build blockchain magic

Alchemy combines the most powerful web3 developer products and tools with resources, community and legendary support.

Get your API key