[英]How would one create a new Ethereum node from the browser?
I'm reading the Web3 documentation and I see that using it in the console requires a running Ethereum node. 我正在阅读Web3文档,并且看到在控制台中使用它需要运行中的以太坊节点。 But since plenty of DApp users will be new to Ethereum, what are the standard ways of generating new nodes from the browser? 但是,由于大量的DApp用户将是以太坊的新手,因此从浏览器生成新节点的标准方法是什么?
Of course, this can be done with the Geth command line tools - but how does one use these tools in the console? 当然,可以使用Geth命令行工具完成此操作-但是如何在控制台中使用这些工具?
As far as I know, there is not yet a way to run a node in the browser but you can get to something apparently close using Metamask. 据我所知,还没有一种方法可以在浏览器中运行节点,但是您可以使用Metamask来达到明显关闭的目的。
If you use geth, you can start it with geth console
, that will give you access to the console. 如果使用geth,则可以使用geth console
启动它,这将使您可以访问控制台。
If you started a node with rpc (geth or other) you can attach geth to it with geth attach http://localhost:8545
如果您使用rpc(geth或其他)启动节点,则可以使用geth attach http://localhost:8545
到该节点上。 geth attach http://localhost:8545
If you are running a DAPP in your browser, it very likely loaded web3.js into your browser for you. 如果您在浏览器中运行DAPP,则很有可能会为您将web3.js加载到浏览器中。 If you open the dev console, you can also access web3 through the console. 如果打开开发人员控制台,则还可以通过控制台访问web3。
Finally, you can also use Metamask (a chrome extension) that will inject web3.js in your browser. 最后,您还可以使用Metamask(chrome扩展程序),该工具将在浏览器中注入web3.js。 From there, you can open the dev console and start issuing commands such as web3.eth.accounts
从那里,您可以打开开发控制台并开始发出命令,例如web3.eth.accounts
In case you are running a DAPP in browser, alternative to MetaMask ( which I highly recommend ) could be connection to 如果您在浏览器中运行DAPP,则可以连接MetaMask(我强烈推荐)的替代方法
https://infura.io/ , register (api key will be generated for you), so you could "connect trough" them. https://infura.io/ ,注册(将为您生成api密钥),因此您可以“连接槽”它们。 ( even though MetaMask uses Infura as well, I think ) Something like this ( in context of code ): (尽管我认为MetaMask也使用Infura)(在代码上下文中)这样的东西:
web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/efYr0Kza6Io9M1NPXZA1');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.