无法使用geth

时间:2017-06-27 12:56:34

标签: ethereum invocation contracts

我使用了Greeter合同并对其进行了编译,生成web3部署代码如下:

var _greeting = "This is a contract" ;
var ballot_sol_greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"type":"constructor"}]);
var ballot_sol_greeter = ballot_sol_greeterContract.new(
    _greeting,
    {
 from: web3.eth.accounts[0], 
 data: '0x6060604052341561000c57fe5b6040516103ac3803806103ac833981016040528080518201919050505b5b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b806001908051906020019061008292919061008a565b505b5061012f565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100cb57805160ff19168380011785556100f9565b828001600101855582156100f9579182015b828111156100f85782518255916020019190600101906100dd565b5b509050610106919061010a565b5090565b61012c91905b80821115610128576000816000905550600101610110565b5090565b90565b61026e8061013e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b514610046578063cfae321714610058575bfe5b341561004e57fe5b6100566100f1565b005b341561006057fe5b610068610185565b60405180806020018281038252838181518152602001915080519060200190808383600083146100b7575b8051825260208311156100b757602082019150602081019050602083039250610093565b505050905090810190601f1680156100e35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561018257600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b61018d61022e565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102235780601f106101f857610100808354040283529160200191610223565b820191906000526020600020905b81548152906001019060200180831161020657829003601f168201915b505050505090505b90565b6020604051908101604052806000815250905600a165627a7a72305820c1f3ef4f75f67078057f269b87485e55352081a112b0c1d16d369e9ec82a99b30029', 
 gas: '4700000'
    }, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
     console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})

我创建了一个javascript文件,并尝试使用loadScript()加载文件,它显示为true,然后我挖掘生成十六进制地址。

然后我停止了矿工并使用greeter.greet()调用了合同。它显示了

ReferenceError: 'greeter' is not defined
at <anonymous>:1:1

并执行

eth.getCode(greeter.address)
ReferenceError: 'greeter' is not defined
at <anonymous>:1:13

我使用在线可靠性编译器 和geth v1.6.6。稳定版

1 个答案:

答案 0 :(得分:0)

contract mortal {
  /* Define variable owner of the type address*/
  address owner;

  /* this function is executed at initialization and sets the owner of the     contract */
  function mortal() { owner = msg.sender; }

  /* Function to recover the funds on the contract */
 function kill() { if (msg.sender == owner) suicide(owner); }
}

contract greeter is mortal {
 /* define variable greeting of the type string */
 string greeting;

 /* this runs when the contract is executed */
 function greeter(string _greeting) public {
    greeting = _greeting;
 }

 /* main function */
 function greet() constant returns (string) {
    return greeting;
  }
 }

同时部署代码:

 >loadScript("firstContract.js")
  INFO [06-27|19:48:01] Submitted contract creation             
 fullhash=0x1037088a27d9cacf9ced417381489ba58658c09e4377ec1f66a9bc24c1f29269 
 contract=0x2c7e7791dfe505c4f3d456d762990558d4cbe171
 null [object Object]
 true