Skip to content

samuelorobosa/token-auto-buy

Repository files navigation

Token Auto Buy/Sell Application

A production-ready Node.js application for automatically buying and selling tokens via PancakeSwap (BSC) and Jupiter (Solana).

Features

  • BSC Integration: Buy/sell tokens using PancakeSwap
  • Solana Integration: Buy/sell tokens using Jupiter DEX aggregator
  • Transaction Signing: Real blockchain transaction execution
  • Slippage Protection: 5% slippage tolerance
  • Error Handling: Comprehensive error management
  • Production Ready: Proper logging, validation, and security

Prerequisites

  • Node.js 18+
  • npm or yarn
  • BSC wallet with BNB for gas fees
  • Solana wallet with SOL for gas fees

Installation

  1. Clone the repository:
git clone <repository-url>
cd token-auto-buy
  1. Install dependencies:
npm install
  1. Set up environment variables:
cp .env.example .env
  1. Configure your environment variables in .env:
# BSC Configuration
WALLET_PRIVATE_KEY=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
BSC_RPC_URL=https://bsc-dataseed.binance.org

# Solana Configuration
SOLANA_PRIVATE_KEY=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64]
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com

Usage

Start the server:

npm run dev  # Development mode
npm run build && npm start  # Production mode

API Endpoint

POST /api/trade

Request body:

{
  "amount": "0.1",
  "type": "buy",
  "contractAddress": "0x1234567890abcdef1234567890abcdef12345678",
  "network": "BSC",
  "recipient": "0x1234567890abcdef1234567890abcdef12345678"
}

Response:

{
  "success": true,
  "message": "Trade executed successfully",
  "data": {
    "hash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
    "status": "success"
  }
}

Supported Networks

  • BSC: Binance Smart Chain using PancakeSwap
  • SOLANA: Solana using Jupiter DEX aggregator

Supported Operations

  • Buy: Purchase tokens with native currency (BNB/SOL)
  • Sell: Sell tokens for native currency (BNB/SOL)

Testnet Testing

BSC Testnet

BSC_RPC_URL=https://data-seed-prebsc-1-s1.binance.org:8545
BSC_CHAIN_ID=97
PANCAKESWAP_ROUTER=0xD99D1c33F9fC3444f8101754aBC46c52416550D1

Solana Devnet

SOLANA_RPC_URL=https://api.devnet.solana.com

Get Testnet Tokens

Security Features

  • ✅ Private key validation
  • ✅ Address validation
  • ✅ Amount validation
  • ✅ Slippage protection (5%)
  • ✅ Gas limit protection
  • ✅ Transaction confirmation
  • ✅ Comprehensive error handling

Error Handling

The application includes comprehensive error handling for:

  • Invalid wallet configuration
  • Insufficient balances
  • Network errors
  • Transaction failures
  • Invalid addresses
  • Invalid amounts

Development

Project Structure

src/
├── config/          # Network configurations
├── controllers/     # API controllers
├── helpers/         # Utility functions
├── middleware/      # Express middleware
├── routes/          # API routes
├── services/        # Trading services
├── types/           # TypeScript types
└── validators/      # Input validation

Building

npm run build

Testing

npm test

Production Deployment

  1. Set NODE_ENV=production in your environment
  2. Use a secure RPC provider
  3. Ensure proper wallet security
  4. Monitor gas fees and slippage
  5. Set up proper logging and monitoring

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors