A test network (testnet for short) is used to simulate the behavior of the main Ethereum network. There are some publicly available test networks that are simply alternative Ethereum blockchains. The currency on these networks is worthless, but they are still useful since the functionality of contracts and protocol changes can be tested without disrupting the main Ethereum network or using real money. When any major change to the Ethereum protocol is about to be included in the main network (mainnet for short), it is tested mostly on these test networks. They are also used by a large number of developers to test applications before deploying them on the main network.
You can either connect to publicly available test networks or spawn a private test network of your own. First, let’s use a public testnet for easier setup. To use a public testnet requires some testnet ether and a connection to that network. For testnet ether, "faucets" are used, which distribute test ether slowly, "dripping" out a small amount to anyone who asks. To connect to a testnet, you need an Ethereum client, either a full client, such as Geth, or a gateway to a full client, such as MetaMask.
Since testnets do not operate with real money, there is little incentive for miners to secure them. Therefore, the testnets must protect themselves from abuse and attacks differently. As a result, faucets were created for these testnets to distribute free test ether to developers in a controlled manner (most faucets 'drip' at the rate of 1 ether every few seconds or so). This controlled distribution of ether prevents users from abusing the chain since giving a limited supply of ether prevents them from writing too much to the chain or executing too many transactions. Additionally, some testnets have implemented Proof of Authentication schemes, where using a faucet requires authentication from a social media site with proper credentials.
MetaMask fully supports the Ropsten, Kovan and Rinkeby testnets, but connecting to other testnets and local networks is also possible. In Metamask, simply clicking the drop down that says 'Main Network' allows you to switch networks. MetaMask also offers an option to "buy" test ether, which directs you to a faucet where you can request free test ether. If the Ropsten testnet is used, ether can be obtained from the Ropsten Test Faucet Service. You can access this faucet from the following page. It requires the Metamask extension to work. https://faucet.metamask.io/
When MetaMask connects to a test network, it uses the Infura service provider for the JSON-RPC interface. Infura was designed to offer stable and reliable RPC access to internal projects within ConsenSys. In addition to a JSON-RPC API, Infura also has a REST (Representational State Transfer) API, IPFS (Interplanetary File System, i.e. decentralized storage) API, and a Websockets (i.e. streaming) API.
Infura offers gateway APIs to the Ethereum mainnet, Ropsten, Kovan, Rinkeby, and INFURAnet (a custom testnet for Infura).
To use Infura via MetaMask for low levels of activity, you do not need an account. For direct use of the API, you need to register an account and use an API key provided by Infura.
More information on Infura can be found at https://infura.io/
Remix IDE may be used to deploy and interact with smart contracts on the mainnet and testnets including Ropsten, Rinkeby, and Kovan (Web3 Provider using an Infura address and an API key or via Injected Web3 to use the network chosen in MetaMask) and Ganache (Web3 Provider Endpoint http://localhost:8545)
Geth natively supports both the Ropsten and Rinkeby networks. To connect to the Ropsten network use the command-line argument:
geth --testnet
This will start syncing the Ropsten blockchain. A new directory named testnet will be created in your main Ethereum data directory. A keystore directory will be created inside testnet and will store the private keys of your testnet accounts. As of this writing, the Ropsten blockchain is significantly smaller than the main Ethereum blockchain: about 14GB of data. Since the testnet requires fewer resources, it is simpler to set up and test your code on the testnet first.
Interacting with the testnet is similar to the mainnet. You can start Geth testnet with a console by running:
geth --testnet console
This makes it possible to perform operations such as opening a new account, checking your balance, checking the balance of other Ethereum addresses, etc.
When running outside of the Geth console, operations can be performed similarly to how they would have been performed on the mainnet, simply by adding the --testnet
parameter to the command-line instruction. As an example, to list all the available testnet accounts and their addresses, run:
geth --testnet account list
Tip
|
Although it much smaller than mainnet, it will still take some time for the testnet to fully sync. |
You can check if geth has completed syncing the testnet by running the following command in the geth interactive console:
eth.getBlock("latest").number
This should return a number other than 0 once your testnet node is fully in sync. You can compare the number to the latest block in a known testnet block explorer, such as https://ropsten.etherscan.io/
Similarly, to connect to the Rinkeby test network, use the command-line argument:
geth --rinkeby
At this stage you’re probably thinking: "I understand why I might use a test network. But why are there so many of them?"
If you want to begin testing contracts on the Ropsten network, there are several faucets from which you can source your Ropsten ether. If one faucet does not work, try another!
-
https://faucet.ropsten.be/
This faucet provides the possibility to queue the address that should receive the test ether. -
The bitfwd Ropsten Faucet
A Ropsten faucet available at https://faucet.bitfwd.xyz/. -
Kyber Network Ropsten Faucet
Another Ropsten faucet available at https://faucet.kyber.network/. -
MetaMask Ropsten Faucet
https://faucet.metamask.io/ -
Ropsten Testnet Mining Pool
http://pool.ropsten.ethereum.org/ -
Etherscan Ropsten Pool https://ropsten.etherscan.io/
The Rinkeby faucet is located at https://faucet.rinkeby.io/. To request test ether it is necessary to make a public post on either Twitter, Google Plus or Facebook.
The Kovan testnet supports various methods to request test ether. Further information can be found in the Kovan testnet GitHub Repository located at https://github.com/kovan-testnet/faucet/blob/master/README.md.
Ethereum Classic currently runs a variant of the Morden testnet that is kept at feature parity with the Ethereum Classic live network. You can connect to it through either the gastracker RPC or by providing a flag to geth
or parity
Faucet: https://testnet.epool.io/
Gastracker RPC: https://web3.gastracker.io/morden
Block Explorer: http://mordenexplorer.ethertrack.io/home
Geth flag: geth --chain=morden
Parity flag: parity --chain=classic-testnet
Olympic, Morden to Ropsten, Kovan, Rinkeby
Olympic testnet (Network ID: 0) was the first public testnet for Frontier (referred to as Ethereum 0.9). It was launched in early 2015 and deprecated in mid 2015 when it was replaced by Morden.
Ethereum’s Morden testnet (Network ID: 2) was launched with Frontier and ran from July 2015 until it was deprecated in November 2016. While anyone using Ethereum can create a testnet, Morden was the first "official" public testnet and replaced the Olympic testnet. Due to long sync times stemming from a bloated blockchain, and consensus issues between the Geth and Parity clients, the testnet was rebooted and reborn as Ropsten.
Ropsten (Network ID: 3) is a public cross-client testnet for Homestead that was introduced in late 2016 and ran smoothly as the public testnet until the end of February 2017. According to Péter Szilágyi, a core developer for Ethereum, the end of February is when "malicious actors decided to abuse the low PoW and gradually inflated the block gas limits to 9 billion (from the normal 4.7 million), at which point sending in gigantic transactions crippled the entire network". Ropsten was recovered in March 2017. https://github.com/ethereum/ropsten
Kovan (Network ID: 42), named after a metro station in Singapore, is a public Parity testnet for Homestead that is powered by Parity’s Proof-of-Authority (PoA) consensus algorithm. The testnet is immune to spam attacks because the Ether supply is controlled by trusted parties. Those trusted parties are companies<<[1]>> that are actively developing on Ethereum. While it seems like this should be a solution to Ethereum’s testnet troubles, there appear to be consensus issues within the Ethereum community regarding the Kovan testnet.
Rinkeby (Network ID: 4), named after a metro station in Stockholm, is a public Geth testnet for Homestead that was started in April 2017 by the Ethereum team and uses the PoA consensus protocol. Similarly to Kovan, it is immune to spam attacks because supply of Ether is controlled by trusted parties. Refer to EIP 225: ethereum/EIPs#225