Skip to content

Latest commit

 

History

History
163 lines (106 loc) · 8.27 KB

ethereum-testnets.asciidoc

File metadata and controls

163 lines (106 loc) · 8.27 KB

Testnet Overview

What is a testnet?

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.

Using Testnets

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.

Getting Test Ether

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.

Connecting to Testnets

Metamask

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

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

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

Parity

Connecting to a testnet in Parity requires using command-line arguments. For instance, to start Parity on the Ropsten testnet, run:

parity --chain ropsten

Parity supports such commands for most testnets.

Ethereum Testnets In Depth

Ropsten

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.

Rinkeby

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/

Kovan

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

Morden

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

Running Local Testnets

Ganache: A personal blockchain for Ethereum development

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.

Ganache CLI: Ganache as a command-line tool

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;