Devnet vs Testnet vs Mainnet: What Do They Mean for Web3 Developers?

Devnet vs testnet vs mainnet… What are these nets, and why so many? Mainnet (main network), testnet (test network), and devnet (development network) are terms used to describe different kinds of blockchain networks. Read on to learn more about what each network is for and what role they play in your Web3 development journey.

Deep dive
January 3, 2023
Developer Advocate
Devnet vs testnet vs mainnet

Devnet vs Testnet vs Mainnet

Devnet, testnet, and mainnet refer to types of blockchain networks used for development, testing, or production within a blockchain ecosystem. The first two kinds—the devnet and testnet—are used for deploying code still in development and testing, where developers can learn more about their applications without running the risk of affecting real-world assets with economic value. Mainnet is for production-ready code: other users can now interact with your application and spend their valuable crypto assets.

What Is a Devnet?

A devnet refers to a local blockchain development environment and is used for rapid development of smart contracts. With a devnet, your smart contract application can interact with simulated blockchain entities (miners, nodes, and a stream of mined blocks), all within your local machine.

Because the development environment is simulated, devnets enable you to create different blockchain configurations to test your code and its requirements. For example, you can start a devnet at an arbitrary block height with a specified network upgrade at a later block, and with many simulated users, to see how your application responds.

Importance of Devnet to Web3 Developers 

When devnets simulate a blockchain environment, the entities created—the other contracts, transactions, or nodes—resemble the conditions your application will inhabit once in production. But since these are simulations, some of their details or features can be changed to facilitate rapid testing and development. 

For instance, on mainnet, Stacks miners mine a block every 10 minutes on average. With devnet, simulated blocks are produced every 30 seconds (and you can adjust that setting to whatever frequency so desired), allowing you to rapidly test your code instead of waiting for a 10 minute transaction confirmation. Devnets are especially useful for troubleshooting bugs and making sure that the code works as intended with a simulated network before deploying the code on a public network. 

Unlike testnets, which are public, each devnet is a single local instance of a simulated network. Any developer, or team, that wants to test the code will need to simulate their own devnet in a local environment and do the testing inside it. It is not usually a public environment, though it can be collaboratively shared amongst a team of developers.

How To Create a Devnet

Different blockchains have different processes for spawning local devnets. But generally, you can create one through a command line interface application. For example, to create a devnet for Stacks, you would use Clarinet. See an example of how to set up a Stacks devnet in this resource

What Is a Testnet?

A testnet (sometimes called a mocknet) refers to a public blockchain network used to test smart contracts and dApps before they are deployed to mainnet (the live production environment). A testnet is an independent chain that runs parallel to mainnet and closely simulates it.

Testnets are geared toward stress-testing Web3 apps in a live blockchain environment. Testnets are a public network with real miners and blockchain nodes, and anyone can join and participate. Every mainnet has a corresponding testnet, and some mainnets may even have multiple testnets that offer different configurations to better test your code.

Devnets and their contracts usually exist only for as long as a single session of testing. Testnets are different: given their public and persistent nature, you will find smart contracts and transactions the result of other developers testing. This liveness and activity is closer to a production environment than a single-session devnet.

Importance of Testnet to Web3 Developers 

Testnets are used to test Web3 apps and smart contracts before they are deployed to mainnet. A testnet mimics its corresponding mainnet, with live miners, live blocks generated according to similar rules and conditions of the mainnet protocol, and live transaction data (all independent of what happens on mainnet). A local devnet is where a developer typically first debugs and analyzes code, to then deploy to testnet to see how their applications performs in an environment with user activity and other smart contracts. 

Importantly, testnets are also public networks, so not only can your entire team test and debug the code in the same environment, but you can also recruit beta testers from all over the world to interact with your app on testnet to collect more data and user feedback.

Lastly, it’s worth mentioning that testnets have token faucets, which are digital services that provide you with test tokens. Given that a testnet runs according to the same protocol rules as mainnet, deploying contracts or transacting with them requires spending a native gas token. Faucets provide you with these test tokens, and since these tokens have no real world value, transaction fees on testnet are effectively free.

How To Get Test Tokens for Use on Testnet

Generally, you can find information on how to access the faucet in the documentation of each blockchain ecosystem. You can also reach out directly to the team through community channels such as Discord to find out how to access their faucet. Visit the Stacks Explorer for the faucet for Stacks tokens.

Once you access the faucet and request the test tokens, they will be credited to your wallet for use. Some faucets may have limits on the number of test tokens you can get on each attempt, but generally, developers can get as many test tokens from the faucet as they need because the test tokens are free. 

What Is a Mainnet?

A mainnet refers to the live production environment for a particular blockchain. When developers deploy code to a mainnet, their code is publicly available to all users, and that code can interact with other apps deployed on the network.

Typically, each blockchain has its own mainnet—whether Bitcoin, Ethereum, or Polygon. In Web3 development, launching on the mainnet happens at the end of the development cycle, after extensive testing on both devnet and testnet. After deploying code to mainnet, your code is now live on the blockchain—congrats!—and can interact and respond to other users and their real world assets.

Importance of Mainnet to Web3 Developers

Mainnet is your production environment where users interact with your smart contract application.

Take care to publish verified, validated, tested code, as vulnerabilities in your smart contracts can be taken advantage of. Hacks, bugs, and exploits have consequences for the real-world assets your smart contract handles. Significantly and by design, when you publish your smart contract on mainnet, it will reside there forever—the censorship-resistance of blockchains—which makes it critically important to do extensive testing before any mainnet deployment.

Devnet vs Testnet vs Mainnet: Which To Use?

You will use a devnet, testnet, and mainnet at different stages of development when creating Web3 apps: a devnet to spin up a local blockchain environment for development, a testnet for testing in a live, public environment, and you will deploy production-ready code to mainnet. 

But before you get to the point of testing Web3 apps, you’ll need to code them first. Writing smart contracts can be an exciting but potentially intimidating challenge. That’s why we created a comprehensive guide to writing smart contracts, to ease you into the Web3 development journey. Download it for free below:

Download Hiro’s Guide to Developing Smart Contracts
Copy link
Hiro news & product updates straight to your inbox
Only relevant communications. We promise we won’t spam.

Related stories