Markdown Converter
Agent skill for markdown-converter
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Sign in to like and favorite skills
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A browser-based API wrapper for GMGN.ai that enables automated trading operations on Binance Smart Chain (BSC). The system uses Playwright to maintain persistent browser sessions, bypassing Cloudflare protection by acting as a real browser.
Type: Node.js application using ES modules Language: JavaScript Key Technology: Playwright for browser automation
# Install dependencies npm install # First-time setup: Launch browser for manual login node setup-browser-session.js # This opens a browser window - login to GMGN.ai manually, then press Enter # Session is saved to .gmgn-session.json (cookies, localStorage, token) # Test the API node example-usage.js
# Run usage example node example-usage.js # Run specific tests node test-price-api.js node test-all-features-browser.js node test-price-polling.js
GmgnBrowserAPI (
gmgn-browser-api.js)
init() - Initialize browser (call once, browser stays open)getTokenPrice(address) - Query token price with historical datagetBNBBalance(wallet?) - Get BNB balancegetTokenBalance(tokenAddress, wallet?) - Get token balancegetHoldings(tokenAddress, wallet?) - Get position info (avg cost, P&L)getMultiTokenPrices(addresses[]) - Batch price querygetTokenInfo(address) - Token statisticsclose() - Close browser and release resourcesBrowser Authentication Flow
setup-browser-session.js - Interactive setup script (user runs once)browser-auth.js - BrowserAuth class handles browser automation
token-manager.js - TokenManager class manages session persistence
.gmgn-session.jsonConfiguration
gmgn-config.js - Centralized config with:
Initial Setup Flow:
node setup-browser-session.js.gmgn-session.jsonRuntime Flow:
.gmgn-session.jsonpage.evaluate() with real browser contextWhy Browser Automation:
All API methods follow this pattern:
// Execute fetch() inside browser context const result = await this.page.evaluate( async ({ endpoint, body }) => { // Get token from localStorage (injected during init) const tgInfo = JSON.parse(localStorage.getItem('tgInfo')); const token = 'Bearer ' + tgInfo.token.access_token; // Make request with browser's fetch (has valid session) const response = await fetch(endpoint, { headers: { 'authorization': token }, credentials: 'include' }); return await response.json(); }, { endpoint, body } );
This executes fetch within the browser page context, ensuring all cookies and session state are valid.
Located in
browser-auth.js and gmgn-browser-api.js:
--disable-blink-features=AutomationControllednavigator.webdriver = falseOptional (most config comes from session file):
GMGN_WALLET_ADDRESS=0xYourWalletAddress # Default wallet for queries GMGN_AUTH_TOKEN=jwt_token # Fallback if session missing BSC_RPC_URL=https://bsc-dataseed1.binance.org # For on-chain queries DEFAULT_SLIPPAGE=40 # 4% slippage DEFAULT_EXPIRES_DAYS=3 # Order expiration
Session File (
.gmgn-session.json):
setup-browser-session.jstoken, cookies, localStorage, expiresAtnode setup-browser-session.js before any API usage.gmgn-session.json in project rootsetup-browser-session.jsinit()close() is called or process exitsAll methods return:
{ success: true/false, data: { ... }, // on success error: "message" // on failure }
Multiple
test-*.js files demonstrate specific features:
test-all-features-browser.js - Complete feature testtest-price-api.js - Price query teststest-price-polling.js - Continuous price monitoringGmgnBrowserAPI class in gmgn-browser-api.js_apiCall() helper for GET requestspage.evaluate() for POST or complex requestsasync getNewFeature(param) { const endpoint = `https://gmgn.ai/api/v1/new_endpoint`; const result = await this._apiCall('GET', endpoint); if (result.success && result.data) { return { success: true, data: processData(result.data) }; } return { success: false, error: result.error || 'Query failed' }; }
await chromium.launch({ headless: false })
await this.page.waitForTimeout(5000);
cat .gmgn-session.json
this.page.on('request', req => console.log(req.url()));
"沒有保存的會話":
node setup-browser-session.js first.gmgn-session.json exists"未檢測到登入狀態":
.gmgn-session.jsonnode setup-browser-session.jsAPI returns errors:
api.isReady())Browser crashes or hangs:
api.close() and api.init() to restartgmgn-browser-api.js - Main API classbrowser-auth.js - Browser authenticationtoken-manager.js - Token/session managementgmgn-config.js - Configurationsetup-browser-session.js - Initial setup toolexample-usage.js - Comprehensive usage demotest-*.js - Various feature tests.gmgn-session.json - Saved session (auto-generated).env - Optional environment configThis codebase replaced earlier approaches that used:
Current approach uses browser automation for maximum reliability and feature access to GMGN.ai's API.