@asterpay-io/solana
v1.0.0
Published
AsterPay Solana integration - USDC payments on Solana for AI agents and DePIN
Maintainers
Readme
@asterpay/solana
Solana USDC payments for AI agents and DePIN infrastructure
Overview
@asterpay/solana provides USDC payment capabilities on Solana:
- Fast transfers - Sub-second finality
- Low fees - ~$0.00025 per transaction
- DePIN support - Batch payouts for node operators
- AI agent ready - Programmatic payments
Installation
npm install @asterpay/solana
# or
yarn add @asterpay/solanaQuick Start
Basic USDC Transfer
import { SolanaWallet, SolanaPaymentClient } from '@asterpay/solana';
// Create wallet
const wallet = new SolanaWallet({
privateKey: process.env.SOLANA_PRIVATE_KEY!,
network: 'mainnet-beta'
});
// Create payment client
const client = new SolanaPaymentClient(wallet);
// Send USDC
const result = await client.sendUSDC({
recipient: 'RecipientPublicKey...',
amount: 10.00,
memo: 'Payment for API access'
});
console.log(`TX: ${result.signature}`);
console.log(`Explorer: ${result.explorerUrl}`);DePIN Batch Payouts
import { SolanaWallet, DePINPayoutClient } from '@asterpay/solana';
const wallet = new SolanaWallet({
privateKey: process.env.SOLANA_KEY!,
network: 'mainnet-beta'
});
const payout = new DePINPayoutClient(wallet);
// Pay multiple node operators
const operators = [
{ address: 'operator1...', amount: 5.50, id: 'node-001' },
{ address: 'operator2...', amount: 3.25, id: 'node-002' },
{ address: 'operator3...', amount: 8.00, id: 'node-003' },
// ... up to thousands of recipients
];
const result = await payout.batchPayout(operators, {
concurrency: 10, // Parallel transactions
retryFailed: true, // Retry failures
maxRetries: 3 // Max retry attempts
});
console.log(`Paid: ${result.successful}/${result.total}`);
console.log(`Total: $${result.totalPaid}`);
console.log(payout.generatePayoutReport(result));Check Balance
const wallet = new SolanaWallet({
privateKey: process.env.SOLANA_KEY!,
network: 'mainnet-beta'
});
const balance = await wallet.getBalance();
console.log(`SOL: ${balance.sol}`);
console.log(`USDC: ${balance.usdc}`);Networks
| Network | Use Case | USDC Address |
|---------|----------|--------------|
| mainnet-beta | Production | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v |
| devnet | Development | 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU |
| testnet | Testing | 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU |
DePIN Use Cases
Node Operator Rewards
// Daily rewards distribution
const rewards = await fetchDailyRewards(); // Your reward calculation
const payout = new DePINPayoutClient(wallet);
const result = await payout.batchPayout(rewards, {
concurrency: 20, // Higher concurrency for speed
});
// Generate report for records
const report = payout.generatePayoutReport(result);
await savePayoutReport(report);Epoch-Based Payouts
// Pay rewards at end of epoch
async function processEpochRewards(epochNumber: number) {
const operators = await getEpochRewards(epochNumber);
// Validate before payout
const { valid, invalid } = await payout.validateRecipients(operators);
if (invalid.length > 0) {
console.warn(`${invalid.length} invalid recipients skipped`);
}
// Process valid recipients
const result = await payout.batchPayout(valid);
return {
epoch: epochNumber,
...result
};
}Fee Estimates
| Operation | Est. Fee (SOL) | Est. Fee (USD) | |-----------|----------------|----------------| | Single transfer | 0.000005 | $0.0005 | | With token account creation | 0.002 | $0.20 | | Batch (1000 recipients) | ~1.0 | ~$100 |
API Reference
SolanaWallet
new SolanaWallet({
privateKey: string | Uint8Array, // Base58 or byte array
network?: 'mainnet-beta' | 'devnet' | 'testnet',
rpcUrl?: string, // Custom RPC endpoint
name?: string // Wallet identifier
})SolanaPaymentClient
const client = new SolanaPaymentClient(wallet);
await client.sendUSDC({
recipient: string, // Recipient address
amount: number, // Amount in USD
memo?: string, // Optional memo
priorityFee?: number // Priority fee (micro-lamports)
});DePINPayoutClient
const payout = new DePINPayoutClient(wallet);
await payout.batchPayout(recipients, {
concurrency?: number, // Parallel transactions (default: 5)
retryFailed?: boolean, // Retry failures (default: true)
maxRetries?: number, // Max retries (default: 3)
retryDelay?: number, // Delay between retries (ms)
createTokenAccounts?: boolean // Create accounts if missing
});Security
- Never expose private keys in code
- Use environment variables for keys
- Test on devnet before mainnet
- Set transaction limits for automated systems
Links
- Website: asterpay.io
- Demo: demo.asterpay.io
- Docs: asterpay.io/docs
- Solana USDC: circle.com/usdc
License
MIT License - see LICENSE
