1

I deployed a HelloWorld contract using web3j and it worked awesome with Ganache. I was able to call my only function from the contract and it returns the desired result all the time.

When I deploy the contract to a private node created with geth, the transaction appears in pendingTransactions list and it returns the address of the deployed contract shortly after starting mining, but I cannot call the funciton. It always returns 0x (tested with both geth console and web3j). As you can see it is there. enter image description here After starting the miner you can observe that it is successfully deployed: enter image description here

This is the code that deploys the contract (it works with Ganache): enter image description here

The problem is that every time when I want to call a function it returns 0x just like the contract is not there. I checked and geth manages to find the specific contract: enter image description here

EDIT:

I used 3 methods to call the contract: Java code using web3j, Geth console and Remix ide.

1) As you can see the contract is deployed(it appeared at pending transactions and was added to the blockchain after I started the miner. The idea is that the result of the method is still empty string not "helloWorld")

2) From Geth console it fails to cast the value to BigNumber. I read somewhere that this might be because the node is not synchronized and it doesn't know what value to return, so it returns empty value. enter image description here

3) From Java using Web3j enter image description here

It throws an exceptions because the value returned is 0x and it fails to cast it:

enter image description here

Genesis.json

{


"config": {
    "chainId": 3792,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "difficulty": "2000",
  "gasLimit": "3141592000000",
  "alloc": {
    "ca56bdff4ab30b96b4f618e718b88c7a1721ecc3": {
      "balance": "300000000000000000000"
    }
  }
}
  • 1
    How do you make the contract call? – Ismael Mar 25 at 1:56
  • 1
    @Ismael I edited the original question in order to include the methods used to call the functions inside the contract. Thank you! – Bogdan Mar 25 at 5:26
  • 1
    I tried your code with geth 1.8.17 and its "dev" chain, and your code works as expected from remix. Are you testing against a private testnet or a public one, ie ropsten, rinkeby, etc. In case you use a private testnet what's is your genesis file like? Are byzantinum opcodes enabled? – Ismael Mar 25 at 7:18
  • 2
    Anyway thank you very much for your time and help! – Bogdan Mar 26 at 18:42
  • 2
    Okay, so I think that I discovered the source of the problem. I was using the version 0.5.6 of solc with geth 1.8.22(stable). Geth was released in February and I think that it is not compatible with the new versions of solc, considering that I am capable to deploy a contract that was compiled with 0.5.4 that was released befero 1.8.22 – Bogdan Mar 30 at 13:39
1

TLDR, but here is a fundamental difference between Ganache and Geth:

When Ganache starts, it automatically unlocks the accounts specified in the command-line.

For example:

ganache-cli
    --port=8545
    --gasPrice=20000000000
    --gasLimit=8000000
    --account=0x0000000000000000000000000000000000000000000000000000000000000001,1000000
    --account=0x0000000000000000000000000000000000000000000000000000000000000002,1000000

Will unlock the accounts with private keys 0x0...1 and 0x0...2 (2 accounts).

The default (if you don't specify anything) is 0x0...1 thru 0x0...a (10 accounts).

Geth doesn't do that, so you must unlock the accounts yourself prior to running any of your Truffle tests, by sending to Geth an "unlock account" command for each one of the accounts used in these tests.

Alternatively, you can sign each transaction with your private key before sending it to your Geth node. Other than for testing, this approach is actually the recommended one, because if somebody hacks your node then they can obtain your account credentials.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.