风情小皮球 2019-07-17 09:45 采纳率: 0%
浏览 409
已采纳

部署智能合约var显示未定义,但是最后调用成功!

E:\blockchain>geth --dev --dev.period 1 console 2>> geth-log
......

personal.unlockAccount(acc1,"ju")
true
> var _greeting = "Hello, Joyce" ;
undefined
> var helloContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"say","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
undefined
> var hello = helloContract.new(
...    _greeting,
...    {
......      from: web3.eth.accounts[1],
......      data: '0x608060405234801561001057600080fd5b506040516102a83803806102a8833981018060405281019080805182019291905050508060009080519060200190610049929190610050565b50506100f5565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009157805160ff19168380011785556100bf565b828001600101855582156100bf579182015b828111156100be5782518255916020019190600101906100a3565b5b5090506100cc91906100d0565b5090565b6100f291905b808211156100ee5760008160009055506001016100d6565b5090565b90565b6101a4806101046000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063954ab4b214610046575b600080fd5b34801561005257600080fd5b5061005b6100d6565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009b578082015181840152602081019050610080565b50505050905090810190601f1680156100c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561016e5780601f106101435761010080835404028352916020019161016e565b820191906000526020600020905b81548152906001019060200180831161015157829003601f168201915b50505050509050905600a165627a7a72305820a7ef9308b4f91e2cbcb6bc84b3196736625ae7e0b242863d77c56dd80fc1e6480029',
......      gas: '4700000'
......    }, function (e, contract){
......     console.log(e, contract);
......     if (typeof contract.address !== 'undefined') {
.........          console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
.........     }
......  })
null [object Object]
undefined
> null [object Object]
Contract mined! address: 0xb926d47fb92892d6eb108c83858d5f1a1fb9bb57 transactionHash: 0xda2420c100021809640c808c1f7aaa1ceba410c27bcd76edddba83e5d05a049a

这些代码var都是未定义,但是查看hello又是对的

 hello
{
  abi: [{
      constant: true,
      inputs: [],
      name: "say",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }, {
      inputs: [{...}],
      payable: false,
      stateMutability: "nonpayable",
      type: "constructor"
  }],
  address: "0xb926d47fb92892d6eb108c83858d5f1a1fb9bb57",
  transactionHash: "0xda2420c100021809640c808c1f7aaa1ceba410c27bcd76edddba83e5d05a049a",
  allEvents: function(),
  say: function()
}
> hello.say()
"Hello, Joyce"

为什么会出现未定义啊?

  • 写回答

1条回答 默认 最新

  • asnissj 2019-07-17 10:25
    关注

    因为var _greeting = "Hello, Joyce" ; 这不是数据类型,所以返回undefined,但是 _greeting 这个变量已经定义成功了,所以_greeting是能取到值的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算