यह गाइड प्रदर्शित करती है कि कैसे एक flexible monitoring system बनाया जाए जो किसी भी on-chain event को track कर सकता है, transaction data को process कर सकता है, और webhooks के माध्यम से रीयल-टाइम notifications deliver कर सकता है। Tenderly के Alert system के शक्तिशाली trigger criterias को Web3Actions के साथ मिलाकर, आप एक modular monitoring infrastructure बनाएंगे जो किसी भी blockchain monitoring आवश्यकता के अनुकूल हो सकता है, सरल event tracking से लेकर जटिल multi-contract interactions तक।
यह गाइड मानती है कि आपके पास एक Tenderly account है और Web3Actions और blockchain events से बुनियादी परिचय है।
Modular Monitoring with Web3Actions
पूर्वापेक्षाएँ
शुरू करने से पहले, सुनिश्चित करें कि आपके पास है:
- Node.js (नवीनतम संस्करण के रूप में वर्तमान में v20 समर्थित है)
- Tenderly CLI स्थापित
- data प्राप्त करने के लिए एक webhook endpoint
- TypeScript की बुनियादी समझ
System Setup
Alert Type: हम इसे Successful Transaction के रूप में सेट अप करेंगे। आप विस्तृत चरण यहाँ पा सकते हैं
Alert Target: target के रूप में हम Tag का उपयोग करेंगे जो हमें विशिष्ट tag से लेबल किए गए सभी contracts और wallets की निगरानी करने देता है। आप यहाँ जाँच सकते हैं कि contract या wallet के लिए Tag कैसे जोड़ें।
Alert Parameter: dropdown से Tag चुनें जो उन contracts को रखता है जिन्हें हम monitor करना चाहते हैं
Alert Destination: अभी के लिए आप जो चाहें सेट अप कर सकते हैं, अगले चरण में हम इस Alert के लिए Destination बनने के लिए Web3Action सेट अप करेंगे
Dependencies स्थापित करें
repo को clone करें। आप template का link यहाँ पा सकते हैं
एक बार आपने repo clone कर लिया, तो CLI के अंदर निम्न command चलाएँ:
cd actions && npm install
Environment Variables कॉन्फ़िगर करें
अपने Tenderly Web3Action में इन
Secrets को सेट अप करें:
WEBHOOK_URL = <Your webhook URL>
BEARER = <Your Tenderly API bearer token>
ACCOUNT_SLUG = <Your Tenderly account slug>
PROJECT_SLUG = <Your project slug>
EVENT_NAME = <Name of the event to track>
tenderly.yaml कॉन्फ़िगर करें
आपकी tenderly.yaml ऐसी दिखनी चाहिए:
account_id: "<YOUR_ACCOUNT_ID>"
actions:
<YOUR_ACCOUNT_ID>/<PROJECT_SLUG>:
runtime: v2
sources: actions
specs:
example:
description: "Event tracking system"
function: example:modularFn
trigger:
type: alert
alert: { <YOUR_ALERT_ID> }
execution_type: parallel
project_slug: "<PROJECT_SLUG>"
placeholders को निम्न मानों से बदलना सुनिश्चित करें:
YOUR_ACCOUNT_ID: आपका account ID जिसे आप इस गाइड का पालन करके प्राप्त कर सकते हैं।
PROJECT_SLUG: आपका project slug जिसे आप इस गाइड का पालन करके प्राप्त कर सकते हैं।
YOUR_ALERT_ID: पिछले चरण में आपके द्वारा बनाए गए alert का ID। आप dashboard में ID पा सकते हैं।
अपनी Web3 Action Deploy करें
अपनी Web3 Action deploy करने के लिए निम्न command चलाएँ:
Core Components
Transaction Processing
system transaction information को process करके शुरू होता है:
export const modularFn = async (context: Context, transactionEvent: TransactionEvent) => {
const txHash = transactionEvent.hash;
const txNetwork = transactionEvent.network;
const blockHash = transactionEvent.blockHash;
const blockNumber = transactionEvent.blockNumber;
const WEBHOOK_URL = await context.secrets.get("WEBHOOK_URL");
const BEARER = await context.secrets.get("BEARER");
const ACCOUNT_SLUG = await context.secrets.get("ACCOUNT_SLUG");
const PROJECT_SLUG = await context.secrets.get("PROJECT_SLUG");
const EVENT_NAME = await context.secrets.get("EVENT_NAME");
if (!EVENT_NAME) {
throw new Error("EVENT_NAME not found in environment variables");
}
const url = `https://api.tenderly.co/api/v1/public-contract/${txNetwork}/trace/${txHash}`;
const traceResponse = await axios.get(url, {
headers: {
authorization: BEARER,
},
});
const traceData = traceResponse.data;
यह component:
- transaction hash और network capture करता है
- Tenderly API के माध्यम से transaction traces retrieve करता है
- block information को process करता है
Contract information (names और ABIs) Contracts API का उपयोग करके fetch की जाती है।
const fetchContractName = async (addr: string) => {
const contractEndpoint = `https://api.tenderly.co/api/v1/account/${ACCOUNT_SLUG}/project/${PROJECT_SLUG}/contract/${txNetwork}/${addr}`;
try {
const contractResponse = await axios.get(contractEndpoint, {headers: {'Authorization': BEARER}});
return contractResponse.data.contract.contract_name;
} catch (error) {
console.error(`Error fetching contract name from endpoint for ${addr}:`, error);
}
};
const fetchContractAbi = async (addr: string) => {
const contractEndpoint = `https://api.tenderly.co/api/v1/account/${ACCOUNT_SLUG}/project/${PROJECT_SLUG}/contract/${txNetwork}/${addr}`;
try {
const contractResponse = await axios.get(contractEndpoint, {headers: {'Authorization': BEARER}});
return contractResponse.data.contract.data.abi;
} catch (error) {
console.error(`Error fetching contract ABI from endpoint for ${addr}:`, error);
}
};
Event Processing
Event processing विशेष functions के माध्यम से संभाला जाता है:
const extractEventAddresses = (logs: any[]): string[] =>
Array.from(new Set(
logs
.filter(log => log.name === EVENT_NAME)
.map(log => log.raw.address)
));
const extractEventDetails = (logs: any[]) => {
return logs
.filter(log => log.name === EVENT_NAME)
.map(log => {
const result: { [key: string]: string } = {
name: log.name
};
log.inputs.forEach((input: any) => {
const name = input.soltype.name;
const value = input.value.toString();
result[name] = value;
});
return result;
});
};
यह अनुभाग:
- name द्वारा events filter करता है
- event parameters extract करता है
- event addresses process करता है
Webhook interaction
system इस structured data को Axios का उपयोग करके आपके webhook पर भेजता है:
{
hash: string, // Transaction hash
transaction: object, // Full transaction event
blockHash: string, // Block hash
blockNumber: number, // Block number
matchReasons: Array<{ // Event details
name: string,
[parameterName: string]: string
}>,
sentinel: { // Contract information
contractName: string,
abi: object
},
traceData: object, // Transaction trace data
addresses: string[] // Involved addresses
}
Troubleshooting
सामान्य समस्याएँ और समाधान:
-
Missing Events
- सत्यापित करें कि EVENT_NAME contract events से बिल्कुल मेल खाता है
- Tenderly dashboard में alert configuration की जाँच करें
- event emission के लिए transaction logs की समीक्षा करें
-
API Errors
- BEARER token अनुमतियाँ validate करें
- API endpoint उपलब्धता की जाँच करें
- network configuration सत्यापित करें
-
Webhook Issues
- WEBHOOK_URL पहुँच की पुष्टि करें
- जाँचें कि payload format अपेक्षाओं से मेल खाता है
- webhook endpoint logs की निगरानी करें