简体   繁体   中英

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. The solidity code I'm using is as follows.

// 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:

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

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.
  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.17
  2. add two lines to the genesis json file automatically generated by puppeth , which are as follows
{
  "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!"

Maybe you use remix ide in another version or your ide has bugs. I suggest you use another brower for remix or another ide for solidity like hardhat https://hardhat.org/

my result for greet: 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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