5/5
## Deploying Your Smart Contract Beyond the Remix VM In previous steps, you likely deployed and tested your smart contract within the Remix IDE's simulated environment, often called the Remix VM. While excellent for initial development and quick checks, it doesn't fully replicate interacting with a real blockchain network. This lesson guides you through deploying your smart contract to a network environment that behaves like a real blockchain, using tools like MetaMask and introducing a powerful development tool: Tenderly Virtual Testnets. ## The Challenge of Public Testnets (Like Sepolia) Public testnets, such as Sepolia, are designed to mirror the functionality of main blockchain networks (like Ethereum Mainnet) but use test Ether (ETH) with no real-world value. They are crucial for final testing stages before deploying to mainnet. However, a significant practical hurdle often arises: acquiring test ETH. Faucets, the websites designed to distribute free test ETH, are notoriously difficult to use. They frequently have strict requirements (like holding a certain amount of mainnet ETH), impose severe rate limits, or simply run out of funds. This difficulty can severely slow down development and cause considerable frustration. **Important Development Philosophy:** Relying heavily on public testnets for *day-to-day development* is generally considered inefficient. Your primary testing loop should ideally be local (using Remix VM or other local blockchain simulators). Deployment to a public testnet should be one of the *later* steps in your process, perhaps just before a security audit or final pre-mainnet checks, rather than a frequent activity during initial coding and debugging. While interacting with a public testnet is valuable experience, the difficulties in obtaining test funds often make it impractical for learning and rapid iteration. Therefore, we'll pivot to a more developer-friendly solution. ## Connecting Remix to External Networks with MetaMask To deploy your contract outside the Remix VM, you need to connect Remix to a blockchain network via a wallet. MetaMask is the most common browser extension wallet for this purpose. 1. **Install MetaMask:** Ensure you have the MetaMask browser extension installed. If you just installed it, refresh your Remix IDE page. 2. **Compile Your Contract:** In Remix, navigate to your Vyper contract (e.g., `favorites.vy`) and compile it using the Vyper compiler tab. 3. **Clear Old Deployments:** Go to the "Deploy & Run Transactions" tab in Remix and clear any previously deployed contract instances from the Remix VM session. 4. **Change Remix Environment:** This is the crucial step. In the "Deploy & Run Transactions" tab, locate the "Environment" dropdown menu. It usually defaults to "Remix VM (e.g., Cancun)". Change this setting to **"Injected Provider - MetaMask"**. 5. **Connect MetaMask to Remix:** Selecting "Injected Provider" will likely trigger a MetaMask pop-up window asking for permission to connect your wallet to the Remix website. Approve this connection request. 6. **Select Network in MetaMask:** Open the MetaMask extension. Click the network dropdown at the top left. Initially, you might consider selecting a public testnet like **Sepolia**. * *Tip:* If you don't see Sepolia listed, go into your MetaMask settings, find the "Networks" or "Advanced" section, and ensure the option **"Show test networks"** is enabled. At this point, if you were proceeding with Sepolia, you'd face the faucet challenge mentioned earlier. Let's explore a better way for development using Tenderly. ## Introducing Tenderly Virtual Testnets: A Better Alternative Tenderly (`tenderly.co`) is a comprehensive blockchain development platform offering various tools, including debugging, simulation, and monitoring. One of its standout features for developers is **Virtual Testnets**. Virtual Testnets are private, on-demand simulations of blockchain networks. Crucially, you can *fork* an existing network (like Sepolia or even Ethereum Mainnet) at its current state, creating your own private copy. This environment provides the realism of interacting with a network state without the hassles of public testnet faucets. ## Setting Up Your Tenderly Virtual Testnet To use Tenderly Virtual Testnets, you'll need a Tenderly account. 1. **Sign Up for Tenderly (Special Offer):** * Use the specific sign-up link provided in the course materials (e.g., in the associated GitHub repository like `github.com/Cyfrin/moccasin-full-course-cu`). This link is part of a partnership. * After creating your account using that link, log in to Tenderly. * Open the chat widget (usually in the bottom right corner). * Send the message: **`CYFRIN2024`** * This code should activate an extended free trial (e.g., a full month), giving you ample time to explore Tenderly's features. Thanks to Tenderly for this offer! 2. **Create a Tenderly Project:** Once logged in, create a new project. Give it a relevant name (e.g., "My First DApp"). 3. **Create a Virtual TestNet:** * Navigate to the "Virtual TestNets" section within your Tenderly project. * Click "Create Virtual TestNet". * Configure your testnet: * **Parent Network:** Select **Sepolia**. This means your virtual testnet will start as a fork (a copy) of the current Sepolia blockchain state. * **Name:** Choose a descriptive name, for instance, **"My Dev Fork"**. * **Chain ID:** Select **Custom**. Public Sepolia has a Chain ID of `11155111`. To avoid potential conflicts with the real network in MetaMask, choose a *different*, unique custom ID. A simple approach is to add an extra digit, like **`111555111`**. You can quickly check sites like `chainlist.org` to ensure your chosen ID isn't already widely used. * **Public Explorer:** Set to **On**. This creates a web interface, similar to Etherscan, where you can view transactions and blocks on your private virtual testnet. * **Smart Contract Visibility:** Set to **Full**. This allows you to view details about deployed contracts later. * Click "Create". Your private, Sepolia-forked virtual testnet will be created almost instantly. ## Connecting MetaMask to Your Tenderly Virtual Testnet Now, you need to tell MetaMask how to communicate with your newly created Tenderly Virtual Testnet. 1. **Find RPC URL:** On your Tenderly Virtual Testnet's page, locate the **HTTPS RPC URL**. It will look something like `https://virtual.sepolia.rpc.tenderly.co/...<unique_identifier>`. Copy this URL. 2. **Add Custom Network in MetaMask:** * Open MetaMask and click the network selector dropdown. * Scroll to the bottom and click **"Add network"** or **"Add a custom network"**. * Fill in the details: * **Network Name:** Enter the name you gave your testnet in Tenderly (e.g., "My Dev Fork"). * **New RPC URL:** Paste the HTTPS RPC URL you copied from Tenderly. * **Chain ID:** Enter the **custom Chain ID** you set in Tenderly (e.g., 111555111). * **Currency Symbol:** Enter **ETH**. * **Block Explorer URL (Optional):** You can leave this blank for now or add the Public Explorer URL from Tenderly later if desired. * Click "Save". 3. **Switch Network:** MetaMask should prompt you to switch to the newly added network. If not, manually select "My Dev Fork" (or whatever you named it) from the network dropdown. Your MetaMask wallet is now connected to your private Tenderly Virtual Testnet. ## Funding Your Virtual Testnet Account (The Easy Way) Remember the pain of public testnet faucets? Tenderly makes funding trivial on its virtual testnets. 1. **Copy Your Address:** Open MetaMask, ensure you're on your Tenderly network ("My Dev Fork"), and copy your account address (usually displayed prominently at the top). 2. **Fund in Tenderly:** Go back to your Tenderly Virtual Testnet page. 3. Click the **"Fund Account"** button. 4. Paste your MetaMask account address into the provided field. 5. Leave the amount as the default (e.g., 1000 ETH) or adjust if desired. 6. Click "Fund". 7. **Check Balance:** Open MetaMask again. You should see the balance updated almost instantly to 1000 ETH (or the amount you requested). Note that any displayed USD value is based on the real ETH price and is purely illustrative; this virtual ETH has no monetary value. You now have ample "test" ETH on your private network, obtained in seconds! ## Deploying Your Smart Contract to Tenderly With Remix connected via MetaMask to your funded Tenderly Virtual Testnet, you're ready to deploy. **Potential Remix/Vyper/MetaMask Bug Workaround:** *As of the time of some recordings, a minor bug occasionally affects deploying Vyper contracts via MetaMask to custom networks unless a Solidity contract has also been compiled in the same Remix session.* If you encounter deployment issues: 1. Create a new file in Remix named `dummy.sol`. 2. Paste the following minimal Solidity code: ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.18; contract Dummy {} ``` 3. Go to the Solidity Compiler tab in Remix and compile `dummy.sol`. 4. Switch back to your `favorites.vy` file. 5. Go to the Vyper Compiler tab and re-compile `favorites.vy`. 6. Proceed to the "Deploy & Run Transactions" tab. **Deployment Steps:** 1. **Verify Setup:** * Ensure the Remix "Environment" is still set to "Injected Provider - MetaMask". * Confirm MetaMask is connected to your Tenderly network ("My Dev Fork"). * Select your compiled Vyper contract (`favorites - favorites.vy`) from the "Contract" dropdown in Remix. 2. **Deploy:** Click the orange **"Deploy"** button in Remix. 3. **Confirm in MetaMask:** MetaMask will pop up with a transaction confirmation request for *contract deployment*. * Review the details: It will likely show a negligible gas fee (as Tenderly handles this on virtual testnets), the nonce (should be 0 for your first transaction), and the **Hex Data**. This data represents your compiled contract bytecode. * Click **"Confirm"**. 4. **Verify Deployment:** * The Remix terminal should show output indicating the transaction was successful and provide the address of your newly deployed contract. * The contract instance will appear under the "Deployed Contracts" section in Remix. * If you check the "Transactions" tab or the Public Explorer link for your Virtual Testnet in Tenderly, you will see the contract creation transaction recorded. ## Interacting with Your Deployed Contract on Tenderly Now that your contract lives on your virtual testnet, you can interact with it just like you did in the Remix VM, but now involving MetaMask for state changes. 1. **Use Deployed Instance:** In Remix, under "Deployed Contracts", expand your deployed `favorites` contract instance. 2. **Read State (Read-Only Calls):** Click buttons corresponding to read-only functions or public state variables (e.g., `my_favorite_number`, `my_name`, `index`). These calls retrieve data directly from the network state (your Tenderly fork) and do *not* require a MetaMask transaction confirmation. The values should reflect the initial state of your contract. 3. **Write State (State-Changing Calls):** Call a function that modifies the contract's state, like `add_person`. Enter the required arguments (e.g., "Alice" for `_name`, 42 for `_fav_num`) and click the function's button. 4. **Confirm in MetaMask:** Because `add_person` changes the blockchain state, MetaMask will pop up again. * Review the details: It will show you're interacting with your deployed contract's address, the nonce (now likely 1), and the relevant hex data representing the function call and its arguments. * Click **"Confirm"**. 5. **Verify Interaction:** * Wait for the transaction to be confirmed (visible in the Remix terminal and Tenderly). * Now, perform read calls again (e.g., check `index` or use `name_to_favorite_number("Alice")`). The returned values should reflect the changes made by the `add_person` transaction. ## Conclusion: Your First Real Deployment Congratulations! You have successfully: * Configured MetaMask to connect to external networks. * Understood the limitations of public testnets for development. * Set up and funded a Tenderly Virtual Testnet – a powerful tool for developers. * Deployed a smart contract from Remix to a realistic, forked network environment using MetaMask. * Interacted with your deployed contract, performing both read and write operations. The process you just completed—using Remix, MetaMask (as an Injected Provider), and connecting to a network (in this case, Tenderly)—is fundamentally **the exact same workflow** you would use to deploy to *any* EVM-compatible blockchain, including Ethereum Mainnet, Polygon, Arbitrum, Optimism, Base, ZKsync, and many others. The only differences would be selecting the target network in MetaMask and ensuring you have the appropriate (real) currency to pay for gas fees. You've taken a significant step from simulated environments to real-world deployment practices. Feel proud of this accomplishment – you are well on your way to becoming a proficient smart contract developer. Take a break, celebrate this milestone, and perhaps share your progress! If you encountered any issues, remember to utilize resources like AI assistants (Claude, ChatGPT, Phind), check the course's GitHub Discussions page, or ask questions in the community forums. Keep building!
A hands-on walkthrough to Deploying Your Smart Contract Beyond the Remix VM - Master deploying smart contracts to realistic network environments using MetaMask, leveraging Tenderly Virtual Testnets to bypass public testnet limitations.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
The basics of blockchain transactions, how to send and receive money on a blockchain network.
How to write Python based smart contracts using Vyper.
How to read and understand Vyper smart contracts.
Vyper data structures, arrays, structs, hash maps.
How to build a smart contract application and deploy on ZKsync with Moccasin.
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on June 11, 2025
Duration: 2h 08min
Duration: 2h 32min
Duration: 24min
Course Overview
About the course
The basics of blockchain transactions, how to send and receive money on a blockchain network.
How to write Python based smart contracts using Vyper.
How to read and understand Vyper smart contracts.
Vyper data structures, arrays, structs, hash maps.
How to build a smart contract application and deploy on ZKsync with Moccasin.
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on June 11, 2025