安装以太坊客户端Ganache: npm install -g ganache-cli (以前的名字是TestRPC)
命令行中启动ganache客户端(服务): ganache-cli -p 7545 (-p指定端口号)
也可以安装图像化界面的Ganache: https://truffleframework.com/ganache
truffle.js(truffle的配置文件,配置ganache网络。Windows下的配置文件是truffle-config.js):
module.exports = {
networks: {
ganacheNet: { // 配置ganache网络环境
host: "127.0.0.1",
port: 7545,
network_id: "*" // match any network
},
privateNet: { // 配置geth的网络环境
host: "127.0.0.1",
port: 8545,
network_id: "*" // match any network
}
}
};
命令行中: truffle migrate --network ganacheNet (部署到ganache环境中,需要启动ganache客户端)
命令行中: truffle migrate --network privateNet (部署到geth私有链环境中)
调用合约:
命令行中: truffle console --network ganacheNet (truffle连接到ganache的交互模式)
交互模式等同于truffle develop进入的开发环境,调用合约与开发环境下一样。
(Math是部署的合约名)
geth是go版本客户端,是⽬前主流的链接以太坊⽹络的客户端。 https://geth.ethereum.org/downloads/
geth的学习笔记: https://pan.baidu.com/s/1yV-NeI4cHcU7DXGGlNqilA 密码:6paj