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 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, its tests are mostly done on these test networks. These test networks are also used by a large number of developers for testing applications before deploying them onto the main network.
You can either connect to publicly available test networks or spawn a development network of your own. First, let’s use a public testnet for easier setup. To use a public testnet requires some testnet ethers and a connection to that network. For testnet ethers, faucets are used. To connect to testnets, we will discuss how to do so in various popular clients.
Since testnets do not operate with real money, the incentive to secure the testnets by miners is low. 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' ether at 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, simpy clicking the drop down that says 'Main Network' allows for switching networks. MetaMask offers an option to buy ether. If the Ropsten testnet is used, ether can be obtained from the Ropsten Test Faucet Service. You can access this faucet from this page. It requires the Metamask extension to work. https://faucet.metamask.io/
Infura was born with the goal of delivering stable and reliable RPC access to the internal projects within ConsenSys. As the Ethereum network began to grab the majority of blockchain developer mindshare, ConsenSys recognized that Infura would be of broad interest to the entire ecosystem. It provides access to Ethereum APIs and IPFS gateways. Using Infura with testnets is simple enough. Infura supports gatweays for the main net, Ropsten, Kovan, Rinkeby and INFURAnet (a custom testnet for Infura). Sending API calls to testnets from Infura simply involves changing the base URL for API calls. More information on the details of these API calls is located at: https://infura.io/docs/gettingStarted/chooseaNetwork
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 writing this, the Ropsten blockchain is significantly smaller than the main Ethereum blockchain and consists of about 14GB of data. Since the testnet requires fewer resources, it is simpler to setup and test your code on the testnet first.
Interacting with the tesnet 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
More on setting up geth at: Go-Ethereum (Geth)
Tip
|
Although much smaller, it might still take time for the testnet to fully sync. You can check if syncing was complete 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 network, use the command-line argument:
geth --rinkeby
If you want to begin testing contracts on the Ropsten network, there are several faucets that you can source your Ropsten ethers from. If a faucet does not work, try a different one.
-
http://faucet.ropsten.be:3001/
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/.
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, Goole Plus or Facebook. https://www.rinkeby.io/ https://rinkeby.etherscan.io/
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: http://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
Morden to Ropsten, Kovan, Rinkeby
Ethereum’s Morden testnet ran from July 2015 to November 2016. While anyone using Ethereum can create a testnet, Morden was the first official public 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 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 inflate the block gas limits to 9 billion (from the normal 4.7 million), at which point sending in gigantic transactions crippling the entire network.
Kovan is powered by Parity’s Proof-of-Authority consensus algorithm. The testnet is immune to spam attacks because the Ether supply is controlled by trusted parties. Those trusted parties are companies 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.
The Rinkeby testnet was started by the Ethereum team and uses the PoA consensus protocol, Started in April 2017. Named after a metro station in Stockholm, is it virtually Immune to spam attacks (as Ether supply is controlled by trusted parties).
TODO: write up pros and cons of both mechanisms
You can use Ganache to deploy contracts, develop your applications, and run tests. It is available as a desktop application for Windows, Mac, and Linux.
Website: http://truffleframework.com/ganache
This tool was previously known under the name "ethereumJS TestRPC".
$ npm install -g ganache-cli
Let’s start a node simulation of the Ethereum blockchain protocol.
* [ ] Check the --networkId
and --port
flag values match your configuration in truffle.js
* [ ] Check the --gasLimit
flag value matches the latest Mainnet Gas Limit (i.e. 8000000 gas) shown at https://ethstats.net to avoid encountering out of gas
exceptions unnecessarily. Note that a --gasPrice
of 4000000000 represents a Gas Price of 4 gwei.
* [ ] Optionally enter a --mnemonic
flag value to restore a previous HD wallet and associated addresses
$ ganache-cli \ --networkId=3 \ --port="8545" \ --verbose \ --gasLimit=8000000 \ --gasPrice=4000000000;