NestJS Enterprise Backend APIs · Lezione

Deploy su testnet e mainnet

Comprendere il processo di deploy delle proprie DApp sulle testnet pubbliche per i test finali e, infine, sulla mainnet di Ethereum.

Lezione 6 di 611 passaggi

Deploy su testnet e mainnet è una lezione NestJS Enterprise Backend APIs gratuita su CoddyKit. Questa è la lezione 6 di 6. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NestJS Enterprise Backend APIs, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NestJS Enterprise Backend APIs include 6 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

What is DApp Deployment?

Welcome! Today, we'll learn about deploying Decentralized Applications (DApps). Deployment is the process of publishing your smart contracts and associated front-end code to a blockchain network.

It's a crucial step that makes your DApp accessible to users worldwide. Without deployment, your DApp remains just code on your computer.

Why Deploy to Testnets First?

Before launching your DApp to the world, it's vital to test it thoroughly. This is where testnets come in!

  • Testnets are separate blockchain networks that mimic the main Ethereum network.
  • They use 'test Ether' (fake currency) for transactions, so you can test without risking real funds.
  • This allows developers to find and fix bugs, ensuring the DApp works as expected.

Key Ethereum Testnets

Ethereum has several public testnets. The most prominent one currently is Sepolia.

  • Sepolia: This is the recommended testnet for new development. It's a proof-of-stake network, like the Ethereum mainnet.
  • Historically, there were others like Goerli, but Sepolia is now the primary choice for testing smart contracts and DApps.

Connecting to a Testnet

To deploy to a testnet, your development environment (like Hardhat or Truffle) needs to connect to it. This is usually done via an RPC URL provided by a service like Infura or Alchemy.

These services act as a gateway, allowing your tools to communicate with the blockchain without running a full node yourself. You'll need an API key for access.

Getting Test Ether (Faucets)

On a testnet, every transaction (including contract deployment) requires gas, paid in test Ether. You can get free test Ether from a faucet.

A faucet is a web service that sends small amounts of test Ether to your wallet address. Simply visit a Sepolia faucet website, enter your address, and request funds.

Deployment Scripts

Deploying smart contracts manually can be tedious. That's why we use deployment scripts, typically written in JavaScript.

These scripts automate the process of compiling your contract, signing the transaction with your private key, and sending it to the chosen blockchain network (testnet or mainnet).

Understanding Gas for Deployment

Every operation on Ethereum, including contract deployment, consumes gas. Gas is a unit that measures the computational effort required.

  • Gas Limit: The maximum gas you're willing to spend.
  • Gas Price: How much Ether you're willing to pay per unit of gas.
  • Total Cost: Gas Limit × Gas Price.

Deployment is often one of the most gas-intensive transactions.

Connecting to a Network Example

Here's a simple JavaScript snippet using Ethers.js to connect to an Ethereum network and fetch its current block number. This is a foundational step for any deployment script.

Remember to replace YOUR_INFURA_API_KEY with your actual key.

const { ethers } = require("ethers");

async function main() {
  // Connect to a Sepolia testnet RPC (Infura example)
  const provider = new ethers.JsonRpcProvider("https://sepolia.infura.io/v3/YOUR_INFURA_API_KEY");

  try {
    const blockNumber = await provider.getBlockNumber();
    console.log("Connected to network. Current block number:", blockNumber);
  } catch (error) {
    console.error("Failed to connect or get block number:", error.message);
  }
}

main();

Deploying to Mainnet

Once your DApp is thoroughly tested on testnets, you might consider deploying to the Ethereum Mainnet. This is the live, public blockchain where real assets and value exist.

  • Real Funds: Mainnet deployments cost real Ether.
  • Security: Ensure extensive audits and testing have been completed.
  • Immutability: Once deployed, smart contracts are generally unchangeable.

Always proceed with extreme caution and ensure all configurations are correct!

Deployment Knowledge Check

You've learned about deploying DApps. Let's test your understanding!

Deployment Journey Recap

Well done! You've learned the essential steps for deploying DApps.

  • We started with testnets for safe, free testing.
  • We explored how to connect to networks and get test Ether.
  • You now understand the role of deployment scripts and gas costs.
  • Finally, we discussed the critical considerations for deploying to the mainnet.

This knowledge is fundamental for bringing your decentralized applications to life!

Gratis per iniziare

Impara TypeScript con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
20
Lezioni
76

Domande Frequenti

La lezione «Deploy su testnet e mainnet» è gratuita?

Sì — il testo completo di «Deploy su testnet e mainnet» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NestJS Enterprise Backend APIs, passa a CoddyKit PRO. Il corso NestJS Enterprise Backend APIs include 6 lezioni in totale.

Cosa imparerò in «Deploy su testnet e mainnet»?

Comprendere il processo di deploy delle proprie DApp sulle testnet pubbliche per i test finali e, infine, sulla mainnet di Ethereum. Eserciti NestJS Enterprise Backend APIs con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare NestJS Enterprise Backend APIs?

Non è richiesta alcuna esperienza precedente. NestJS Enterprise Backend APIs su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 6 di 6.

Quanto tempo richiede la lezione «Deploy su testnet e mainnet»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione NestJS Enterprise Backend APIs?

Sì. Ogni lezione NestJS Enterprise Backend APIs include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Test unitari ed E2E
  2. Framework Hardhat e Truffle
  3. Test delle prestazioni delle API
  4. Test unitari degli smart contract
  5. Dockerizzazione e Kubernetes
  6. Deploy su testnet e mainnet
← Torna a NestJS Enterprise Backend APIs