我正在阅读“Dummies的”一书,并创建了一个契约HelloWorld,部署到块链中,直到我尝试调用合同的功能为止,这一切都很好。
我的合同代码:
//SPDX-License-Identifier: MIT-License
pragma solidity ^0.8.16;
contract HelloWorld {
string private helloMessage = "Hello World";
function getHelloMessage() public view returns (string memory) {
return helloMessage;
}
}编译、部署和所有必要的步骤都进行得很好,尽管对代码做了一些修改,因为自从Dummies书籍发布以来,所有的软件包都被更新了很多。
使用松露控制台,输入命令
HelloWorld.deployed().then(function(instance) {return instance });我得到了想要的输出,根据这本书,它应该允许我使用以下命令调用契约上的函数:
HelloWorld.deployed().then(function(instance) {return instance.getHelloWorld() }); 答复是:
Uncaught TypeError: instance.getHelloWorld is not a function鉴于这本书有点过时,我在网上搜索,包括类似的文章在这个论坛,但我似乎找不到任何符合上述语法。由于我对所有这些都是新手,我想我对块菌不熟悉可能就是为什么我不知道如何解决这个问题。我会非常感激任何人谁能指出我的正确方向。
我的开发设置如下:块菌v5.5.25 (核心: 5.5.25) Ganache v7.4.0 Solidity v0.5.16 (solc-js) Node v18.7.0 Web3.js v1.7.4
发布于 2022-08-14 17:09:33
在契约中,函数名为getHelloMessage,但您正在调用getHelloWorld。
您应该键入控制台。
HelloWorld.deployed().then(function(instance) {return instance.getHelloMessage() }) https://ethereum.stackexchange.com/questions/133377
复制相似问题