Tools·7 min का पठन·Solingo द्वारा

Tenderly — Smart Contracts को Pro की तरह Debug और Monitor करें

Tenderly, smart contracts को debugging, monitoring, और simulating के लिए एक powerful platform है। सीखें कैसे transaction debugging, gas profiling, alerts, और fork testing का उपयोग करें ताकि bulletproof dApps बना सकें।

# Tenderly — Smart Contracts को Pro की तरह Debug और Monitor करें

Smart contract bugs millions का नुकसान कर सकते हैं। Traditional debugging tools limited हैं — आप failed transactions को आसानी से step through नहीं कर सकते या deployment से पहले changes को simulate नहीं कर सकते। Tenderly इसे debugging, monitoring, simulating, और testing smart contracts के लिए एक comprehensive platform के साथ solve करता है। चाहे आप mysterious revert को track कर रहे हों या gas costs को optimize कर रहे हों, Tenderly आपको confidence के साथ production-ready code ship करने के लिए जो insights चाहिए वे provide करता है।

Tenderly क्या है?

Tenderly एक Web3 development platform है जो offer करता है:

  • Transaction debugging — किसी भी transaction को step through करें, failed ones भी
  • Gas profiling — Expensive operations को identify करें और costs को optimize करें
  • Alerts — Contract events के लिए real-time notifications
  • Simulations — Transactions को भेजने से पहले test करें
  • Forks — किसी भी network state से private testnets बनाएं
  • Monitoring — Contract performance और usage को track करें
  • Web3 Actions — On-chain events से triggered serverless functions

Aave, Uniswap, Compound, और हजारों अन्य projects की teams द्वारा उपयोग किया जाता है, Tenderly professional smart contract development के लिए essential है।

शुरुआत करना

एक Account बनाएं

  • tenderly.co पर जाएं
  • GitHub, Google, या email के साथ sign up करें
  • एक project बनाएं (e.g., "MyDApp")
  • आप debug करने के लिए ready हैं!
  • एक Contract Add करें

    Option 1: Address से Search करें

    • "Add Contract" पर click करें
    • Contract address paste करें
    • Network select करें (Ethereum, Polygon, Arbitrum, etc.)
    • Tenderly auto-detects verified contracts

    Option 2: Hardhat/Foundry से Import करें

    Tenderly CLI install करें:

    npm install --save-dev @tenderly/hardhat-tenderly

    hardhat.config.js configure करें:

    require("@tenderly/hardhat-tenderly");
    
    

    module.exports = {

    tenderly: {

    username: "your-username",

    project: "your-project"

    }

    };

    Contracts push करें:

    npx hardhat tenderly:verify ContractName --network mainnet

    Transaction Debugging

    किसी भी Transaction को Debug करें

    Tenderly का killer feature: किसी भी EVM chain पर किसी भी transaction को debug करें, failed transactions सहित।

    Steps:

  • Etherscan से एक transaction hash copy करें
  • इसे Tenderly के search bar में paste करें
  • Transaction पर click करें
  • आपको मिलेगा:

    • Call trace — हर function call, nested calls, और external calls
    • State changes — storage updates, balance changes
    • Gas usage — per operation
    • Events emitted — सभी logs
    • Execution stack — highlighted lines के साथ Solidity source code
    • Debugger — step-by-step execution

    Example: Failed Transfer को Debug करना

    चलिए एक transaction को debug करते हैं जो revert हो गया:

    Transaction: 0xabc123...
    

    Error: execution reverted

    Tenderly में:

  • Call Trace वह function call दिखाता है जो revert हुआ
  • Debugger exact line को highlight करता है:
  • require(balanceOf[msg.sender] >= amount, "Insufficient balance");

  • State Changes दिखाता है कि balanceOf[sender] 50 था लेकिन amount 100 था
  • Root cause: Insufficient balance
  • Tenderly के बिना, आपको केवल "execution reverted" दिखेगा — इसके साथ, आपको exactly पता है क्यों।

    Step-by-Step Debugging

    Debugger tab पर click करें:

    • Step Over — Current line को execute करें
    • Step Into — Function call में enter करें
    • Step Out — Function से exit करें
    • Continue — अगले breakpoint तक run करें

    Execution में किसी भी point पर उनकी values देखने के लिए variables पर hover करें।

    State Changes को देखना

    State Changes tab दिखाता है:

    • Storage updates — कौन से slots change हुए और किन values में
    • Balance changes — ETH transferred
    • Contract creation — अगर नए contracts deploy किए गए

    Clarity के लिए contract या variable name से filter करें।

    Gas Profiling

    Tenderly के gas profiler के साथ अपने contract के gas consumption को optimize करें।

    Gas Profiler का उपयोग कैसे करें

  • Tenderly में एक transaction open करें
  • Gas Profiler tab पर click करें
  • Gas usage का breakdown देखें:
  • - Total gas — overall transaction cost

    - Per function — हर function द्वारा उपयोग की गई gas

    - Per opcode — सबसे expensive operations (SSTORE, SLOAD, etc.)

    - Flame graph — gas usage का visual representation

    Example: Expensive Loops को ढूंढना

    function batchTransfer(address[] calldata recipients, uint256 amount) external {
    

    for (uint i = 0; i < recipients.length; i++) {

    _transfer(msg.sender, recipients[i], amount);

    }

    }

    Gas profiler दिखाता है:

    • SSTORE operations dominate करते हैं (90% gas)
    • हर _transfer balanceOf mapping में दो बार write करता है

    Optimization: Balances को memory में batch update करें, storage में एक बार write करें।

    function batchTransfer(address[] calldata recipients, uint256 amount) external {
    

    uint256 totalAmount = recipients.length * amount;

    require(balanceOf[msg.sender] >= totalAmount);

    balanceOf[msg.sender] -= totalAmount; // एक SSTORE

    for (uint i = 0; i < recipients.length; i++) {

    balanceOf[recipients[i]] += amount; // Multiple SSTOREs, लेकिन unavoidable

    }

    }

    Gas saved: ~5,000 per transfer (एक SSTORE eliminated)।

    Simulations

    Transactions को भेजने से पहले test करें ताकि failed transactions और wasted gas से बच सकें।

    एक Transaction को Simulate करें

  • Tenderly में Simulator पर जाएं
  • Network select करें (mainnet, testnet, या fork)
  • Enter करें:
  • - From address — caller

    - To address — contract

    - Function — call करने की method

    - Parameters — function arguments

  • Simulate पर click करें
  • Tenderly transaction को एक sandboxed environment में execute करता है और दिखाता है:

    • क्या यह succeed होगा या revert?
    • Gas cost
    • State changes
    • Events emitted

    Use Cases

    Deployment से पहले test करें:

    // 1M tokens mint करने की gas cost देखने के लिए simulate करें
    

    simulate: mint(0x123..., 1000000)

    Complex interactions को test करें:

    // Defenses को verify करने के लिए flash loan attack को simulate करें
    

    simulate: flashLoan(10000 ETH) → swap() → exploit()

    Different states के साथ test करें:

    • Specific block पर fork करें
    • Contract storage को modify करें (e.g., balance को 1M ETH set करें)
    • इस modified state में transaction को simulate करें

    Forks — किसी भी State से Private Testnets

    Tenderly Forks किसी भी block height पर किसी भी EVM network का एक private, simulated version बनाते हैं।

    एक Fork बनाएं

  • Tenderly में Forks पर जाएं
  • Create Fork पर click करें
  • Select करें:
  • - Network — Ethereum Mainnet, Polygon, Arbitrum, etc.

    - Block number — current या historical block

  • Create पर click करें
  • आपको एक private RPC URL मिलता है (e.g., https://rpc.tenderly.co/fork/abc123)।

    Fork का उपयोग करें

    MetaMask के साथ:

  • Custom RPC add करें
  • Tenderly Fork RPC URL paste करें
  • Chain ID: original network के समान
  • Connect करें और transact करें
  • Hardhat के साथ:

    module.exports = {
    

    networks: {

    tenderlyFork: {

    url: "https://rpc.tenderly.co/fork/abc123"

    }

    }

    };

    Tests run करें:

    npx hardhat test --network tenderlyFork

    Fork Features

    State को modify करें:

    • किसी भी address balance को set करें
    • Contract storage को change करें
    • Time को fast-forward करें

    Unlimited ETH:

    • Faucets की कोई ज़रूरत नहीं
    • Large transactions को test करें

    Instant mining:

    • Block confirmations के लिए wait करने की ज़रूरत नहीं
    • CI/CD के लिए perfect

    Example: Live Protocol को Test करना

    आप एक Aave liquidation को test करना चाहते हैं:

  • Latest block पर Ethereum Mainnet को fork करें
  • अपने address balance को 1,000 ETH set करें
  • Aave में ETH deposit करें
  • USDC borrow करें
  • Price drop को simulate करें (oracle storage को modify करें)
  • Liquidation को trigger करें
  • Tenderly में पूरे flow को debug करें
  • सभी real ETH खर्च किए बिना या mainnet को affect किए बिना।

    Alerts — Real-Time Monitoring

    Specific events occur होने पर notified होने के लिए alerts set up करें।

    एक Alert बनाएं

  • Alerts पर जाएं
  • New Alert पर click करें
  • Configure करें:
  • - Contract — कौन सी contract को monitor करना है

    - Event — किस event पर trigger करना है (e.g., Transfer, Approval, OwnershipTransferred)

    - Conditions — parameters से filter करें (e.g., amount > 10 ETH)

    - Destination — Email, Slack, Discord, Webhook

  • Save करें
  • Example Alerts

    Large transfers को monitor करें:

    Event: Transfer
    

    Condition: value > 1000000 (1M tokens)

    Destination: Slack #security

    Contract ownership changes को detect करें:

    Event: OwnershipTransferred
    

    Destination: Email

    Failed transactions को track करें:

    Status: Failed
    

    Destination: Discord #dev-ops

    Gas spikes को monitor करें:

    Condition: gasUsed > 5000000
    

    Destination: Webhook

    Web3 Actions — Serverless Functions

    Web3 Actions blockchain events से triggered serverless functions हैं।

    एक Web3 Action बनाएं

  • Web3 Actions पर जाएं
  • New Action पर click करें
  • Trigger select करें:
  • - Webhook — HTTP endpoint

    - Block — हर N blocks

    - Transaction — specific contract/event

  • JavaScript code लिखें:
  • const { ethers } = require("ethers");

    module.exports = async (context) => {

    const { transaction, network } = context;

    // आपका logic यहाँ

    console.log(New transfer: ${transaction.hash});

    // Notification भेजें, database update करें, दूसरा transaction trigger करें, etc.

    };

  • Deploy करें
  • Example: Auto-Rebalancing Bot

    Token price target से deviate होने पर trigger करें:

    module.exports = async (context) => {
    

    const { provider, secrets } = context;

    const price = await getTokenPrice(provider);

    const targetPrice = 1.0;

    if (Math.abs(price - targetPrice) > 0.05) {

    // Price 5% से ज़्यादा deviate हुई

    await rebalance(provider, secrets.PRIVATE_KEY);

    }

    };

    Example: Automated Treasury Management

    Balance low होने पर funds transfer करें:

    module.exports = async (context) => {
    

    const { provider, secrets } = context;

    const balance = await provider.getBalance(treasuryAddress);

    if (balance < ethers.parseEther('10')) {

    // Treasury को refill करें

    const signer = new ethers.Wallet(secrets.PRIVATE_KEY, provider);

    await signer.sendTransaction({

    to: treasuryAddress,

    value: ethers.parseEther('100')

    });

    }

    };

    Monitoring Dashboards

    Contract performance को track करने के लिए custom dashboards बनाएं।

    Available Metrics

    • Transaction volume — transactions की संख्या
    • Gas usage — total gas consumed
    • Unique users — distinct callers
    • Function calls — कौन से functions सबसे ज़्यादा call किए जाते हैं
    • Error rate — failed transactions का percentage
    • Average gas cost — per transaction या function

    एक Dashboard बनाएं

  • Dashboards पर जाएं
  • New Dashboard पर click करें
  • Widgets add करें:
  • - Line chart (time के साथ transactions)

    - Bar chart (gas से top functions)

    - Table (हाल के failed transactions)

  • Contract, time range, network से filter करें
  • Best Practices

    1. Failed Transactions को तुरंत Debug करें

    जब production में एक transaction fail हो:

  • Etherscan से hash copy करें
  • Tenderly में open करें
  • Root cause ढूंढने के लिए debugger का उपयोग करें
  • Issue को fix करें और corrected transaction को simulate करें
  • 2. हर Mainnet Deployment से पहले Simulate करें

    Mainnet पर deploy करने से पहले:

  • Tenderly Fork पर deploy करें
  • सभी critical functions को simulate करें
  • Gas costs को check करें
  • State changes को verify करें
  • केवल तभी mainnet पर deploy करें
  • 3. Critical Events के लिए Alerts Set Up करें

    Monitor करें:

    • Ownership transfers
    • Large withdrawals
    • Failed transactions
    • Gas spikes
    • Unusual activity

    4. Integration Testing के लिए Forks का उपयोग करें

    Real protocols के खिलाफ अपने dApp को test करें:

  • Mainnet को fork करें
  • Fork पर अपना contract deploy करें
  • Live Uniswap, Aave, etc. के साथ interact करें
  • पूरे flow को debug करें
  • 5. हर Release पर Gas को Profile करें

    Key functions पर gas profiler run करें:

    • Regressions (gas increases) को identify करें
    • Hot paths को optimize करें
    • Optimizations से पहले/बाद में compare करें

    Pricing

    Free Tier:

    • 5,000 transactions/month
    • Basic debugging
    • 3 alerts
    • 1 fork

    Developer Tier ($50/month):

    • 50,000 transactions/month
    • Advanced debugging
    • Unlimited alerts
    • 10 forks
    • Web3 Actions

    Team Tier ($200/month):

    • 500,000 transactions/month
    • Team collaboration
    • Custom SLAs
    • Priority support

    अधिकतर solo developers और small teams free tier पर रह सकती हैं।

    Tenderly CLI

    Install करें:

    npm install -g @tenderly/cli

    Login करें:

    tenderly login

    ABI export करें:

    tenderly export init
    

    tenderly export

    Contracts push करें:

    tenderly contracts upload

    Conclusion

    Tenderly professional smart contract development के लिए एक essential tool है। इसकी powerful debugging, simulation, और monitoring capabilities production में पहुंचने से पहले bugs को पकड़ती हैं, gas costs को optimize करती हैं, और contract behavior में real-time insights provide करती हैं। चाहे आप एक simple token बना रहे हों या एक complex DeFi protocol, Tenderly आपको confidence के साथ ship करने में मदद करता है।

    आज ही smarter debugging शुरू करें — Tenderly के लिए sign up करें और अपना पहला contract connect करें। Solingo के security challenges के साथ advanced debugging techniques practice करें ताकि bulletproof smart contracts बना सकें।

    अगले steps:

    • Etherscan से एक failed transaction को debug करें
    • एक fork बनाएं और complex interaction को test करें
    • अपने deployed contracts के लिए alerts set up करें
    • Expensive function को optimize करने के लिए gas profiler का उपयोग करें

    Practice में लगाने के लिए तैयार हैं?

    Solingo पर interactive exercises के साथ इन concepts को apply करें।

    मुफ्त में शुरू करें