Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blockchain 无法将HelloWorld协定部署到我的网络(testrpc)_Blockchain_Ethereum_Solidity_Truffle - Fatal编程技术网

Blockchain 无法将HelloWorld协定部署到我的网络(testrpc)

Blockchain 无法将HelloWorld协定部署到我的网络(testrpc),blockchain,ethereum,solidity,truffle,Blockchain,Ethereum,Solidity,Truffle,请原谅我的基本问题,巴德,我还需要什么来部署我的合同 我的简单Hello World合同定义如下 HelloWorld.sol: pragma solidity ^0.4.17; contract HelloWorld{ function sayHello() internal pure returns(string){ return("Hello 2018!"); } } Initial migrations.js: var Migrations = a

请原谅我的基本问题,巴德,我还需要什么来部署我的合同

我的简单Hello World合同定义如下 HelloWorld.sol:

pragma solidity ^0.4.17;

contract HelloWorld{  
    function sayHello() internal pure returns(string){
        return("Hello 2018!");
    }
}
Initial 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 compile
truffle migrate
然后转到控制台:

   truffle console
我使用js:

var hw
HelloWorld.deployed().then(function(deployed){hw=deployed;});
我明白了

错误:HelloWorld尚未部署到检测到的网络 (网络/工件不匹配) 位于C:\Users\Kofola\AppData\Roaming\npm\node\u modules\truffle\build\cli.bundled.js:317116:17 在 在进程中。_tickDomainCallback(internal/process/next_tick.js:228:7)

如何正确部署合同并测试其方法?

我还应该补充一点,我的testrpc服务器运行在8545,一切似乎都正常。(所有这些都在本地主机上运行) 我试图指定网络的id,我显式地设置了id并在truffle.js中指定,但仍然不起作用。我还试图改变函数的可见性

编辑“块菌命令的输出”:

合同详情:

控制台输出跟踪到所需结果:

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)>
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld>truffle compile
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld>truffle迁移
使用网络“开发”。
网络是最新的。
PS C:\Users\Kofola\BlockChain\Ethereum HelloWorld>truffle控制台
块菌(开发)>var hw
未定义
truffle(development)>HelloWorld.deployed().then(函数(deployed){hw=deployed;});
未定义
块菌(开发)>hw.sayHello.call()
''
块菌(开发)>hw.SayHello.call()
TypeError:无法读取未定义的属性“call”

在evalmachine上。

您的
truffle migrate
命令显示未部署任何内容。您的输出应该如下所示:

有些事情可以尝试:

  • Truffle在Windows 10上运行时存在一个小问题,
    Truffle.js
    与主
    Truffle
    命令的名称冲突。您需要将
    truffle.js
    重命名为
    truffle config.js
    请参阅
  • 清除所有以前的生成/迁移。删除
    build
    目录并运行
    truffle migrate--reset
  • 如果前两个不起作用,请重新启动
    testrpc
    ,清除本地区块链上以前的任何迁移。然后重新运行
    truffle migrate

  • 您可以添加来自truffle
    compile
    migrate
    命令的输出吗?还有,你在什么操作系统上运行这个?通常,您希望将部署放在2_deploy_contracts.js中,而不是1_initial_migrations.js中,但我认为这不是您的问题。@Adam Kipnis我在Win10 Home 64位上运行。这个项目是用命令truffle init初始化/创建的,警告输出也不相关,现在显示这些只是因为我编辑了可见性。我的问题中的代码没有警告,但仍然是相同的错误。好吧,发生了一些事情,一旦我运行了你的命令--reset,它说编译。。。。等然后我进入testrpc服务器,按下ctrl+c(我想退出),在控制台中看到执行开始继续,我看到了您期望的输出,部署helloworld。。。等现在,当我调用该方法时,返回的是“”,而不是“Hello 2018”。在测试rpc控制台上,当我调用方法sayHello时,我看到eth_调用。我们正朝着正确的方向前进:D BUD尚未到达:D您是否将可见性从
    内部
    更改回
    公共
    ?您无法使用
    internal
    可见性从客户端调用
    sayHello()
    。我已将我的函数sayHello编辑为“函数sayHello()返回(字符串){…”另外,我的项目目录包含truffle-config.js,默认为空。我所做的是,我在其中放入了与truffle.js相同的内容,我不确定这是否有任何效果。是的。…
    truffle-config.js
    应该与
    truffle.js
    相同。这只是一个文件重命名。更改合同中的可见性之后(然后重新运行
    compile
    migrate
    ),键入
    hw
    (从更长的输出中截断)后,您应该会在控制台中看到以下输出:sayHello:{[Function]call:[Function],sendTransaction:[Function],request:[Function:bound],estimateGas:[Function]},我现在明白了。Bud仍然无法运行我的方法并打印正确的消息
    $ 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...