Развёртывание в тестовых сетях и основной сети
Изучите процесс развёртывания децентрализованных приложений в публичных тестовых сетях для финального тестирования и последующего запуска в основной сети Ethereum
«Развёртывание в тестовых сетях и основной сети» — бесплатный урок NestJS Enterprise Backend APIs на CoddyKit. Это урок 6 из 6. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения NestJS Enterprise Backend APIs, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс NestJS Enterprise Backend APIs содержит 6 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
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!
Изучай TypeScript с ИИ-репетитором — бесплатно
Пиши и запускай код прямо в браузере, получай мгновенную помощь от ИИ-репетитора 24/7 и продолжи учиться на сайте или в приложении.
- Курсы
- 20
- Уроки
- 76
Часто задаваемые вопросы
Урок «Развёртывание в тестовых сетях и основной сети» бесплатный?
Да — полный текст урока «Развёртывание в тестовых сетях и основной сети» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс NestJS Enterprise Backend APIs, подпишись на CoddyKit PRO. Курс NestJS Enterprise Backend APIs содержит 6 уроков всего.
Чему я научусь в уроке «Развёртывание в тестовых сетях и основной сети»?
Изучите процесс развёртывания децентрализованных приложений в публичных тестовых сетях для финального тестирования и последующего запуска в основной сети Ethereum Ты практикуешь NestJS Enterprise Backend APIs с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать NestJS Enterprise Backend APIs?
Предыдущий опыт не требуется. NestJS Enterprise Backend APIs на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 6 из 6.
Сколько времени занимает урок «Развёртывание в тестовых сетях и основной сети»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке NestJS Enterprise Backend APIs?
Да. Каждый урок NestJS Enterprise Backend APIs включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Модульное и сквозное тестирование
- Фреймворки Hardhat и Truffle
- Тестирование производительности API
- Модульное тестирование смарт-контрактов
- Контейнеризация с Docker и Kubernetes
- Развёртывание в тестовых сетях и основной сети