In Ethereum, what is a private testnet, why would

2019-07-10 05:43发布

问题:

I've seen/heard developers talk about Ethereum test nets, but I've just been publishing to the public block chain. What is a private test net and how do I set one up?

回答1:

A private testnet is your own personal, local-to-your-machine blockchain to mess around with. Publishing to the public chain is slow and creates bloat. Plus, you have to use real ether to do anything. A private test net avoids these issues.

Setting up a private testnet is easier than you’d think.

geth --rpc --rpcaddr "127.0.0.1" --rpcport "8545" --dev --mine 

This says, “start a geth instance with JSON RPC (for web3.js interaction) at the given IP and port, create a private chain and start mining it.” In the log, you should see lots of the hammer icons, signifying that you’re mining your private chain’s blocks. (CPU-only mining is sufficient because the difficulty begins so low.)

When you type “geth attach” per usual in another terminal window, you’ll see that all of your accounts balances are zero except your coinbase which is rapidly filling up with fake ether. Don’t worry. Your accounts aren’t really zero. All their “real” values will be there if you connect to a “real” geth instance and the public blockchain.

Now you can interact with your private test net just as you would the public one.



回答2:

A diffrent way to setup a private Network is to use testrpc. This kinda simulates a ethereum Network by providing a local client that acts as if it is connected to a network for development and testing. The advantage is, that it is very fast, but it will not presist the state of your network as it operates completely in memory.



标签: ethereum