Solidity
松露遷移不執行 2_deploy_contracts.js
我
truffle migrate
在預設 Truffle 項目和使用 Infura 作為提供程序時遇到問題。重現問題的步驟
truffle init
npm install ethereumjs-wallet bip39 web3-provider-engine@8.6.1 web3@0.18.4 zeppelin-solidity --save
- 編輯
truffle.js
以使用確定性錢包和 infura 提供程序。(程式碼如下)truffle compile
truffle migrate --network rinkeby
但是,執行
truffle migrate --network rinkeby
只會進行部分遷移。它不會繼續遷移2_deploy_contracts.js
。$ truffle migrate --network rinkeby Running migration: 1_initial_migration.js Deploying Migrations... ... 0xf7a1eea43cfe61d59f55a3f5ce8b1c33bc9d5b37c2486ebdc83fdf4d1ba03041 $
任何人都知道可能是什麼問題?
使用:
- 松露 v3.4.9(核心:3.4.8)
- Solidity v0.4.15 (solc-js)
松露.js
var bip39 = require("bip39"); var hdkey = require('ethereumjs-wallet/hdkey'); var ProviderEngine = require("web3-provider-engine"); var WalletSubprovider = require('web3-provider-engine/subproviders/wallet.js'); var Web3Subprovider = require("web3-provider-engine/subproviders/web3.js"); var Web3 = require("web3"); // Get our mnemonic and create an hdwallet var mnemonic = "couch solve unique spirit wine fine occur rhythm foot feature glory away"; var hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic)); // Get the first account using the standard hd path. var wallet_hdpath = "m/44'/60'/0'/0/"; var wallet = hdwallet.derivePath(wallet_hdpath + "0").getWallet(); var address = "0x" + wallet.getAddress().toString("hex"); var providerUrl = "https://rinkeby.infura.io/somekey"; var engine = new ProviderEngine(); engine.addProvider(new WalletSubprovider(wallet, {})); engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(providerUrl))); engine.start(); // Required by the provider engine. module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*" // Match any network id }, rinkeby: { network_id: 4, provider: engine, from: address } } };
這是輸出
truffle migrate --network rinkeby --verbose-rpc
Using network 'rinkeby'. Running migration: 1_initial_migration.js .> { .> "jsonrpc": "2.0", .> "id": 1, .> "method": "eth_accounts", .> "params": [] .> } .< { .< "id": 1, .< "jsonrpc": "2.0", .< "result": [ .< "0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6" .< ] .< } .> { .> "jsonrpc": "2.0", .> "id": 2, .> "method": "net_version", .> "params": [] .> } .< { .< "id": 2, .< "jsonrpc": "2.0", .< "result": "4" .< } Deploying Migrations... .> { .> "jsonrpc": "2.0", .> "id": 3, .> "method": "net_version", .> "params": [] .> } .< { .< "id": 3, .< "jsonrpc": "2.0", .< "result": "4" .< } .> { .> "jsonrpc": "2.0", .> "id": 4, .> "method": "eth_sendTransaction", .> "params": [ .> { .> "from": "0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6", .> "gas": "0x47e7c4", .> "gasPrice": "0x174876e800", .> "data": "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101e58061003c6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630900f010811461005e578063445df0ac1461007f5780638da5cb5b146100a4578063fdacd576146100d3575b600080fd5b341561006957600080fd5b61007d600160a060020a03600435166100eb565b005b341561008a57600080fd5b610092610182565b60405190815260200160405180910390f35b34156100af57600080fd5b6100b7610188565b604051600160a060020a03909116815260200160405180910390f35b34156100de57600080fd5b61007d600435610197565b005b6000805433600160a060020a039081169116141561017c5781905080600160a060020a031663fdacd5766001546040517c010000000000000000000000000000000000000000000000000000000063ffffffff84160281526004810191909152602401600060405180830381600087803b151561016757600080fd5b6102c65a03f1151561017857600080fd5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a03908116911614156101b45760018190555b5b5b505600a165627a7a723058205f879dec75723925844d4fd706c85432c3686fa32c9ccf4e7a6ca2b8bb0307380029" .> } .> ] .> } .> { .> "id": 1507552744042366, .> "jsonrpc": "2.0", .> "params": [ .> "0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6", .> "pending" .> ], .> "method": "eth_getTransactionCount" .> } .< { .< "id": 1507552744042366, .< "jsonrpc": "2.0", .< "result": "0x13" .< } .> { .> "id": 1507552744515044, .> "jsonrpc": "2.0", .> "params": [ .> "0xf902741385174876e8008347e7c48080b902216060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101e58061003c6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630900f010811461005e578063445df0ac1461007f5780638da5cb5b146100a4578063fdacd576146100d3575b600080fd5b341561006957600080fd5b61007d600160a060020a03600435166100eb565b005b341561008a57600080fd5b610092610182565b60405190815260200160405180910390f35b34156100af57600080fd5b6100b7610188565b604051600160a060020a03909116815260200160405180910390f35b34156100de57600080fd5b61007d600435610197565b005b6000805433600160a060020a039081169116141561017c5781905080600160a060020a031663fdacd5766001546040517c010000000000000000000000000000000000000000000000000000000063ffffffff84160281526004810191909152602401600060405180830381600087803b151561016757600080fd5b6102c65a03f1151561017857600080fd5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a03908116911614156101b45760018190555b5b5b505600a165627a7a723058205f879dec75723925844d4fd706c85432c3686fa32c9ccf4e7a6ca2b8bb03073800291ba0b65823e784f3eccb6aee7f2832d6780df2d345052fc59b18a5fc0b695d5e59b3a06c6dccd25ca9f120883ba6ffec3a7a22bc38a06fa50e71159ee00e1990fbfc7f" .> ], .> "method": "eth_sendRawTransaction" .> } .< { .< "id": 1507552744515044, .< "jsonrpc": "2.0", .< "result": "0xf2b4e82e4a806ad1adcd8ff4e6d5cad05ee99302a2265810e3de04fd3a652c33" .< } .< { .< "id": 4, .< "jsonrpc": "2.0", .< "result": "0xf2b4e82e4a806ad1adcd8ff4e6d5cad05ee99302a2265810e3de04fd3a652c33" .< } ... 0xf2b4e82e4a806ad1adcd8ff4e6d5cad05ee99302a2265810e3de04fd3a652c33 .> { .> "jsonrpc": "2.0", .> "id": 5, .> "method": "eth_newBlockFilter", .> "params": [] .> }
更新:您可以替換 Infura / Truffle 教程提供的程式碼如下,它非常短且更易於閱讀/修改。
您可以為下面的兩行更改上面的所有程式碼,以使其更容易。
var HDWalletProvider = require("truffle-hdwallet-provider"); var mnemonic = "word1 word2 word3 etc";
安裝 truffle-hdwallet-provider 包。
$ npm install truffle-hdwallet-provider
然後:
module.exports = { networks: { development: { host: 'localhost', port: 8545, network_id: '*' // Match any network id }, ropsten: { provider: new HDWalletProvider(mnemonic, "https://ropsten.infura.io/wefbowufweufbweu"), // The actual api key infura gave you network_id: '3' } } }
此範例使用 Ropsten,但將其更改為 Rinkeby 應該很簡單,只需確保您使用 Infura 給您的 url 以及正確的 api 密鑰和 network_id 4 而不是 3