Building Custom Blocks
Extend Zzyra’s planned automation capabilities with your own custom blocks. Create powerful integrations, specialized workflows, and unique automation logic tailored to your specific needs.
Current Status : Basic AI-assisted block creation available
Planned : Advanced SDK, marketplace, and developer rewards program
Block Architecture
User Interface Form Fields Configuration Validation
Block Logic Input Processing Business Logic Output Generation
Integration Layer API Calls Web3 Interactions Data Processing
Example Custom Block Development
Example: Creating a “Price Alert” block that monitors cryptocurrency prices and sends notifications when thresholds are met.
Block Definition // Planned SDK structure (in development)
import { Block , BlockConfig , BlockInput , BlockOutput } from '@zzyra/blocks' ;
interface PriceAlertConfig {
symbol : string ;
threshold : number ;
condition : 'above' | 'below' ;
notificationChannel : 'email' | 'discord' | 'slack' ;
}
// Planned decorator pattern (in development)
@ Block ({
name: 'Price Alert' ,
description: 'Monitor cryptocurrency prices and send alerts' ,
category: 'Trading' ,
version: '1.0.0'
})
export class PriceAlertBlock {
@ BlockConfig ()
config : PriceAlertConfig ;
async execute () : Promise < void > {
const { symbol , threshold , condition } = this . config ;
const { currentPrice } = this . input ;
let alertTriggered = false ;
let message = '' ;
if ( condition === 'above' && currentPrice > threshold ) {
alertTriggered = true ;
message = `🚀 ${ symbol } price is above $ ${ threshold } ! Current: $ ${ currentPrice } ` ;
}
this . output = {
alertTriggered ,
message ,
timestamp: new Date (). toISOString ()
};
}
}
Development Workflow
Define Requirements
Identify the automation need and define inputs, outputs, and configuration
Create Block Structure
Set up the block class with proper decorators and interfaces
Implement Logic
Write the core business logic and integration code
Test & Validate
Test the block with various inputs and edge cases
Deploy & Share
Deploy to Zzyra marketplace and share with the community
Advanced Patterns
Web3 Integration Block
@ Block ({
name: 'DeFi Yield Automation' ,
description: 'Automate DeFi yield farming operations' ,
category: 'DeFi' ,
version: '2.0.0'
})
export class DeFiYieldBlock {
async execute () : Promise < void > {
const { protocol , action , amount } = this . config ;
// Initialize protocol-specific contract
const contract = await this . getProtocolContract ( protocol );
let transaction ;
switch ( action ) {
case 'deposit' :
transaction = await this . deposit ( amount );
break ;
case 'withdraw' :
transaction = await this . withdraw ( amount );
break ;
case 'harvest' :
transaction = await this . harvest ();
break ;
}
const receipt = await transaction . wait ();
this . output = {
transactionHash: receipt . transactionHash ,
success: true ,
gasUsed: receipt . gasUsed . toString ()
};
}
}
@ Block ({
name: 'AI Trading Advisor' ,
description: 'AI-powered trading recommendations' ,
category: 'AI Trading' ,
version: '1.0.0'
})
export class AITradingBlock {
async execute () : Promise < void > {
const { model , strategy } = this . config ;
const { marketData , portfolio } = this . input ;
// Prepare context for AI analysis
const context = this . prepareAnalysisContext ( marketData , portfolio );
// Generate AI recommendations
const response = await this . openai . chat . completions . create ({
model: model === 'gpt-4' ? 'gpt-4' : 'gpt-3.5-turbo' ,
messages: [
{
role: 'system' ,
content: 'You are an expert cryptocurrency trading advisor.'
},
{
role: 'user' ,
content: `Analyze this market data: ${ JSON . stringify ( context ) } `
}
]
});
const aiRecommendation = JSON . parse ( response . choices [ 0 ]. message . content );
this . output = {
recommendations: this . validateRecommendations ( aiRecommendation ),
confidence: aiRecommendation . confidence ,
reasoning: aiRecommendation . reasoning
};
}
}
Testing Framework
Unit Tests
Integration Tests
describe ( 'PriceAlertBlock' , () => {
let block : PriceAlertBlock ;
beforeEach (() => {
block = new PriceAlertBlock ();
block . config = {
symbol: 'ETH' ,
threshold: 3000 ,
condition: 'above' ,
notificationChannel: 'email'
};
});
it ( 'should trigger alert when price is above threshold' , async () => {
block . input = {
currentPrice: 3200 ,
marketData: {}
};
await block . execute ();
expect ( block . output . alertTriggered ). toBe ( true );
expect ( block . output . message ). toContain ( '🚀 ETH price is above $3000' );
});
});
describe ( 'PriceAlertBlock Integration' , () => {
it ( 'should send email notification when alert is triggered' , async () => {
const mockEmailService = jest . fn ();
const block = new PriceAlertBlock ();
block . config . notificationChannel = 'email' ;
block . input . currentPrice = 3200 ;
await block . execute ();
expect ( mockEmailService ). toHaveBeenCalledWith (
expect . stringContaining ( 'ETH price is above $3000' )
);
});
});
Block Marketplace
Publishing Steps
Prepare Your Block
Ensure your block is well-tested and documented
Create Listing
Add description, pricing, and usage examples
Submit for Review
Our team reviews for quality and security
Go Live
Your block is available to the community
Getting Started
Custom blocks are the foundation of Zzyra’s extensibility. By building and
sharing blocks, you contribute to the ecosystem and help others automate their
workflows more effectively.