> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenderly.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Contracts deploy और verify करें

> Debugger, Gas Profiler, और Simulator के लिए verification के साथ Foundry या Hardhat के साथ Virtual Environment पर Solidity contracts deploy करें।

Foundry या Hardhat का उपयोग करके Virtual Environment पर Solidity contracts deploy करें। Virtual Environment पर deploy किए गए contracts को **virtual contracts** कहा जाता है और वे **Virtual Contracts** tab के तहत **Contracts** section में दिखाई देते हैं।

deploy करते समय contracts को verify करें। Verified contracts explorer में Debugger, Gas Profiler, Simulator, और समृद्ध transaction views को अनलॉक करते हैं।

## शुरू करने से पहले

* एक [Virtual Environment](/virtual-environments/quickstart)। dashboard से इसका RPC URL कॉपी करें।
* उस Virtual Environment पर एक [funded deployer address](/virtual-environments/unlimited-faucet)।

Virtual Environment पर Verification को अलग access key की आवश्यकता नहीं है: RPC URL स्वयं authenticate करता है, और verifier endpoint उसी URL के साथ `/verify` जोड़ा हुआ है।

<Warning>
  डिफ़ॉल्ट रूप से, Virtual Environment पर verify किए गए contracts निजी होते हैं। [public explorer](/virtual-environments/explorer#public-explorer) की visibility setting के आधार पर, code बाहरी रूप से दिखाई दे सकता है। कुछ भी verify करने से पहले public explorer toggle और [verification visibility](/virtual-environments/explorer#public-explorer) जाँच लें जिसे आप निजी रखना चाहते हैं।
</Warning>

## Deploy और verify

<Tabs>
  <Tab title="Foundry">
    ### `foundry.toml` कॉन्फ़िगर करें

    Tenderly का verifier उस metadata hash को match करता है जिसे Solidity compiler deployed bytecode में जोड़ता है, आपके द्वारा submit किए गए source के विरुद्ध। compiled output में metadata को रखने के लिए `cbor_metadata` और `bytecode_hash` को स्पष्ट रूप से सेट करें:

    ```toml title="foundry.toml" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    [profile.default]
    src = "src"
    out = "out"
    libs = ["lib"]
    solc_version = "0.8.24"
    optimizer = true
    optimizer_runs = 200

    # Required for Tenderly contract verification:
    # keep the CBOR metadata so the verifier can match the on-chain bytecode hash.
    cbor_metadata = true
    bytecode_hash = "ipfs"
    ```

    `cbor_metadata = true` और `bytecode_hash = "ipfs"` Foundry के डिफ़ॉल्ट हैं, लेकिन कुछ templates उन्हें strip कर देते हैं; `bytecode_hash = "none"` verification को तोड़ देता है। `solc_version` और optimizer settings को pin करें ताकि re-verification वही bytecode compile करे।

    यदि आपका project OpenZeppelin जैसी libraries का उपयोग करता है, तो `remappings.txt` में remappings को स्पष्ट रूप से घोषित करें:

    ```bash title="remappings.txt" theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
    forge-std/=lib/forge-std/src/
    ```

    Auto-detected remappings के साथ, verification payload में build द्वारा उपयोग की गई अलग remapping strings हो सकती हैं, जिससे bytecode-mismatch failures होते हैं।

    ### Environment variables सेट करें

    ```bash showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    export TENDERLY_VIRTUAL_TESTNET_RPC=...   # paste your RPC URL
    export TENDERLY_VERIFIER_URL=$TENDERLY_VIRTUAL_TESTNET_RPC/verify
    export PRIVATE_KEY=...                    # deployer private key
    ```

    Deploy करने से पहले connection की जाँच करें। `cast chain-id` को Virtual Environment के chain ID को print करना चाहिए, और deployer balance गैर-शून्य होना चाहिए:

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    cast chain-id --rpc-url $TENDERLY_VIRTUAL_TESTNET_RPC
    cast balance <DEPLOYER_ADDRESS> --rpc-url $TENDERLY_VIRTUAL_TESTNET_RPC
    ```

    ### `forge create` के साथ deploy करें

    verify flags के साथ `forge create` चलाएं। Constructor arguments raw values के रूप में पास किए जाते हैं; Foundry उन्हें ABI-encode करता है और encoded रूप को verifier को submit करता है:

    ```bash showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    forge create src/Counter.sol:Counter \
      --rpc-url $TENDERLY_VIRTUAL_TESTNET_RPC \
      --private-key $PRIVATE_KEY \
      --broadcast \
      --verify \
      --verifier custom \
      --verifier-url $TENDERLY_VERIFIER_URL \
      --constructor-args 42
    ```

    <Warning>
      `--constructor-args` को अंत में रखें। यह command line के बाकी हिस्से को greedily consume कर लेता है, इसलिए इसके बाद रखा गया कोई भी flag एक और constructor argument माना जाता है।
    </Warning>

    ### Foundry script के साथ deploy करें

    एक ही run में कई contracts deploy करने के लिए `forge script` का उपयोग करें। script में प्रत्येक `new Foo(...)` को verification के लिए स्वचालित रूप से submit किया जाता है, broadcast log से लिए गए सही constructor arguments के साथ। Imports को transparently handle किया जाता है: verifier को एक standard-JSON payload मिलता है जिसमें compiler द्वारा छूने वाली प्रत्येक source file होती है, इसलिए local imports और library imports (जैसे OpenZeppelin) बिना अतिरिक्त steps के verify होते हैं।

    `--slow` का उपयोग करें ताकि transactions एक-एक करके भेजी जाएं। इसके बिना, broadcast batching पिछले transaction के confirm होने से पहले एक transaction submit कर सकती है, जो एक hosted RPC के विरुद्ध flaky है और verification step को race कर सकती है।

    ```bash showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    forge script script/Counter.s.sol:CounterScript \
      --rpc-url $TENDERLY_VIRTUAL_TESTNET_RPC \
      --private-key $PRIVATE_KEY \
      --broadcast \
      --slow \
      --verify \
      --verifier custom \
      --verifier-url $TENDERLY_VERIFIER_URL
    ```

    ### मौजूदा contract को verify करें

    पहले से deployed contracts को `forge verify-contract` के साथ verify किया जा सकता है। `forge create` के विपरीत, यह command **पहले से ही ABI-encoded** constructor arguments की अपेक्षा करता है; उन्हें बनाने के लिए `cast abi-encode` का उपयोग करें:

    ```bash showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    forge verify-contract $COUNTER_ADDRESS src/Counter.sol:Counter \
      --verifier custom \
      --verifier-url $TENDERLY_VERIFIER_URL \
      --constructor-args $(cast abi-encode "constructor(uint256)" 42) \
      --watch
    ```

    `--watch` verifier को तब तक poll करता है जब तक verification समाप्त न हो जाए और परिणाम print करता है। Multi-contract deployments के लिए, प्रत्येक deployed address के लिए `forge verify-contract` एक बार चलाएं।
  </Tab>

  <Tab title="Hardhat">
    <Info>
      `@tenderly/hardhat-tenderly` plugin Hardhat के `2.22.0` तक के version के साथ संगत है। समर्थित version matrix के लिए [Hardhat verification](/contract-verification/hardhat#versions-and-compatibility) देखें।

      ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
      npm install hardhat@2.22.0
      ```
    </Info>

    ### Plugin और CLI स्थापित करें

    Tenderly Hardhat plugin स्थापित करें:

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    npm install --save-dev @tenderly/hardhat-tenderly
    ```

    [Tenderly CLI](https://github.com/Tenderly/tenderly-cli) स्थापित करें और login करें ताकि plugin authenticate कर सके:

    <Tabs>
      <Tab title="macOS (Homebrew)">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        brew tap tenderly/tenderly
        brew install tenderly
        tenderly login
        ```
      </Tab>

      <Tab title="Linux">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        curl https://raw.githubusercontent.com/Tenderly/tenderly-cli/master/scripts/install-linux.sh | sudo sh
        tenderly login
        ```
      </Tab>

      <Tab title="Manual">
        [release page](https://github.com/Tenderly/tenderly-cli/releases) से latest binary डाउनलोड करें, इसे अपने `$PATH` में जोड़ें, फिर चलाएं:

        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        tenderly login
        ```
      </Tab>
    </Tabs>

    ### Hardhat कॉन्फ़िगर करें

    अपने `networks` block में `virtualMainnet` (या स्पष्टता के लिए `virtual` से शुरू होने वाला कोई भी नाम) जोड़ें, फिर अपने [project और username slugs](/platform/account/projects/slug) के साथ एक `tenderly` block जोड़ें। `automaticVerifications: true` के साथ `tenderly.setup()` को कॉल करें ताकि प्रत्येक deploy के दौरान contracts verify हों।

    ```typescript title="hardhat.config.ts" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    import * as tenderly from "@tenderly/hardhat-tenderly";

    tenderly.setup({ automaticVerifications: true });

    const config: HardhatUserConfig = {
      solidity: "0.8.19",
      networks: {
        virtualMainnet: {
          url: process.env.TENDERLY_VIRTUAL_MAINNET_RPC!,
          chainId: 73571, // the Chain ID you selected at Virtual Environment creation
        },
      },
      tenderly: {
        project: "YOUR_PROJECT_SLUG",
        username: "YOUR_USERNAME_SLUG",
      },
    };

    export default config;
    ```

    ### Deploy

    आपके द्वारा परिभाषित network के विरुद्ध अपनी deploy script चलाएं। `automaticVerifications: true` के साथ, plugin deploy होते ही verify करता है।

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    npx hardhat run scripts/deploy.ts --network virtualMainnet
    ```
  </Tab>
</Tabs>

## Dashboard जाँचें

Tenderly Dashboard में, **Contracts** खोलें और **Virtual Contracts** tab चुनें। आपके नए deployed contracts वहाँ दिखाई देते हैं, प्रत्येक contract के लिए verification status दिखाई देता है।

## Troubleshooting

| लक्षण                                                                       | संभावित कारण                                                                                                                                       | समाधान                                                                                                                                                           |
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| verifier से `unauthorized` / `-32004` response                              | गलत verifier URL। एक सामान्य गलती `/verify` के बजाय `/verify/etherscan` जोड़ना है।                                                                 | सुनिश्चित करें कि verifier URL ठीक `/verify` पर समाप्त होता है।                                                                                                  |
| `Bytecode does not match deployed contract`                                 | submit किया गया source deploy किए गए source से अलग compile हुआ: एक `optimizer_runs` mismatch, एक अलग `solc_version`, या एक stripped metadata hash। | `foundry.toml` में `solc_version`, `optimizer`, `optimizer_runs`, और `bytecode_hash` को pin करें। फिर से verify करने से पहले `forge clean && forge build` चलाएं। |
| `Failed to deserialize content`                                             | verifier ने एक error string लौटाई जिसे Foundry parse नहीं कर सकता, आमतौर पर एक upstream auth या path error को wrap कर रहा है।                      | URL की फिर से जाँच करें और raw response देखने के लिए `-vvvv` के साथ फिर से चलाएं।                                                                                |
| `forge create` पर `Dry run enabled, not broadcasting transaction`           | `--broadcast` पास नहीं किया गया, या `--constructor-args` द्वारा निगल लिया गया।                                                                     | `--constructor-args` को अंतिम flag बनने के लिए स्थानांतरित करें।                                                                                                 |
| `forge script` पर केवल पहला contract verify होता है                         | RPC race: पहले receipt से पहले दूसरा transaction submit हुआ।                                                                                       | `--slow` जोड़ें।                                                                                                                                                 |
| Verifier `OK` की रिपोर्ट करता है लेकिन explorer अभी भी unverified दिखाता है | UI caching।                                                                                                                                        | explorer page को hard-refresh करें। API response में status authoritative है।                                                                                    |

## अगले कदम

* [Foundry के साथ proxy contracts verify करें](/virtual-environments/develop/verify-proxy-contracts): upgrades सहित एक UUPS implementation और उसके ERC1967 proxy को verify करें।
* [Stage contracts](/virtual-environments/ci-cd/stage-contracts): अपनी team के साथ RPC लिंक और contract addresses साझा करें।
* [अपने dApp को stage करें](/virtual-environments/ci-cd/stage-dapps): अपने frontend को Virtual Environment पर पॉइंट करें।
* [Virtual Environment को fork करें](/virtual-environments/develop/fork-testnet): एक Virtual Environment state से शाखा करें।
