In Ethereum, what is a private testnet, why would I want it, and how do I set it up?

懵懂的女人 提交于 2019-12-11 03:34:34

问题


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.



来源:https://stackoverflow.com/questions/33826018/in-ethereum-what-is-a-private-testnet-why-would-i-want-it-and-how-do-i-set-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!