What are Solana Actions?

icon picker
Implementing Solana Actions

Basic Implementation

Define Action URL:
javascript
Copy code
const actionUrl = 'https://actions.example.com/transaction';

Create Action Endpoint:
Define a GET route to provide human-readable information.
Define a POST route to handle transaction construction and signing.
const express = require('express');
const app = express();

app.get('/transaction', (req, res) => {
res.json({
name: 'Transaction Example',
description: 'An example transaction action',
});
});

app.post('/transaction', (req, res) => {
// Logic to create and return a transaction for signing
});

app.listen(3000, () => console.log('Server running on port 3000'));

Integrate with Dialect:
const { Dialect, SolanaDialectWalletAdapter } = require('@dialectlabs/sdk');

const dialect = new Dialect({
wallet: new SolanaDialectWalletAdapter({ connection }),
});

dialect.createNotification({
title: 'Action Required',
message: 'Sign the transaction',
action: {
type: 'link',
url: actionUrl,
},
});

console.log('Notification created');

Advanced Implementation

Multi-Actions: Group multiple actions in a single GET call.
Complex Transactions: Handle more sophisticated transaction scenarios by using advanced routing and transaction construction logic.
javascript
Copy code
app.post('/complex-transaction', (req, res) => {
const { actionType } = req.body;
if (actionType === 'swap') {
// Logic for swap action
} else if (actionType === 'stake') {
// Logic for stake action
}
res.send('Transaction created');
});

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.