2017-12-31 271 views
1

私の基本的な質問を赦してください。私の契約を展開するために他に何が必要ですか?私のネットワーク(testrpc)にHelloWorld契約を展開できません

私は HelloWorld.sol次のように定義され、単純なHello Worldの契約を持っている:

pragma solidity ^0.4.17; 

contract HelloWorld{ 
    function sayHello() internal pure returns(string){ 
     return("Hello 2018!"); 
    } 
} 

初期migrations.js:トリュフを使用してイム以来

var Migrations = artifacts.require("./Migrations.sol"); 
var HelloWorld = artifacts.require("./HelloWorld.sol"); 

module.exports = function(deployer) { 
    deployer.deploy(Migrations); 
    deployer.deploy(HelloWorld); 
}; 

そして最後に、truffle.jsを:

module.exports = { 

    networks: { 
    development: { 
     host: "localhost", 
     port: 8545, 
     network_id: "*" // Match any network id 
    } 
    } 

}; 

私は、コマンドを実行します。

truffle console 

と私はJSを使用します:

truffle compile 
truffle migrate 

次にコンソールに移動

var hw 
HelloWorld.deployed().then(function(deployed){hw=deployed;}); 

私はどのように私が正しく展開ん

Error: HelloWorld has not been deployed to detected network (network/artifact mismatch) at C:\Users\Kofola\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:317116:17 at at process._tickDomainCallback (internal/process/next_tick.js:228:7)

を取得します私の契約とテストエトド?

また、私のtestrpcサーバーが8545で動作していて、すべてが正常であるようです。 (これはすべてlocalhost上で実行されています) 私はネットワークのIDを指定しようとしました。私は明示的にidを設定し、truffle.jsで指定しても動作しません。私はまた、機能の可視性を変更しようとしました。

編集 "トリュフコマンドの出力": enter image description here

契約の詳細: enter image description here

コンソール出力トレイル望ましい結果へ:

PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle compile 
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle migrate 
Using network 'development'. 

Network up to date. 
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle console 
truffle(development)> var hw 
undefined 
truffle(development)> HelloWorld.deployed().then(function(deployed){hw=deployed;}); 
undefined 
truffle(development)> hw.sayHello.call() 
'' 
truffle(development)> hw.SayHello.call() 
TypeError: Cannot read property 'call' of undefined 
    at evalmachine.<anonymous>:1:13 
    at ContextifyScript.Script.runInContext (vm.js:59:29) 
    at Object.runInContext (vm.js:120:6) 
    at Console.interpret (C:\Users\Kofola\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:202629:17) 
    at ReplManager.interpret (C:\Users\Kofola\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:203345:18) 
    at bound (domain.js:301:14) 
    at REPLServer.runBound [as eval] (domain.js:314:12) 
    at REPLServer.onLine (repl.js:441:10) 
    at emitOne (events.js:116:13) 
    at REPLServer.emit (events.js:211:7) 
truffle(development)> hw.sayHello.call() 
'' 
truffle(development)> .exit 
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle migrate --reset 
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) 

PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle compile 
Compiling .\contracts\HelloWorld.sol... 
Compiling .\contracts\Migrations.sol... 

Compilation warnings encountered: 

/C/Users/Kofola/BlockChain/EthereumHelloWorld/contracts/HelloWorld.sol:5:5: Warning: No visibility specified. Defaulting to "public". 
    function sayHello() returns(string){ 
    ^
Spanning multiple lines. 
,/C/Users/Kofola/BlockChain/EthereumHelloWorld/contracts/HelloWorld.sol:5:5: Warning: Function state mutability can be restricted to pure 
    function sayHello() returns(string){ 
    ^
Spanning multiple lines. 

Writing artifacts to .\build\contracts 

PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle migrate --reset 
Using network 'development'. 

Running migration: 1_initial_migration.js 
    Deploying Migrations... 
    ... 0x1ed08bc4bcbb9db244acd9edfe4cfc71ca1675d069e4f17dcb5780f1ae496da0 
    Migrations: 0x2bcb6d8aade2239b14c17374d631be59c2847175 
    Deploying HelloWorld... 
    ... 0x0195732cdb2a7fae8896be02a86403c88fd45c5e793a0ab1de7b3fdf6a086a67 
    HelloWorld: 0xf169c021288e56a0b9739fd959fe305a7f67f500 
Saving successful migration to network... 
    ... 0xed919bb06a5a83fbf7e8bae8b99ec2f398979b51bc3f41c152ef621e1c799561 
Saving artifacts... 
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle migrate 
Using network 'development'. 

Network up to date. 
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle console 
truffle(development)> var hw = HelloWorld.at(HelloWorld.address); 
undefined 
truffle(development)> hw.address 
'0xf169c021288e56a0b9739fd959fe305a7f67f500' 
truffle(development)> hw.sayHello(); 
{ tx: '0x694a532cffb398dd316c53c6ac44adde7d8a7c00e305bcd8b39746fb3d20acdc', 
    receipt: 
    { transactionHash: '0x694a532cffb398dd316c53c6ac44adde7d8a7c00e305bcd8b39746fb3d20acdc', 
    transactionIndex: 0, 
    blockHash: '0xdfd7a8637904ec0ed282acac34e2da4929f410325f7f37744955ce5b3195cc8b', 
    blockNumber: 4, 
    gasUsed: 21934, 
    cumulativeGasUsed: 21934, 
    contractAddress: null, 
    logs: [], 
    status: 1 }, 
    logs: [] } 
truffle(development)> hw 
TruffleContract { 
    constructor: 
    { [Function: TruffleContract] 
    _static_methods: 
     { setProvider: [Function: setProvider], 
     new: [Function: new], 
     at: [Function: at], 
     deployed: [Function: deployed], 
     defaults: [Function: defaults], 
     hasNetwork: [Function: hasNetwork], 
     isDeployed: [Function: isDeployed], 
     detectNetwork: [Function: detectNetwork], 
     setNetwork: [Function: setNetwork], 
     resetAddress: [Function: resetAddress], 
     link: [Function: link], 
     clone: [Function: clone], 
     addProp: [Function: addProp], 
     toJSON: [Function: toJSON] }, 
    _properties: 
     { contract_name: [Object], 
     contractName: [Object], 
     abi: [Object], 
     network: [Function: network], 
     networks: [Function: networks], 
     address: [Object], 
     links: [Function: links], 
     events: [Function: events], 
     binary: [Function: binary], 
     deployedBinary: [Function: deployedBinary], 
     unlinked_binary: [Object], 
     bytecode: [Object], 
     deployedBytecode: [Object], 
     sourceMap: [Object], 
     deployedSourceMap: [Object], 
     source: [Object], 
     sourcePath: [Object], 
     ast: [Object], 
     compiler: [Object], 
     schema_version: [Function: schema_version], 
     schemaVersion: [Function: schemaVersion], 
     updated_at: [Function: updated_at], 
     updatedAt: [Function: updatedAt] }, 
    _property_values: {}, 
    _json: 
     { contractName: 'HelloWorld', 
     abi: [Array], 
     bytecode: '0x6060604052341561000f57600080fd5b6101578061001e6000396000f300606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063ef5fb05b14610046575b600080fd5b341561005157600080fd5b6100596100d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009957808201518184015260208101905061007e565b50505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610117565b6040805190810160405280600b81526020017f48656c6c6f203230313821000000000000000000000000000000000000000000815250905090565b6020604051908101604052806000815250905600a165627a7a723058201d959a32cbfc1f3e235a39bee940f8e7653bd7d2a041268570ed5b2453d1a9430029', 
     deployedBytecode: '0x606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063ef5fb05b14610046575b600080fd5b341561005157600080fd5b6100596100d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009957808201518184015260208101905061007e565b50505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610117565b6040805190810160405280600b81526020017f48656c6c6f203230313821000000000000000000000000000000000000000000815250905090565b6020604051908101604052806000815250905600a165627a7a723058201d959a32cbfc1f3e235a39bee940f8e7653bd7d2a041268570ed5b2453d1a9430029', 
     sourceMap: '28:114:0:-;;;;;;;;;;;;;;;;;', 
     deployedSourceMap: '28:114:0:-;;;;;;;;;;;;;;;;;;;;;;;;62:75;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;23:1:-1;8:100;33:3;30:1;27:2;8:100;;;99:1;94:3;90;84:5;80:1;75:3;71;64:6;52:2;49:1;45:3;40:15;;8:100;;;12:14;3:109;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;62:75:0;90:6;;:::i;:::-;108:21;;;;;;;;;;;;;;;;;;;;62:75;:::o;28:114::-;;;;;;;;;;;;;;;:::o', 
     source: 'pragma solidity ^0.4.17;\r\n\r\ncontract HelloWorld{ \r\n \r\n function sayHello() returns(string){\r\n  return("Hello 2018!");\r\n 
}\r\n\r\n}', 
     sourcePath: 'C:\\Users\\Kofola\\BlockChain\\EthereumHelloWorld\\contracts\\HelloWorld.sol', 
     ast: [Object], 
     compiler: [Object], 
     networks: [Object], 
     schemaVersion: '1.0.1', 
     updatedAt: '2017-12-31T19:58:12.425Z' }, 
    setProvider: [Function: bound setProvider], 
    new: [Function: bound new], 
    at: [Function: bound at], 
    deployed: [Function: bound deployed], 
    defaults: [Function: bound defaults], 
    hasNetwork: [Function: bound hasNetwork], 
    isDeployed: [Function: bound isDeployed], 
    detectNetwork: [Function: bound detectNetwork], 
    setNetwork: [Function: bound setNetwork], 
    resetAddress: [Function: bound resetAddress], 
    link: [Function: bound link], 
    clone: [Function: bound clone], 
    addProp: [Function: bound addProp], 
    toJSON: [Function: bound toJSON], 
    web3: 
     Web3 { 
     _requestManager: [Object], 
     currentProvider: [Object], 
     eth: [Object], 
     db: [Object], 
     shh: [Object], 
     net: [Object], 
     personal: [Object], 
     bzz: [Object], 
     settings: [Object], 
     version: [Object], 
     providers: [Object], 
     _extend: [Object] }, 
    class_defaults: 
     { from: '0x848375e1f2447bee3257b9afcac99af09d83f9f0', 
     gas: 6721975, 
     gasPrice: 100000000000 }, 
    currentProvider: 
     HttpProvider { 
     host: 'http://localhost:8545', 
     timeout: 0, 
     user: undefined, 
     password: undefined, 
     send: [Function], 
     sendAsync: [Function], 
     _alreadyWrapped: true }, 
    network_id: '1001' }, 
    abi: 
    [ { constant: false, 
     inputs: [], 
     name: 'sayHello', 
     outputs: [Array], 
     payable: false, 
     stateMutability: 'nonpayable', 
     type: 'function' } ], 
    contract: 
    Contract { 
    _eth: 
     Eth { 
     _requestManager: [Object], 
     getBalance: [Object], 
     getStorageAt: [Object], 
     getCode: [Object], 
     getBlock: [Object], 
     getUncle: [Object], 
     getCompilers: [Object], 
     getBlockTransactionCount: [Object], 
     getBlockUncleCount: [Object], 
     getTransaction: [Object], 
     getTransactionFromBlock: [Object], 
     getTransactionReceipt: [Object], 
     getTransactionCount: [Object], 
     call: [Object], 
     estimateGas: [Object], 
     sendRawTransaction: [Object], 
     signTransaction: [Object], 
     sendTransaction: [Object], 
     sign: [Object], 
     compile: [Object], 
     submitWork: [Object], 
     getWork: [Object], 
     coinbase: [Getter], 
     getCoinbase: [Object], 
     mining: [Getter], 
     getMining: [Object], 
     hashrate: [Getter], 
     getHashrate: [Object], 
     syncing: [Getter], 
     getSyncing: [Object], 
     gasPrice: [Getter], 
     getGasPrice: [Object], 
     accounts: [Getter], 
     getAccounts: [Object], 
     blockNumber: [Getter], 
     getBlockNumber: [Object], 
     protocolVersion: [Getter], 
     getProtocolVersion: [Object], 
     iban: [Object], 
     sendIBANTransaction: [Function: bound transfer] }, 
    transactionHash: null, 
    address: '0xf169c021288e56a0b9739fd959fe305a7f67f500', 
    abi: [ [Object] ], 
    sayHello: 
     { [Function: bound ] 
     request: [Function: bound ], 
     call: [Function: bound ], 
     sendTransaction: [Function: bound ], 
     estimateGas: [Function: bound ], 
     getData: [Function: bound ], 
     '': [Circular] }, 
    allEvents: [Function: bound ] }, 
    sayHello: 
    { [Function] 
    call: [Function], 
    sendTransaction: [Function], 
    request: [Function: bound ], 
    estimateGas: [Function] }, 
    sendTransaction: [Function], 
    send: [Function], 
    allEvents: [Function: bound ], 
    address: '0xf169c021288e56a0b9739fd959fe305a7f67f500', 
    transactionHash: null } 
truffle(development)> 
(To exit, press ^C again or type .exit) 
truffle(development)> hw.sayHello.call() 
'Hello 2018!' 
truffle(development)> 

ソリューション:それらが必要になる場合があります同じ問題READ COMMENTSインフォメーション

それを実行するためのコマンドで、コード作業:https://github.com/TomasBisciak/EthereumHelloWorldExample

+0

トリュフルの 'compile'コマンドと' migrate'コマンドの出力を追加できますか?また、どのOSでこれを実行していますか?通常は、1_initial_migrations.jsではなく、2_deploy_contracts.jsにデプロイメントを配置する必要がありますが、ここではそれが問題ではないと思います。 –

+0

@Adam Kipnis ImがWin10 Home 64bitで動作しています。このプロジェクトは、初期化された/コマンドトリュフinitで作成された、警告出力も関連していません、これらは現在表示されているだけで私は可視性を編集した原因が表示されます。 –

答えて

2

あなたtruffle migrateコマンドが表示されて何も展開されませんでした。

$ truffle migrate 
Using network 'development'. 

Running migration: 1_initial_migration.js 
    Deploying Migrations... 
    ... 0x92408ab65d6fb64dedcf1e3aaa99854cc5fc3eb3e15687e04df86d357cdf22d8 
    Migrations: 0xbaae4238d6818704f09c253d4c7bc57a3585623a 
    Deploying HelloWorld... 
    ... 0x47d7237c07e819f28dd7e154cfef67fa6b854cc963b6562abe1861cbdb85c222 
    HelloWorld: 0x0a926a36ec5bf177c7724d0d1a85aa15e965916c 
Saving successful migration to network... 
    ... 0x548eab4802922e75dedfbb63ce158c4863bddcc5e6fc14f0396f109be13d8794 
Saving artifacts... 
Running migration: 2_deploy_contracts.js 
Saving successful migration to network... 
    ... 0x308b6e327d3cbc901cd49d380f56d30eb422efc3232d54115a2ef025dfc68f0c 
Saving artifacts... 

しようとするいくつかのもの:あなたの出力は次のようになります。

  1. トリュフはtruffle.jsがメインtruffleコマンドを使用して、名前の競合を持つWindows 10上で実行されているマイナーな問題があります。 truffle.jsからtruffle-config.jsに名前を変更する場合は、thisを参照してください。
  2. 以前のすべてのビルド/移行をクリアします。 buildディレクトリを削除し、truffle migrate --resetを実行します。
  3. 前の2が機能しない場合は、testrpcを再起動して、ローカルブロックチェーンの以前の移行をすべてクリアします。次に再実行truffle migrate
+0

さて、私はあなたのコマンドを実行すると、何かが起こった - リセット、それはコンパイル.... etc ...そしてそれはつまらなかった。その後、私はtestrpcサーバーに入った、Ctrl + Cを押した(私は外出したい)そしてその瞬間、私は実行が継続し始めたと私はあなたが期待した出力を見てhelloworld ...などを展開していることを見た...芽今私はメソッドを呼び出すとき、私は 'Hello 2018' 。テストのrpcコンソールでsayHelloメソッドを呼び出すと、eth_callが表示されます。私たちは正しい方向に進んでいます:D BUDはまだありません:D –

+0

可視性を 'internal'から' public'に戻しましたか? 'sayHello()'を 'internal'可視性を持つクライアントから呼び出すことはできません。 –

+0

私の関数sayHelloを編集して "function sayHello()returns(string){..."。また、私のプロジェクトディレクトリにtruffle-config.jsが入っています。私がしたことは、私がtruffle.jsに持っていたのと同じ内容をそれに入れたことです。何の効果もあったかどうかわかりません。 –

関連する問題