💎
Beginner Tutorial

Beginner Tutorial: Building Your First AI-Powered Workflow with Solana Synq
Welcome to Solana Synq, where we integrate AI-powered tools into the Solana ecosystem. In this beginner tutorial, you’ll learn how to set up your environment, interact with Solana Synq, and build a simple AI-driven workflow for analyzing on-chain transaction data.
Step 1: Prerequisites
Before starting, make sure you have the following:
Installed Tools:
Python 3.8 or later
Node.js 16.x or later
Solana CLI installed (solana --version
)
Solana Test Wallet: Create one using the Solana CLI:
bashCopy codesolana-keygen new --outfile ~/.config/solana/id.json
Basic Knowledge: Familiarity with Python, JavaScript, or TypeScript is helpful.
Step 2: Installing Solana Synq
The Solana Synq framework (Solana Synq) is available for both Python and JavaScript/TypeScript.
For Python:
Install the SolanaSynq library:
bashCopy codepip install SolanaSynq
For JavaScript/TypeScript:
Install the package using npm:
bashCopy codenpm install SolanaSynq
Step 3: Setting Up Your Project
Create a folder for your project and initialize your preferred language environment.
Python:
bashCopy codemkdir SolanaSynq-tutorial
cd SolanaSynq-tutorial
python -m venv venv
source venv/bin/activate
JavaScript/TypeScript:
bashCopy codemkdir SolanaSynq-tutorial
cd SolanaSynq-tutorial
npm init -y
Step 4: Initializing the Solana Synq Client
Python Example:
Create a file named main.py
and add the following:
pythonCopy codefrom SolanaSynq import SolanaSynqClient
# Initialize Synapse Client
client = SolanaSynqClient(api_key="your_api_key")
# Verify connection
print("SolanaSynq Client Initialized:", client)
Run the script:
bashCopy codepython main.py
JavaScript/TypeScript Example:
Create a file named index.js
and add the following:
javascriptCopy codeconst { SynapseClient } = require('solsynapse');
// Initialize Solana Synq Client
const client = new SynapseClient({ apiKey: 'your_api_key' });
// Verify connection
console.log('Synapse Client Initialized:', client);
Run the script:
bashCopy codenode index.js
Step 5: Loading a Pre-Trained Model
Solana Synapse includes pre-trained models for tasks like sentiment analysis, trading, and data visualization. Let’s load the sentiment analysis model.
Python:
pythonCopy code# Load sentiment analysis model
model = client.load_model("sentiment-analysis")
# Display model info
print("Loaded Model:", model)
JavaScript:
javascriptCopy code// Load sentiment analysis model
const sentimentModel = client.loadModel('sentiment-analysis');
// Display model info
console.log('Loaded Model:', sentimentModel);
Step 6: Fetching Blockchain Data
Use Solana Synapse to fetch recent Solana blockchain transactions.
Python:
pythonCopy code# Fetch blockchain data
transactions = client.fetch_chain_data("recent_transactions", chain="Solana")
# Display the first few transactions
print("Recent Transactions:", transactions[:5])
JavaScript:
javascriptCopy code// Fetch blockchain data
client.fetchChainData('recent_transactions', 'Solana').then((data) => {
console.log('Recent Transactions:', data.slice(0, 5));
});
Step 7: Analyzing Blockchain Data with AI
Now, let’s analyze the sentiment of recent transactions using the pre-trained model.
Python:
pythonCopy code# Analyze sentiment
results = model.infer(transactions)
# Display sentiment analysis results
print("Sentiment Analysis Results:", results)
JavaScript:
javascriptCopy code// Analyze sentiment
client.fetchChainData('recent_transactions', 'Solana').then((data) => {
const results = sentimentModel.infer(data);
console.log('Sentiment Analysis Results:', results);
});
Step 8: Automating Workflows
To automate repetitive tasks, use the Workflow Automator. For example, set up an alert for negative sentiment on transactions.
Python:
pythonCopy code# Define a callback function for negative sentiment
def alert_on_negative_sentiment(results):
for result in results:
if result["sentiment"] == "negative":
print("⚠️ Negative Sentiment Detected:", result)
# Automate sentiment analysis
client.workflow_automator.add_task(
task_name="NegativeSentimentAlert",
model=model,
data_source="recent_transactions",
callback=alert_on_negative_sentiment,
)
# Start the workflow
client.workflow_automator.run()
JavaScript:
javascriptCopy code// Define a callback for negative sentiment
const alertOnNegativeSentiment = (results) => {
results.forEach((result) => {
if (result.sentiment === 'negative') {
console.log('⚠️ Negative Sentiment Detected:', result);
}
});
};
// Automate sentiment analysis
client.workflowAutomator.addTask({
taskName: 'NegativeSentimentAlert',
model: sentimentModel,
dataSource: 'recent_transactions',
callback: alertOnNegativeSentiment,
});
// Start the workflow
client.workflowAutomator.run();
Step 9: Visualizing Data
Use the data visualization model to generate a bar chart of transaction volumes.
Python:
pythonCopy code# Load data visualization model
viz_model = client.load_model("data-visualization")
# Generate bar chart
chart = viz_model.generate_chart(data=transactions, chart_type="bar")
# Display chart
chart.show()
JavaScript:
javascriptCopy code// Load data visualization model
const vizModel = client.loadModel('data-visualization');
// Generate bar chart
client.fetchChainData('recent_transactions', 'Solana').then((data) => {
const chart = vizModel.generateChart(data, 'bar');
chart.render();
});
Step 10: Deploy Your First Workflow
Integrate your workflow into a dApp or script for seamless operation.
Python Deployment Example:
__name__
__main__
print("Running AI-Powered Workflow")
client.workflow_automator.run()
JavaScript Deployment Example:
javascriptCopy code(async () => {
console.log('Running AI-Powered Workflow');
await client.workflowAutomator.run();
})();
Next Steps
Congratulations! You’ve built and automated your first AI-powered workflow using Solana Synq. Here are some next steps:
Explore more pre-trained models like trading bots and data visualizations.
Integrate your workflow into a Solana dApp.
Experiment with custom AI models using the deploy_model
function.