a month ago
The variables are always returning an error either about bad size, or not 58base, or 64 base, they are in my .env file in the node.js project. It is for the SOlana blockchain trying to sell a token for cash. The cash accepting works, but wont transfer tokens because of the variable not being encoded in the right format base58 or 62, always a size error. Now it wont deploy anymore either.
1 Replies
23 days ago
I can help you troubleshoot the Solana token selling issue
. This sounds like you're dealing with keypair/public key encoding problems. Let me address the common issues
Common Problems with Solana Keys
Base58 vs Base64 confusion:
Solana public keys use Base58 encoding
Private keys (secret keys) are typically stored as Base64 or byte arrays
The .env file format matters
Here's what you likely need
import { Keypair, PublicKey } from '@solana/web3.js';
import bs58 from 'bs58';
// For private key (from phantom wallet export or solana CLI):
// If it's a byte array [1,2,3,...] format:
const privateKey = JSON.parse(process.env.PRIVATE_KEY);
const keypair = Keypair.fromSecretKey(new Uint8Array(privateKey));
// If it's base58 string (more common):
const keypair = Keypair.fromSecretKey(bs58.decode(process.env.PRIVATE_KEY));
// For public key (token mint, recipient addresses):
const tokenMint = new PublicKey(process.env.TOKEN_MINT_ADDRESS);
Your .env should look like
# Private key as base58 string
PRIVATE_KEY=your_base58_private_key_here
# or as byte array (from Phantom export)
PRIVATE_KEY=[123,45,67,...]
# Public addresses are always base58
TOKEN_MINT_ADDRESS=TokenMintAddress111111111111111111111
RECIPIENT_ADDRESS=RecipientAddress11111111111111111111
Common fixes
Install bs58 if you haven't: npm install bs58
Check your private key format - export from Phantom gives you a byte array, Solana CLI gives base58
Public keys should never be decoded - pass them directly to new PublicKey()












