Solana Action
Solana Action¶
Solana Actions is an innovative feature launched by the Solana blockchain that allows users to execute blockchain transactions directly through simple URL links on any website, social media, or application without needing to navigate to a DApp or wallet interface. This technology is implemented through the Solana Actions API and Blinks (Blockchain Links), significantly lowering the barrier to Web3 interaction and opening new possibilities for blockchain application promotion and adoption.
Core Concepts of Solana Actions¶
1. Actions¶
Actions are executable blockchain operations:
- Standardized Interface: API endpoints following the Solana Actions specification
- Transaction Building: Server-side transaction construction for user signing
- Rich Metadata: Includes title, description, icon, and other display information
- Interactive: Supports user input parameters
- Embeddable: Can be displayed and executed on any supported platform
2. Blinks (Blockchain Links)¶
Blinks are the visual representation of Actions:
- Rich Media Cards: Display Action information in card format
- One-Click Execution: Users click to trigger transactions
- Dynamic Rendering: Supported platforms automatically render Action URLs as interactive cards
- Cross-Platform: Works on Twitter, Discord, websites, and more
- Instant Feedback: Real-time transaction status and result display
3. Actions API¶
Standardized API interface:
- GET Request: Retrieves Action metadata and interaction parameters
- POST Request: Submits user input and returns a transaction for signing
- Standard Response: Unified JSON response format
- CORS Support: Cross-Origin Resource Sharing configuration
- Security: Transactions are signed by the user's wallet, ensuring security
How Solana Actions Work¶
Execution Flow¶
- Discover Action: User sees an Action URL (Blink)
- Render Interface: Supported client calls GET request to retrieve metadata
- Display Card: Metadata is rendered as an interactive card
- User Interaction: User enters parameters (e.g., amount) and clicks execute
- Build Transaction: Client calls POST request to get the serialized transaction
- Sign Confirmation: User's wallet prompts for signature
- Broadcast Transaction: After signing, sends to the Solana network
- Result Display: Shows transaction hash and status
API Specification¶
GET Endpoint:
{
"icon": "https://example.com/icon.png",
"title": "Donate to Project",
"description": "Support our open source project",
"label": "Donate",
"links": {
"actions": [
{
"label": "Donate 0.1 SOL",
"href": "/api/actions/donate?amount=0.1"
},
{
"label": "Donate 1 SOL",
"href": "/api/actions/donate?amount=1"
},
{
"label": "Custom Amount",
"href": "/api/actions/donate?amount={amount}",
"parameters": [
{
"name": "amount",
"label": "Enter SOL amount"
}
]
}
]
}
}
POST Endpoint Response:
{
"transaction": "base64-encoded serialized transaction",
"message": "Thank you for your donation!"
}
Solana Actions Use Cases¶
1. Social Media Integration¶
Enabling blockchain interaction on social platforms:
- Twitter Tipping: Tip SOL or tokens directly below tweets
- NFT Minting: Share NFT minting links on social media
- Governance Voting: Share DAO proposal voting links
- Crowdfunding: Project crowdfunding links shared on social media
- Airdrop Claiming: Click links to claim airdrops
2. E-Commerce and Payments¶
Simplifying crypto payment flows:
- Product Purchases: Generate product purchase links; users click to pay
- Subscription Services: One-click service subscription and payment
- Tips and Donations: Content creators share tipping links
- Group Payments: Split payments and group payments
- Recurring Payments: Automated subscription payments
3. DeFi Operations¶
Lowering the barrier to DeFi usage:
- Token Swaps: Share token swap links
- Liquidity Provision: One-click liquidity addition
- Staking: Simplified staking operations
- Lending: Quick lending operations
- Yield Farming: One-click yield farming participation
4. NFTs and Gaming¶
Gaming and NFT scenarios:
- NFT Purchases: Share NFT purchase links
- In-Game Purchases: Game item purchases
- Tournament Registration: On-chain game tournament sign-up
- Achievement Unlock: Game achievement NFT minting
- Mystery Box: NFT mystery box purchase and opening
5. DAO Governance¶
Decentralized governance:
- Proposal Voting: Share voting links in communities
- Member Joining: DAO member registration links
- Funding Requests: Fund allocation requests and voting
- Permission Management: Permission change voting
- Parameter Adjustment: Protocol parameter adjustment voting
Developing Solana Actions¶
1. Creating an Actions API¶
Creating an Actions API with Next.js:
// app/api/actions/donate/route.ts
import { ActionGetResponse, ActionPostRequest, ActionPostResponse } from '@solana/actions';
import { Transaction, SystemProgram, PublicKey, LAMPORTS_PER_SOL } from '@solana/web3.js';
const DONATION_ADDRESS = new PublicKey('your-wallet-address');
export async function GET(request: Request) {
const payload: ActionGetResponse = {
icon: 'https://yoursite.com/icon.png',
title: 'Support Our Project',
description: 'Your donation will help us continue developing',
label: 'Donate',
links: {
actions: [
{
label: 'Donate 0.1 SOL',
href: '/api/actions/donate?amount=0.1'
},
{
label: 'Donate 1 SOL',
href: '/api/actions/donate?amount=1'
},
{
label: 'Custom Amount',
href: '/api/actions/donate?amount={amount}',
parameters: [
{
name: 'amount',
label: 'Enter SOL amount',
required: true
}
]
}
]
}
};
return Response.json(payload, {
headers: {
'X-Action-Version': '2.0',
'X-Blockchain-Ids': 'solana:mainnet'
}
});
}
export async function POST(request: Request) {
const body: ActionPostRequest = await request.json();
const { searchParams } = new URL(request.url);
const amount = Number(searchParams.get('amount') || 0.1);
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: new PublicKey(body.account),
toPubkey: DONATION_ADDRESS,
lamports: amount * LAMPORTS_PER_SOL
})
);
transaction.feePayer = new PublicKey(body.account);
transaction.recentBlockhash = (
await connection.getLatestBlockhash()
).blockhash;
const payload: ActionPostResponse = {
transaction: transaction.serialize({
requireAllSignatures: false
}).toString('base64'),
message: `Thank you for donating ${amount} SOL!`
};
return Response.json(payload);
}
2. Configuring actions.json¶
Configure at the website root:
3. Testing Actions¶
Test using Dialect's Actions inspector:
Platforms Supporting Blinks¶
1. Twitter/X¶
Supported via browser extensions:
- Dialect Blinks: Chrome extension that automatically renders Blinks
- Display Method: Action URLs are automatically converted to interactive cards
- Execution: Click card buttons to execute transactions directly
- Sharing: Anyone can share Action URLs in tweets
2. Discord¶
Bots and integrations:
- Blinks Bot: Discord bot that renders Blinks
- Channel Integration: Share and execute Actions in channels
- Community Interaction: Community members directly participate in on-chain operations
- Automation: Linked with Discord events
3. Websites and Applications¶
Direct embedding:
- React Components: Use
@dialectlabs/blinkscomponent library - Custom Styling: Customize Blink appearance
- Mobile: Supports mobile wallets
- Embedded: Embed in any webpage
4. Wallet Integration¶
Mainstream wallet support:
- Phantom: Native Actions support
- Solflare: Supports Blinks rendering
- Backpack: Integrated Actions functionality
- Mobile Wallets: Supported via deep links
Best Practices¶
1. User Experience¶
- Clear Description: Provide detailed Action explanations
- Icon Design: Use high-quality, recognizable icons
- Parameter Validation: Validate user input legitimacy
- Error Handling: Friendly error messages
- Instant Feedback: Real-time transaction status display
2. Security¶
- Transaction Validation: Server-side validation of transaction parameters
- Amount Limits: Set reasonable minimum and maximum amounts
- Rate Limiting: Prevent abuse and attacks
- Audit Checks: Regularly audit Actions code
- User Confirmation: Require secondary confirmation for important operations
3. Performance Optimization¶
- Caching Strategy: Cache metadata to reduce requests
- Fast Response: Optimize API response time
- CDN Acceleration: Use CDN for icons and resources
- Compressed Transfer: Enable GZIP compression
- Preloading: Preload frequently used transaction data
4. SEO and Sharing¶
- Open Graph: Configure OG tags
- Metadata: Rich metadata improves discoverability
- Social Sharing: Optimize social media sharing effectiveness
- Short Links: Use short links to improve distribution
- Analytics: Track Action usage data
Ecosystem Tools¶
Development Tools¶
- @solana/actions: Official Actions SDK
- @dialectlabs/blinks: Blinks React component library
- Actions Inspector: Actions debugging tool
- Blinks Preview: Blinks preview tool
Reference Resources¶
- Official Documentation: Solana Actions specification documentation
- Example Projects: Sample code on GitHub
- Community Tutorials: Tutorials and guides from the Solana community
- Tool Collection: Awesome Solana Actions list
Future Development¶
Potential Applications¶
- AI Integration: AI agents executing on-chain operations via Actions
- IoT: IoT devices triggering Actions
- AR/VR: On-chain interactions in virtual worlds
- Cross-chain Extension: Expanding to other blockchains
- Enterprise Applications: Enterprise-grade Actions solutions
Ecosystem Growth¶
- More Platforms: More platforms natively supporting Blinks
- Tool Improvement: Continuous improvement of development tools and infrastructure
- Standard Unification: Cross-chain Actions standard development
- User Growth: Growing user acceptance and usage
- Innovative Applications: More innovative use cases emerging
Related Concepts and Technologies¶
- Solana: The blockchain Solana Actions belongs to
- Phantom: A mainstream wallet supporting Actions
- Dialect: The primary driver of Blinks technology
- Web3: The new paradigm of the decentralized internet
Summary¶
Solana Actions dramatically lowers the barrier to Web3 usage by simplifying complex blockchain interactions into simple URL links. Blinks' visual presentation makes blockchain operations as simple as clicking a button, paving the way for mass adoption of blockchain applications. For developers, Actions provides a standardized interface that makes creating shareable, embeddable blockchain applications easier than ever. As the ecosystem continues to improve and more platforms offer support, Solana Actions is poised to become a significant breakthrough in Web3 user experience, driving blockchain technology toward mainstream adoption.