简体   繁体   English

Remix solidity 不会在私有以太坊链上返回结果

[英]Remix solidity does not return result on private ethereum chain

I have just started learning ethereum and remix, and this question might seem stupid to you.我刚开始学习以太坊和混音,这个问题对你来说可能很愚蠢。

I tried following codes on javascript vm embedded inside remix ide, and it works totally fine, but it fails to return the string on a private chain I set up early, even though it does not report any errors.我在嵌入在 remix ide 中的 javascript vm 上尝试了以下代码,它工作得很好,但它无法在我早期设置的私有链上返回字符串,即使它没有报告任何错误。 The solidity code I'm using is as follows.我使用的solidity代码如下。

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
contract Greeter {

    function greet() external pure returns(string memory) {
        return "Hello, World!";
    }

}

Can anybody provide some idea where I might go wrong?任何人都可以提供一些想法我可能会出错吗? PS I have set miner.start() , and use following script to start the private chain: PS 我设置miner.start() ,并使用以下脚本启动私有链:

geth --datadir data --networkid 18810100026 --port 60000 --rpc  --rpcport 8100 --rpcaddr 0.0.0.0 --bootnodes enode://****73c2e56ed109f7ab559bc0df26e01e4a72c4eef660d0853e8c241a737b43bd7f7da32d22e272fe187f7063d9559691@****:30301 --rpcapi eth,web3,miner,admin,personal,net --rpccorsdomain "*"```

geth version is 1.7.3

screenshot of contract running on private chain私链上运行的合约截图

screenshot of contract running on javascript VM在 javascript VM 上运行的合约截图

I think there were two fact that might lead to such an error我认为有两个事实可能导致这样的错误

  1. I did not update the geth to the current latest version.我没有将geth更新到当前的最新版本。
  2. I did not initialize the genesis block correctly.我没有正确初始化创世区块。

So I made two modifications to solve such a problem所以我做了两个修改来解决这样的问题

  1. Update the geth to 1.10.17geth更新到 1.10.17
  2. add two lines to the genesis json file automatically generated by puppeth , which are as followspuppeth自动生成的 genesis json 文件中添加两行,如下
{
  "config": {
    ...
    "byzantiumBlock": 4,
    "constantinopleBlock": 5,
    ...
  },
...

The problem was solved thereafter.之后问题就解决了。

i think your contract is ok!我觉得你的合同没问题!

i copy your code in to new contract on Remix 0.23.3, and return greet function: "Hello, World!"我将您的代码复制到 Remix 0.23.3 上的新合约中,并返回问候功能:“Hello,World!”

Maybe you use remix ide in another version or your ide has bugs.也许你在另一个版本中使用了 remix ide,或者你的 ide 有错误。 I suggest you use another brower for remix or another ide for solidity like hardhat https://hardhat.org/我建议您使用其他浏览器进行混音或使用其他 ide 来获得稳固性,例如安全帽https://hardhat.org/

my result for greet:我打招呼的结果: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM