Create and manage TipLinks for transferring SOL and SPL tokens on Solana. This implementation enables quick creation of shareable links for token transfers with comprehensive transaction handling and error management.
Core Features
-
TipLink Creation
- SOL transfer support
- SPL token support
- Associated account creation
- Transaction optimization
-
Transaction Management
- Compute budget handling
- Minimum balance management
- Multi-instruction bundling
- Confirmation handling
Usage
Create SOL TipLink
// Create TipLink for SOL transfer
const { url, signature } = await create_TipLink(
agent,
1.0 // Amount in SOL
);
// Returns TipLink URL and transaction signature
console.log(url, signature);
Create SPL Token TipLink
// Create TipLink for SPL token transfer
const { url, signature } = await create_TipLink(
agent,
100, // Amount in token units
new PublicKey("TokenMintAddress")
);
// Returns TipLink URL and transaction signature
console.log(url, signature);
Data Structures
TipLink Response
interface TipLinkResponse {
url: string; // TipLink URL
signature: string; // Transaction signature
}
Example Prompts
Natural Language Prompts
"Create a TipLink for 1 SOL"
"Generate a link to send 100 USDC"
"Make a TipLink for sending BONK tokens"
"Create a shareable link for 5 SOL"
// SOL transfer
{
"amount": 1.0
}
// SPL token transfer
{
"amount": 100,
"splmintAddress": "TokenMintAddress123"
}
Implementation Details
SOL Transfer Implementation
async function createSolTipLink(
agent: SolanaAgentKit,
amount: number
): Promise<TipLinkResponse> {
const tiplink = await TipLink.create();
const transaction = new Transaction();
transaction.add(
SystemProgram.transfer({
fromPubkey: agent.wallet_address,
toPubkey: tiplink.keypair.publicKey,
lamports: amount * LAMPORTS_PER_SOL,
})
);
return sendAndConfirmTransaction(...);
}
SPL Token Implementation
async function createSplTipLink(
agent: SolanaAgentKit,
amount: number,
splmintAddress: PublicKey
): Promise<TipLinkResponse> {
const tiplink = await TipLink.create();
const transaction = new Transaction();
// Add compute budget instruction
// Add minimum SOL transfer
// Create ATA
// Transfer tokens
return sendAndConfirmTransaction(...);
}
Error Handling
try {
const result = await create_TipLink(agent, amount, splmintAddress);
} catch (error) {
if (error.message.includes("insufficient balance")) {
// Handle insufficient funds
} else if (error.message.includes("invalid account")) {
// Handle invalid accounts
}
}
Best Practices
-
Transaction Optimization
- Set compute budget
- Bundle instructions
- Handle confirmations
- Validate inputs
-
Balance Management
- Check balances
- Include rent
- Handle decimals
- Validate amounts
-
Error Management
- Handle timeouts
- Validate responses
- Log errors
- Implement retries
Common Issues
-
Transaction Issues
- Insufficient balance
- Invalid accounts
- Failed confirmations
- Timeout errors
-
Token Issues
- Missing ATAs
- Invalid mints
- Decimal mismatches
- Transfer failures
-
Network Issues
- Connection errors
- Confirmation delays
- RPC issues
- Timeout errors
Success Response
{
status: "success",
url: "https://tiplink.io/t/...",
signature: "transaction-signature",
amount: 1.0,
tokenType: "SOL", // or "SPL"
}
Error Response
{
status: "error",
message: "Error message",
code: "ERROR_CODE"
}
Tips for TipLink Creation
-
Transaction Building
- Order instructions properly
- Include all necessary accounts
- Set proper compute budget
- Handle confirmations
-
Token Handling
- Check decimals
- Validate addresses
- Create ATAs
- Handle balances
-
Error Prevention
- Validate inputs
- Check balances
- Handle timeouts
- Log operations
Common Token Addresses
const COMMON_TOKENS = {
USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
SOL: "So11111111111111111111111111111111111111112",
BONK: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"
};
Resources