Solidity
將合約部署到 rinkbey 沒有任何作用
我一直在嘗試將我的契約部署到 Rinkbey,但似乎什麼也沒發生。
我之前已經在本地將合約部署到 ganache RPC 並使用
truffle migrate
它工作正常,我能夠毫無問題地呼叫已部署合約的方法。之後,我在 truffle.js 中添加了以下幾行
rinkeby: { host: "127.0.0.1", // Connect to geth on the specified port: 8545, from: "xxxxxxxxxxxxxxxx", // find it from geth console by typing `eth.accounts` use the first one network_id: 4, gas: 5000000 }
所以它變成了
module.exports = { // See <http://truffleframework.com/docs/advanced/configuration> // to customize your Truffle configuration! networks: { development: { host: "127.0.0.1", port: 8545, network_id: "*" }, rinkeby: { host: "127.0.0.1", // Connect to geth on the specified port: 8545, from: "xxxxxxxxxxxx", // find it from geth console by typing `eth.accounts` use the first one network_id: 4, gas: 5000000 // Gas limit } } };
我
migrations/1_initial_migration.js
的如下:var Migrations = artifacts.require("./Migrations.sol"); module.exports = function(deployer) { deployer.deploy(Migrations); };
如下
contracts/Migrations.sol
:pragma solidity ^0.4.17; contract Migrations { address public owner; uint public last_completed_migration; modifier restricted() { if (msg.sender == owner) _; } function Migrations() public { owner = msg.sender; } function setCompleted(uint completed) public restricted { last_completed_migration = completed; } function upgrade(address new_address) public restricted { Migrations upgraded = Migrations(new_address); upgraded.setCompleted(last_completed_migration); } }
之後,我停止本地執行
geth
並執行以下命令來解鎖帳戶以準備將契約部署到 rinkbey
geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --unlock="xxxxxxxxxxxxxxxx"
然後在不同的終端視窗中執行以下命令
truffle compile; truffle migrate --network rinkeby
並得到了這個輸出
Using network 'rinkeby'. Network up to date.
雖然我期待它應該顯示我完成了到 rinkbey 和契約地址的遷移,但它只是一直說
Network is up to date
。即使我編輯了我的契約,也有點思考,這可能會引發新的遷移。但這並沒有幫助。知道我在這裡做錯了什麼嗎?更新:我在某處讀過,我需要刪除該
build
文件夾,所以我做到了。然後跑truffle compile; truffle migrate --network rinkeby
了,這次得到了以下結果:Compiling ./contracts/Migrations.sol... Compiling ./contracts/addition.sol... Writing artifacts to ./build/contracts Using network 'rinkeby'. Network up to date.
還是看不到已部署的合約地址?
創建一個名為 2_deploy_contracts.js 的新文件,該文件將在初始遷移後自動呼叫
1_initial_migration.js 只會更新已經部署的遷移合約
var myContract = artifacts.require("MyContract"); module.exports = function(deployer) { deployer.deploy(myContract); };