生生不息

生生不息

truffle migrate --rest报错解决

2025-06-20
truffle migrate --rest报错解决

背景

本地部署truffle合约报错连接不到当地端口

Something went wrong while attempting to connect to the network at http://localhost:7545. Check your network configuration

解决方案

  1. 修改ganache端口7545修改为8545

修改truffle-config.js中端口为8545

再试试

不行就尝试第2种

  1. 修改localhost
    修改truffle-config.js中本地网址localhost为127.0.0.1
module.exports = {
  networks: {
    development: {
      host: "127.0.0.1", // 原来是localhost
      port: 7545,
      network_id: "*" 
    }
  },

  compilers: {
    solc: {
       version: "0.5.8"
    }
  }
};

笔者是第二种方案成功的,对于localhost类问题,都可以尝试更改,本质一样,但不同程序可能判定不同。