锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

Dapp搭建学习记录(一)ganache+web3js

时间:2023-04-24 17:37:00 3bl振动烈度变送器

Dapp搭建


##方式一 geth js

1.centOs8安装geth客户端

https://its401.com/article/weixin_48288539/121287068#2geth_50

2.geth控制台的一些命令

geth客户端启动
geth --datadir testchaindata --networkid 10001 console 2>1.txt  geth --testnet --fast --cache=512 --datadir "/data/ethereum/block_data" --rpc --rpcapi db,net,eth,web3,personal --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*" console 
检查节点数量
eth.blockNumber 
创建账户
personal.newAccount("xxx") 
查看账户数量
eth.accounts 
启动挖矿
miner.start() 
检查开采是否开始
eth.mining 

##方式二 ganache js

1.全局安装Ganache命令行模式(要求 Node.js >= v10.13.0 and npm >= 6.4.1.)

npm install ganache --global 

这里遇到的一个问题是:npm dose not support Node.js v10.15.3
原来环境是node版本太低,解决方案删除原来nodejs,使用wget命令下载最新版本nodejs,这是下载nodejs17.解决问题。

启动ganache
ganache 

2.安装web3js并测试

npm install web3 

测试:

  • 建立nodejs测试文件
    vim test.js
  • 写入文件
    var Web3 = require('web3'); var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); console.log(web3.version); web3.eth.getAccounts().then(console.log);
  • 执行node test.js打印出web3版本,也证web3安装成功

3.express

express是基于 Node.js 快速、开放、极简的平台 Web 开发框架

  • 安装:

    npm install express -g

    npm install -g express-generator

  • 创建工程

    express -e MyDapp

    cd MyDapp
    启动工程
    npm start
    打卡浏览器http://127.0.0.1:3000检查效果,出现express Welcome to express即为成功。

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章