5 truffle如何部署到远程私有链

我在本地使用truffle建了一个项目,我想把上面的合约部署到以太坊上 这是我的配置文件

development: {
      host: "115.159.21.194",     // Localhost (default: none)
      port: 7545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
    },

这是我的部署脚本

var Note = artifacts.require("./noteContract.sol");
var web3 = new Web3(new Web3.providers.HttpProvider('http://115.159.21.194:7545'));
module.exports = function (deployer) {
  deployer.deploy(Note, {from:web3.eth.accounts[0]});
};

这是我的geth启动命令

geth --rpc --rpcport "7545" --rpcaddr "0.0.0.0" --rpccorsdomain="*" --rpcapi eth,web3,admin,personal,net --datadir data --port "30303" --nodiscover --networkid 1024 --allow-insecure-unlock console 2>>geth.log  

这是出错原因

PS C:\Users\Administrator\Desktop\项目\wallet> truffle migrate
Could not connect to your Ethereum client. Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle.js)

请问哪里有问题。。。

请先 登录 后评论

最佳答案 2020-02-10 20:46

解决了。原来不是在部署文件写,是在配置文件引入钱包

配置文件核心部分

var HDWalletProvider = require("truffle-hdwallet-provider");  // 导入模块
var mnemonic = "medal luxury .....  ..... ... danger faculty spy";  //MetaMask的助记词。

development: {
      host: "115.159.21.194",     // Localhost (default: none)
      port: 7545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
      provider: function () {
        // mnemonic表示MetaMask的助记词。 "ropsten.infura.io/v3/33..."表示Infura上的项目id
        return new HDWalletProvider(mnemonic, "http://115.159.21.194:7545", 0);   // 1表示第二个账户(从0开始)
      }
    },
请先 登录 后评论

其它 1 个回答

Tiny熊 - 布道者
  擅长:智能合约,以太坊
请先 登录 后评论