Solidity

無法使用 truffle 將合約部署到 rinkeby 測試網路

  • June 25, 2018

這些是我為了將我的合約部署到 rinkeby 網路而採取的步驟:

  1. 創建了一個 .rinkeby 文件夾。
  2. 從這裡下載了 rinkeby 的 genesis json
  3. 執行此命令:

geth –datadir=$HOME/.rinkeby –light init rinkeby.json 4. 執行此命令:

GETH –networkid = 4 –datadir = $ HOME / .rinkeby –syncmode =光–bootnodes = e節點://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303 discport = 30304 –rpc –rpcapi分貝,ETH,淨,web3,個人 –rpcport 8545 –rpcaddr 127.0.0.1 –rpccorsdomain “*” 5. 將 geth 連接到網路後,我使用帶有以下程式碼和命令的 truffle 來部署合約:

程式碼:

module.exports = {
 networks: {
   rinkeby: {
     network_id: 4,
     host: '127.0.0.1',
     port: 8545,
     gas: 4000000
   },
 },
 rpc: {
   // Use the default host and port when not using rinkeby
   host: 'localhost',
   port: 8080,
 },
};

命令:

truffle compile; truffle migrate --network rinkeby

這是我得到的錯誤:

Using network 'rinkeby'.

/usr/lib/node_modules/truffle/build/cli.bundled.js:23538
       throw new Error("Expected parameter '" + key + "' not passed to function.");
       ^

Error: Expected parameter 'from' not passed to function.
   at /usr/lib/node_modules/truffle/build/cli.bundled.js:23538:15
   at Array.forEach (native)
   at Object.options (/usr/lib/node_modules/truffle/build/cli.bundled.js:23536:19)
   at Object.run (/usr/lib/node_modules/truffle/build/cli.bundled.js:66868:12)
   at /usr/lib/node_modules/truffle/build/cli.bundled.js:88946:23
   at /usr/lib/node_modules/truffle/build/cli.bundled.js:67033:9
   at /usr/lib/node_modules/truffle/build/cli.bundled.js:66861:7
   at done (/usr/lib/node_modules/truffle/build/cli.bundled.js:155469:5)
   at /usr/lib/node_modules/truffle/build/cli.bundled.js:155526:11
   at FSReqWrap.oncomplete (fs.js:153:5)

我遵循的過程中有什麼不正確的?我不明白為什麼會出現這個錯誤以及如何刪除它。

問題出在 truffle.js 文件中。

module.exports = {
 networks: {
   rinkeby: {
     network_id: 4,
     host: '127.0.0.1',
     port: 8545,
     gas: 4000000,
     from: <your account address>
   },
 },
 rpc: {
   // Use the default host and port when not using rinkeby
   host: 'localhost',
   port: 8080,
 },
};

只需要在from: <account address>rinkeby 的配置資訊中添加一個。

我在 truffle 配置方面遇到了相當大的困難。我已經使用 ethers.js 製作了用於部署的小庫。希望這對將來的某人有所幫助:

const etherlime = require('etherlime');

const ICOTokenContract = require('./build/contracts/ICOToken.json');

const randomAddress = '0xda8a06f1c910cab18ad187be1faa2b8606c2ec86';

const defaultConfigs = {
   gasPrice: 20000000000,
   gasLimit: 4700000
}

const deployer = new etherlime.InfuraPrivateKeyDeployer('Your Privste KEY', 'ropsten', 'Your infura API key', defaultConfigs);

const runICODeployment = async () => {
   const contractWrapper = await deployer.deploy(ICOTokenContract);
   const transferTransaction = await contractWrapper.contract.transferOwnership(randomAddress);
   const result = await contractWrapper.verboseWaitForTransaction(transferTransaction.hash, 'Transfer Ownership');
}
runICODeployment()

將它放在一個 js 文件中並通過節點執行它

引用自:https://ethereum.stackexchange.com/questions/24215