Dealing with different network modes

Waves Tech
Waves Protocol
Published in
6 min readAug 25, 2020

A blockchain network is made of nodes interacting with each other. The Waves protocol offers developers several network options, which we’ll discuss in this article.

Why we need different networks

The mainnet uses the real WAVES token. Since each transaction requires a fee, using the mainet for development purposes would be costly. Similarly, making mistakes during testing could result in a loss of funds or even an entire account.

You want to choose the testnet if you develop using the current node/Ride version of the Waves smart contract or the stagenet if you plan to use experimental features or those still in development.

Keep in mind that the stagenet could be reset with all data removed, whereas on the testnet, this doesn’t occur.

From mainnet to customnet

The mainnet is the core Waves network where cryptocurrencies possess a real economic value and nodes that generate blocks are rewarded with native coins from the protocol and from transaction fees paid by users.

The testnet is a network for application testing. The testnet provides the same functionalities as the mainnet. However, on the testnet, you can obtain WAVES tokens for free using a faucet. As a result, you can run your project without a risk of losing real money.

The stagenet is an experimental network. On it, the Waves team can test new protocol functionalities before they would be deployed on the testnet or mainnet and collect user feedback. If you want to launch a stagenet node, lease WAVES tokens, ask a question or leave a comment and join the stagenet. Please note that experimental functionalities may be unstable and blockchain height rollbacks are possible.

The devnet is a locally deployed node used for development purposes. The easiest way to deploy a devnet node is by using a Docker container on the testnet or stagenet.

The customnet is a Waves blockchain deployed with a customized genesis configuration where you can define your own custom network type, initial balance etc. A custom network won’t connect to any other node from the mainnet, testnet or stagenet, acting as your own isolated network.

Using the networks

Waves networks use unique identifiers that are often requested in libraries and development tools.

Mainnet = W or 87 (ASCII code of W).

Testnet = T or 84 (ASCII code of T).

Stagenet = S or 83 (ASCII code of S).

Custom = a symbol chosen by the network owner and specified in the address-scheme-character setting.

Currently, all mainnet addresses start with “3P” and all testnet and stagenet addresses start with “3M” or “3N”. The idea of using these categories to identify the network of a given address is tempting, but these categories could change in the future.

To identify a network you are dealing with, it’s best to convert the address (which is encoded in base58 from bytes) back to bytes where the second byte represents your network identifier. This is an example with the @waves/ts-lib-crypto library.

Type “node” in your console to switch to REPL (requires nodejs to be installed), then the following:

const libs = require(“@waves/ts-lib-crypto”)libs.base58Decode(“3NBFcaDqHTRhHGYKXRkdGg4XuqnZdsRCtvH”)

The second byte of the result is the chainId of the address in ASCII.

As a side note, keep in mind that seed phrases, 15 random words generally requested for security purposes, are the same for the testnet, stagenet or mainnet, since the difference is in the address.

Waves Signer

Working with Waves Signer, you need to define the network NODE_URL parameter. By default, it would be the mainnet, but if, for example, you want to use the testnet, set the node URL as follows:

import Signer from ‘@waves/signer’;import Provider from ‘@waves.exchange/provider-web’;const signer = new Signer({// Specify URL of the node on TestnetNODE_URL: ‘https://nodes-testnet.wavesnodes.com'});signer.setProvider(new Provider());

For more details see https://github.com/wavesplatform/signer

Waves Keeper

With Waves Keeper, you don’t have to define the network in your code, but you can check what network the user is connected to via their Waves Keeper:

if (typeof WavesKeeper !== ‘undefined’){document.getElementById(‘login’).addEventListener(‘click’, function(e){WavesKeeper.publicState().then(state => {if((state.network.code == “T”)){console.log(`Waves Kepper is on Testnet Network`);// your code}else{console.log(`Switch your Waves Keeper network to Testnet Network`)}}).catch(error => {console.error(error);})})}

“WavesKeeper” is a global object injected by the extension, so you can access it from anywhere in your code. If it is not defined, it means that Waves Keeper is not installed. If it is defined, the user should be able to connect.

You can use this to alert a user if their Waves Keeper network isn’t matching the network requested by your web application.
https://github.com/wavesplatform/waveskeeper

Public node addresses

You can use a public network for development but not all API endpoints are publicly available. Depending on your specific needs, you may want to set up your own development node. But for regular purposes, you can use the following public nodes:

Mainnet: https://nodes.wavesplatform.com

Testnet: https://nodes-testnet.wavesnodes.com
Stagenet: https://nodes-stagenet.wavesnodes.com/

Set up your own node

If you need to set up your own node for any network, use the official documentation. The main advantage will be to have your own API KEY and access to the entire Node API with no restrictions, as well as supporting the network if you open up a node for mining. https://docs.waves.tech/en/waves-node/how-to-install-a-node/how-to-install-a-node

Online IDE

If you use the Waves Online IDE, you can choose between the mainnet and the testnet as shown below:

https://waves-ide.com/

If you work on the stagenet, you will have to use the following version: https://stagenet.waves-ide.com/

Other useful tools

If you use different networks, it will be very helpful to have API and tools also available for a relevant network. All of them are available on the testnet and stagenet.

WAVES EXPLORER

Mainnet: https://wavesexplorer.com

Testnet: https://wavesexplorer.com/testnet
Stagenet: https://stagenet.wavesexplorer.com/

WAVES.EXCHANGE

Mainnet: https://waves.exchange

Testnet: https://testnet.waves.exchange

Stagenet: https://stagenet.waves.exchange/

WAVES DATA SERVICE

Mainnet: https://api.wavesplatform.com/v0/docs/
Testnet: https://api-test.wavesplatform.com/v0/docs/
Stagenet: https://api-stagenet.wavesplatform.com/v0/docs/

WAVES.EXCHANGE Matcher API

Mainnet: https://matcher.waves.exchange/

Testnet: https://matcher-testnet.waves.exchange

Stagenet: https://matcher-stagenet.waves.exchange/

How about devnet?

A devnet is a locally installed network for development. The easiest way to deploy it is by using a Docker image and setting it as a testnet or stagenet node. This is very convenient for developers and you will find the details on the Docker page:

https://hub.docker.com/r/wavesplatform/waves-private-node

If you want to dig deeper, consider using your devnet with the surfboard tool: https://medium.com/wavesprotocol/how-to-build-deploy-and-test-a-waves-ride-dapp-785311f58c2

And custom networks?

A custom network operates just like any other network except that you have a custom configuration and are alone on the network, unless you set up more nodes and connect them to each other. All details about custom node configuration are available here: https://docs.waves.tech/en/waves-node/private-waves-network#setup-jar-node-with-custom-blockchain

Build solutions with Waves!

Understanding differences between networks is an important step towards bApp and dApp development. When it comes to these network modes, Waves offers a wide range of options, as well as various tools and libraries, allowing you to develop safely before your final mainnet deployment.

--

--

Waves Tech
Waves Protocol

Waves Tech is a powerful blockchain-agnostic ecosystem focused on inter-chain DeFi, the embodiment of technological freedom for blockchain-based finance.