1:ganache安装参考:https://github.com/trufflesuite/ganache

2:安装完成执行ganache 出现下图,代表成功并启动了,ganache启动私链默认会创建10个账户并有1000个eth

3:用web3js 连接访问ganache的私链安装web3

npm install web3 -save

 4:创建一个js文件 如test.js

const Web3 = require("web3");

const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

console.log(web3.version);
web3.eth.getAccounts().then(console.log);

5: 在test.js目录执行node  test.js,出现如下结果,打印了版本和打印了账户,代表成功连接到私链

 

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐