मुख्य सामग्री पर जाएं
इस गाइड में, आप सीखेंगे कि Tenderly CLI के माध्यम से generate किए गए Web3 Action project में files और project structure को कैसे navigate करें। Tenderly CLI का उपयोग कैसे करें सीखें।

Project अवलोकन और root directory file structure

जब आप tenderly actions init command चलाते हैं, तो Tenderly CLI आवश्यक files के साथ एक actions root directory बनाएगा। default रूप से, actions root directory का नाम actions होता है। हालाँकि, आप initialization प्रक्रिया के दौरान एक अलग नाम निर्दिष्ट करने में सक्षम हैं। एक बार initialize होने के बाद, root directory का नाम अभी भी folder name और tenderly.yaml file के भीतर sources field को बदलकर समायोजित किया जा सकता है। TypeScript-आधारित Web3 Actions project structure का एक उदाहरण:
example
src
|--- actions 			# actions root directory, can be renamed
|--- |--- example.ts
|--- |--- package.json
|--- |--- tsconfig.json
|--- |--- node_modules
|         |--- @tenderly/actions
|         |--- typescript
|--- tenderly.yaml
|--- tenderly-schema.json
actions root directory में आपकी Web3 Actions के लिए npm project होता है। package.json, node_modules, source files, और अन्य dependencies, libraries, और resources सहित सभी प्रासंगिक files इस folder में समाहित हैं। Default files में शामिल हैं:
  • actions/example.ts: default रूप से, इस file में सभी Web3 Actions होती हैं।
  • tenderly.yaml: यह एक configuration file है जो project में सभी Web3 Actions के लिए सेटिंग्स निर्दिष्ट करती है
  • tenderly-schema.json: स्वचालित रूप से उत्पन्न JSON Schema जो tenderly.yaml के लिए IDE validation और autocomplete सक्षम करता है, tenderly-schema.json को हाथ से edit न करें
zipped actions root directory का size, node_modules सहित, 40MB से कम होना चाहिए। अतिरिक्त packages स्थापित करते समय सुनिश्चित करें कि आप इस सीमा से नीचे रहें।

tenderly.yaml file संरचना

tenderly.yaml file में Tenderly project और सभी Web3 Actions के लिए configurations और सेटिंग्स होती हैं। इस गाइड के प्रयोजन के लिए, पूर्ण उदाहरण tenderly.yaml file इस तरह दिखेगी:
example.yaml
$schema: ./tenderly-schema.json
account_id: 'tenderly-username'
project_slug: 'our-cool-project'
actions:
  our-org/our-cool-project:
    runtime: v2
    sources: actions
    specs:
      bestActionEver:
        description: Does the best thing ever
        function: very/organized/file:bestActionEver
        trigger:
          type: block
          block:
            network:
              - 3
            blocks: 10
$schema field को tenderly actions init द्वारा स्वचालित रूप से जोड़ा जाता है और यह उत्पन्न tenderly-schema.json file की ओर इंगित करता है। JSON Schema का समर्थन करने वाले IDEs (VS Code, JetBrains) इसका उपयोग tenderly.yaml को edit करते समय autocompletion और inline validation प्रदान करने के लिए करते हैं। schema file को हर बार tenderly actions init चलाने पर भी regenerate किया जाता है। यदि आप इसे commit नहीं करना चाहते हैं तो tenderly-schema.json को अपने .gitignore में जोड़ें।
अब, आइए break down करें कि इस file का प्रत्येक अनुभाग क्या करता है और इसे कैसे कॉन्फ़िगर करें। आसान समझ के लिए, tenderly.yaml को दो प्राथमिक अनुभागों वाला मानें:
  • General configuration: वह अनुभाग जिसमें account और project का नाम शामिल है जिससे Web3 Action जुड़ा है।
  • Web3 Actions configuration: वह अनुभाग जिसमें Web3 Action के लिए configurations शामिल हैं, अनिवार्य रूप से Tenderly को यह सूचित करते हुए कि इसे कब चलाना चाहिए।

General configuration

general configuration अनुभाग में निम्न key-value pairs शामिल हैं:
example.yaml
account_id: 'johnDoe'
project_slug: 'our-cool-project'
  • account_id: आपका username
  • project_slug: Web3 Action से जुड़े project का slug (वैकल्पिक, खाली छोड़ा जा सकता है)
organization name, username, और project slug कैसे खोजें सीखने के लिए इस गाइड को देखें।

Web3 Actions configuration

actions object वह है जहाँ आप अपनी Web3 Actions को परिभाषित करना शुरू करते हैं, जिसमें project settings शामिल हैं, जैसे runtime, sources location, और वास्तविक Web3 Action declaration।
example.yaml
account_id: 'johnDoe'
project_slug: ''
actions:
  my-username/my-cool-project: # in case it's an individual project
    # our-cool-org/our-cool-project:   # in case it's an org-level project
    runtime: v2
    sources: actions
    specs: ...

Project निर्दिष्ट करना

Tenderly के भीतर project को विशिष्ट रूप से पहचानने वाली composite key निर्दिष्ट करके शुरू करें।
  • username/project-slug: व्यक्तिगत developers से संबंधित projects के लिए Username और project slug
  • org-name/project-slug: यदि आपका project किसी organization से संबंधित है तो Organization name और project slug
organization name, username, और project slug कैसे खोजें सीखने के लिए इस गाइड को देखें।
Tenderly Dashboard में आपके पास पहुँच रखने वाले कई projects के लिए एक ही Web3 Actions project का उपयोग करना संभव है।

runtime को Configure करना

इसके बाद, आपको runtime version और वह directory निर्दिष्ट करने की आवश्यकता है जिसमें आपका Web3 Action code है। इस data का उपयोग Tenderly CLI द्वारा आपके code को bundle और Tenderly की infrastructure पर Web3 Actions runtime में deploy करने के लिए किया जाता है। निम्न सेटिंग्स अनिवार्य हैं:
  • runtime: runtime version। वर्तमान में, हम v2 का समर्थन करते हैं, जो Node 20 के अनुरूप है।
  • sources: Web3 Action source files का location। value एक path होना चाहिए जो tenderly.yaml file वाले folder के सापेक्ष actions root directory की ओर इंगित करता है। यह उस path से मेल खाना चाहिए जो आपने init command चलाते समय निर्दिष्ट किया था।
उदाहरण: नीचे दिखाई गई folder structure के लिए, sources के लिए उचित मान web3-actions होगा।
example
src
|-- web3-actions 			# actions root directory, can be renamed
|   |--- example.ts
|   |--- package.json
|   |--- tsconfig.json
|   |--- node_modules
|   	 |--- @tenderly
|        |--- /typescript
|-- tenderly.yaml
यदि आप sources value बदलते हैं, तो actions root के सापेक्ष निर्दिष्ट path पर एक directory मौजूद होनी चाहिए, और इसमें आपकी Web3 Action functions वाली source files होनी चाहिए।

Web3 Actions सेटिंग्स परिभाषित करना

व्यक्तिगत Web3 Actions को specs object के तहत declare किया जाता है। आप एक single tenderly.yaml file में कई Web3 Actions declare कर सकते हैं। प्रत्येक Web3 Action को उस key से शुरू होना चाहिए जो action name (bestActionEver) का प्रतिनिधित्व करती है। action name project level पर unique होना चाहिए और letter से शुरू होना चाहिए जिसके बाद letters, digits, hyphens, या underscores हों (pattern: ^[a-zA-Z][a-zA-Z0-9_-]*$)। यह key यह दर्शाती है कि deploy की गई Web3 Action को Tenderly Dashboard में कैसे नाम दिया गया है और प्रस्तुत किया गया है। description key को भी शामिल किया जाना चाहिए। description आम तौर पर एक या दो वाक्य होते हैं जो बताते हैं कि Web3 Action क्या करती है।
example.yaml
specs:
  bestActionEver:
    description: Does the best thing ever!
इसके बाद, आपको उस action function से link करने के लिए function key निर्दिष्ट करने की आवश्यकता है जिसे आप चलाना चाहते हैं। Web3 Actions के लिए source code को कई files के बीच विभाजित किया जा सकता है या custom directory structure में nested किया जा सकता है। tenderly.yaml file seamless referencing की अनुमति देती है। उदाहरण के लिए, actions/very/organized/file.ts में स्थित एक function bestActionEver yaml में इस तरह referenced होगा:
example.yaml
our-org/our-cool-project:
  runtime: v2
  sources: actions
  specs:
    bestActionEver:
      description: Does the best thing ever
      function: very/organized/file:bestActionEver
      trigger: ...
अगला चरण Web3 Action के लिए trigger चुनना और परिभाषित करना है। एक trigger एक event है जिसे Tenderly listen करता है और एक criterion पूरा होने पर Web3 Action को execute करता है। triggers के गहन reference के लिए, उपलब्ध Web3 Action Trigger Types का अन्वेषण करें। Web3 Action के लिए trigger परिभाषित करते समय, पहली चीज़ इसका type निर्दिष्ट करना है। नीचे दिए गए उदाहरण में, हम block trigger type परिभाषित कर रहे हैं। इसका मतलब है कि Rinkeby पर हर 10 blocks mine होने के बाद bestActionEver Web3 Action एक बार चलेगी।
example.yaml
bestActionEver:
  description: Does the best thing ever
  function: very/organized/file:bestActionEver
  trigger:
    type: block
    block:
      network:
        - 3
      blocks: 10