@powersun/mcp-client
v1.3.0
Published
TypeScript SDK for PowerSun.vip — TRON Energy & Bandwidth marketplace and DEX swap aggregator with 27 MCP tools. Register, buy energy, swap tokens, sell resources, earn passive income.
Maintainers
Readme
@powersun/mcp-client
TypeScript SDK for PowerSun.vip — the TRON Energy & Bandwidth marketplace and DEX swap aggregator with 27 MCP tools for AI agents.
Install
npm install @powersun/mcp-clientQuick Start
import { PowerSun } from '@powersun/mcp-client';
// Public access (market data, estimates)
const ps = new PowerSun();
const prices = await ps.market.getPrices();
const estimate = await ps.market.estimateCost({
txCount: 10,
txType: 'trc20_transfer',
durationMinutes: 60,
});
// Authenticated access (buy energy, check balance)
const client = new PowerSun({ apiKey: 'ps_your_key_here' });
const balance = await client.buyer.getBalance();
const order = await client.buyer.buyEnergy({
targetAddress: 'TYourAddressHere...',
txCount: 5,
durationMinutes: 60,
});HTTP 402 Pay-per-use (No Registration)
import { PowerSun, PaymentRequiredError } from '@powersun/mcp-client';
const ps = new PowerSun(); // no API key
try {
await ps.buyer.buyEnergy({
targetAddress: 'TYourAddressHere...',
txCount: 1,
durationMinutes: 5,
});
} catch (err) {
if (err instanceof PaymentRequiredError) {
// Send TRX to the deposit address
console.log('Deposit address:', err.payment.depositAddress);
console.log('Amount (TRX):', err.payment.requiredAmountTrx);
// Poll for payment confirmation
const status = await ps.paymentStatus(err.payment.intentId);
console.log('Payment status:', status.status);
}
}Registration
const ps = new PowerSun();
// Step 1: Get challenge
const { challengeId, challenge } = await ps.register('TYourAddress...');
// Step 2: Sign challenge with TronLink / tronWeb
const signature = await tronWeb.trx.signMessageV2(challenge);
// Step 3: Verify and get API key
const { apiKey } = await ps.verify(challengeId, 'TYourAddress...', signature);
// Step 4: Use authenticated client
const client = new PowerSun({ apiKey });Token Swap (SunSwap DEX)
const client = new PowerSun({ apiKey: 'ps_your_key_here' });
// Get swap quote (TRX → USDT)
const quote = await client.swap.getQuote({
fromToken: 'TRX',
toToken: 'USDT',
amountIn: '10000000', // 10 TRX in SUN
slippageBps: 100, // 1% slippage
});
console.log('Expected output:', quote.quote.expectedAmountOut);
console.log('Energy cost:', quote.energy.costTrx, 'TRX');
// Sign the unsigned TX with tronWeb
const signedTx = await tronWeb.trx.sign(quote.unsignedTx);
// Broadcast with automatic energy delegation
const result = await client.buyer.broadcast({ txData: signedTx });API Reference
new PowerSun(config?)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiKey | string | — | API key (ps_* format) |
| baseUrl | string | https://powersun.vip | API base URL |
| timeout | number | 30000 | Request timeout (ms) |
Market (public)
ps.market.getPrices()— Price tiers for all durationsps.market.estimateCost(params)— Cost estimateps.market.getAvailableResources()— Available energy/bandwidthps.market.getOverview()— Full market snapshot
Buyer (auth recommended)
ps.buyer.buyEnergy(params)— Purchase energy (API key, 402, or x402)ps.buyer.getBalance()— Account balanceps.buyer.getOrderStatus(orderId)— Order detailsps.buyer.broadcast(params)— Broadcast pre-signed tx with auto Energy (API key, x402, or 402 pay-per-use)
Swap (auth recommended)
ps.swap.getQuote(params)— Get swap quote with unsigned TX for SunSwap DEX (API key, x402, or 402)
Registration (public)
ps.register(address)— Start registrationps.verify(challengeId, address, signature)— Verify & get API keyps.paymentStatus(intentId)— Check 402 payment status
Links
- Platform: powersun.vip
- MCP Server: powersun.vip/mcp
- API Docs: powersun.vip/api-docs
License
MIT
