current location:Home >> Blockchain knowledge >> how to add tokens onto solana account ledger

how to add tokens onto solana account ledger

admin Blockchain knowledge 134

There are several ways to add tokens to a Solana account's ledger. Here are the main methods:

1. Token Minting (For Token Creators)

how to add tokens onto solana account ledger

If you own the token mint authority:

import { mintTo } from '@solana/spl-token';

// Mint new tokens to a specific account
const transactionSignature = await mintTo(
  connection,
  payer,
  mintAddress,
  destinationAccount,
  authority,
  amount
);

2. Token Transfer (For Users)

Receive tokens from another account:

  • Sender initiates the transfer

  • Receiver needs a token account for that specific mint

import { getOrCreateAssociatedTokenAccount, transfer } from '@solana/spl-token';

// Create token account if it doesn't exist
const toTokenAccount = await getOrCreateAssociatedTokenAccount(
  connection,
  payer,
  mintAddress,
  receiverPublicKey
);

// Transfer tokens
await transfer(
  connection,
  payer,
  fromTokenAccount.address,
  toTokenAccount.address,
  owner,
  amount
);

3. Using Wallets

Phantom Wallet Example:

// Connect wallet first
const provider = window.solana;
await provider.connect();

// Wallet will automatically create token accounts
// when receiving tokens

4. Common Token Actions

Check Token Balance:

import { getAccount } from '@solana/spl-token';

const tokenAccount = await getAccount(connection, tokenAccountAddress);
console.log(Number(tokenAccount.amount));

Create Token Account (if needed):

import { createAssociatedTokenAccount } from '@solana/spl-token';

const tokenAccount = await createAssociatedTokenAccount(
  connection,
  payer,
  mintAddress,
  ownerPublicKey
);

5. Important Notes

  1. Associated Token Account (ATA): Most wallets use ATAs which are PDAs derived from owner and mint addresses

  2. Rent Exemption: Token accounts require SOL for rent (currently ~0.00203928 SOL)

  3. Mint-Specific: Each token type requires a separate token account

  4. Authority: Token accounts have owner authority (can transfer) and optional close authority

6. Troubleshooting

"Token account does not exist": Create the token account first
"Insufficient SOL": Need SOL for transaction fees and rent
"Invalid owner": Ensure you're using the correct owner/keypair

7. Complete Example

import { Connection, PublicKey, Keypair } from '@solana/web3.js';
import { getOrCreateAssociatedTokenAccount, transfer } from '@solana/spl-token';

const connection = new Connection('https://api.mainnet-beta.solana.com');
const mintAddress = new PublicKey('...');
const sender = Keypair.fromSecretKey(...);
const receiver = new PublicKey('...');

// Get or create receiver's token account
const receiverTokenAccount = await getOrCreateAssociatedTokenAccount(
  connection,
  sender,
  mintAddress,
  receiver
);

// Now receiver can receive tokens to this account

Note: Always verify addresses and test with small amounts first. Use devnet for testing before mainnet transactions.

If you have any questions or uncertainties, please join the official Telegram group: https://t.me/GToken_EN

GTokenTool

GTokenTool is the most comprehensive one click coin issuance tool, supporting multiple public chains such as TON, SOL, BSC, etc. Function: Create tokensmarket value managementbatch airdropstoken pre-sales IDO、 Lockpledge mining, etc. Provide a visual interface that allows users to quickly create, deploy, and manage their own cryptocurrencies without writing code.

Similar recommendations