0

I've only begun working with geth from last week and have faced the quite a challenge. I've written a smart contract and it works on remix (JavaScript VM) but somehow it does not work on my geth private network.

I've tried to deploy the same smart contract on Ganache and it worked fine.

I really don't know whether my geth private network is not functioning properly or my smart contract is at fault here. Please help

Genesis.json

{
  "config": {
    "chainId": 111,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "alloc"      : {},
  "coinbase"   : "0x1000000000000000000000000000000000000000",
  "difficulty" : "0x10000",
  "gasLimit"   : "9721975",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

Geth initialization

geth --datadir ./node1 --keystore keystore init genesis.json 

Geth console

geth --identity "1" --keystore keystore --datadir ./node1 --networkid 111 --port 30303 --nodiscover --rpc --rpcapi "db, personal, eth, web3, debug, miner, net, txpool" --rpccorsdomain="*" --rpcaddr="localhost" --rpcport 8545 --gasprice 20000000000 --allow-insecure-unlock console

Truffle configuration

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "111",
      from: "0x2a223397b04891e552f540900bde25383f32f7c8"
    }
  }
};

Smart contract

pragma solidity ^0.5.8;

contract SendMessage {

    struct Message{
        uint ID;
        string text;
        address from;
        address to;
    }
    event countEvent(
        uint indexed messagesCount
    );

    mapping(address => bool) public senders;
    mapping(uint => Message) public messages;
    uint messagesCount;
    address public owner;

    constructor () public {
        owner = msg.sender;
    }

    function sendText (string memory _text, address _to) public {
        messagesCount++;
        messages[messagesCount] = Message(messagesCount, _text, msg.sender, _to);
        emit countEvent(messagesCount);

    }

    function getCount () public view returns(uint) {
        return messagesCount;
    }
}

When I deploy the smart contract on the geth private network, it gets deployed without any issues, and I can execute sendText function with with following command in truffle console.

let app = await SendMessage.deploed()
let accounts = await web3.eth.getAccounts()
app.sendText("1st", accounts[1], {from:accounts[0]})

Transaction is successfully mined on the blockchain, but transaction log is empty in the transaction receipt. Here is the transaction receipt.

enter image description here

Assuming from the empty log the function did not succeed and messagesCount did not increase, subsequently when I call getCount() function I get error.

enter image description here

Geth version: 1.9.3-stable
Go version: go1.12.9
Nodejs version: v10.16.0
Solidity version: 0.5.11
Web3js version: 1.2.1

  • 1. I don't see here that you started mining in private network. 2. How did you determine that Transaction is successfully mined ? you second image does not shows that this is mined transaction ... it's just submitted transaction. If you need to get transaction status try : web3.eth.getTransactionReceipt(<your subbmited transaction hash>) method web3js.readthedocs.io/en/v1.2.0/… returned receipt shuold have blocknumber , which means that transaction is mined and included into block... – Baracuda Sep 19 at 12:11
  • @Baracuda I've tried web3.eth.getTransactionReceipt() and returned receipt had a block number 12 and empty logs. Afterwards I've tried web3.eth.getBlock(12) and the block had corresponding transaction hash in transactions. I should've included these in the question from the start, sorry – Xass1on Sep 20 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.