4

Playing around with Web3j, I set up a private, single-node blockchain with Geth using a genesis gas limit of 21 million.

I started a node with the following command:

geth --datadir ./geth/data --rpc --networkid 611234220438 --nodiscover --mine --minerthreads 1 --etherbase 0xda42738b67c0dca7a44e3601312b7e44a007e4d2 --targetgaslimit 21000000 --verbosity 3

When I deploy a contract (gas limit 1 million), everything works as expected. A little bit of ETH is taken out of my wallet and I can interact with the deployed contract. However, constant functions work. All non-constant transactions fail and consume all gas.

I am executing this contract function (Solidity 0.4.13):

function skip() {}

Here is the contract creation and transaction as confirmed by Geth logging:

Submitted contract creation

fullhash=0xb407cf8dcb79cca01bd7bf11fb2ed025f5316d978aef92f2373be290a389df50 contract=0x075abea5aae9997bbf83a4a7f03d57c5bad65303

Submitted transaction

fullhash=0xae6697b0ebf6754f2570433a57dea159c662d79f59ef9d820cda5ffeb83028a5 recipient=0xc7c1335a273a6ee519f5563357b93b3e365a74da

Here is the transaction receipt:

{
  "transactionHash":"0x43c42aee0e44df748b0b482240e79f1536df15196843a4f752083bda02a14b01",
  "transactionIndex":0,
  "blockHash":"0x86b599ac97879417c5ed3f96e8985e85e861774c010b340e50081fcb6b2248bf",
  "blockNumber":461,
  "cumulativeGasUsed":1000000,
  "gasUsed":1000000,
  "contractAddress":null,
  "root":"0x70b774d4d679210d1e88f0d8fc0d6f2e0aec457fe333d65515e6bf61de7e0ec6",
  "from":"0xd2b4519298938983586e09028a2ea302c667cf76",
  "to":"0x075abea5aae9997bbf83a4a7f03d57c5bad65303",
  "logs":[],
  "logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "gasUsedRaw":"0xf4240",
  "transactionIndexRaw":"0x0",
  "blockNumberRaw":"0x1cd",
  "cumulativeGasUsedRaw":"0xf4240"
}

What might be going wrong? To me, it looks like the transaction might be failing, though I don't know why or how to tell.

migrated from stackoverflow.com Jul 24 '17 at 14:56

This question came from our site for professional and enthusiast programmers.

  • If you can't call non-constant functions, even empty ones, it seems more an error when creating the transaction. Now solc 0.4.4 is pretty old I'd try with a newer version. – Ismael Jul 23 '17 at 21:51
  • @Ismael good point, thanks. Updated to 0.4.13, yet the problem persists. – Jodiug Jul 24 '17 at 8:10
  • Possible duplicate of Out of Gas invoking precompiled contracts on private blockchains – Gawey Jul 25 '17 at 12:28
  • @Gawey I don't think it's a duplicate - that question concerns precompiled contracts built into the blockchain, whereas my contract is explicitly deployed. Until the contract is deployed, it does not have an address so I cannot assign it any Ether in the genesis file. – Jodiug Jul 27 '17 at 12:35
  • Ran that function on browser-solidity. It reports Transaction cost: 21380 gas, and Execution cost: 108 gas. You have probably verified this but, just to confirm, does the from account have enough ETH for the gas at the current gas price on your blockchain? At least, it did not throw, which would have consumed all gas sent. – Ajoy Bhatia Jul 31 '17 at 18:31
1

I don't know whether this is same as in your case but I was also facing the same issue and the problem was that I was giving the wrong parameter for --datadir parameter.

I fixed that and the problem was solved.

  • Hi @anand011090, would you mind sharing the incorrect parameter, and how you changed it to make it work? – Jodiug Jul 25 '17 at 14:11
  • @Jodiug in --datadir parameter, i was specifying the wrong path but in actual, there wasn't any directory with that name. so it was starting the process as a new with no accounts and whenever I tried to run, it showed me out of gas. Well it was my carelessness. I don't know whether you also have same issue. – anand011090 Jul 28 '17 at 9:51
  • Can confirm this was not the problem - I tried using a faulty datadir (./geth/daata). This created a new folder and caused the error Error processing transaction request: exceeds block gas limit when deploying the contract. With the right data path, the contract is deployed correctly but the subsequent method calls fail. – Jodiug Jul 28 '17 at 13:18
1

As you have mentioned that all non-constant transactions are failing and constant functions are working. I am suspecting this could be due to lack of default account.

Try to set the default account address or associate an account address to the transaction like below:

web3.eth.defaultAccount = web3.eth.accounts[0]

or

contract.function(param,{from: eth.accounts[0]}) 

or

contract.function(param,{from: 'Your account address'}) 
  • Apparently, the from field is set in the transaction above. According to people, the issue might be that the account was locked. I used Parity.build(HttpService()).personalUnlockAccount(wallet.address, walletPassword).sendAsync().get() to unlock all my accounts, but unfortunately that had no effect. – Jodiug Jul 30 '17 at 12:37
1

It turns out this was a misunderstanding of how Web3j works. I was expecting Web3j to deploy my latest contract on every run, but instead it was deploying my contract from a binary-encoded String.

In the Contract class generated by web3j-maven-plugin:

static final String BINARY = "606060405234610000575b60008054600160a060020a03191633600160a060020a03161790555b5b6104b9806100366000396000f300606060405236156100675763ffffffff60e060020a6000350416630f656e2c811461006c578063189e(...)";

This string is your compiled contract, not some kind of checksum for the contract.sol file. Unless you regenerate the Contract class on every change, it will keep using the old version, which did not have a function skip defined. I discovered this by starting from scratch.

Hopefully, the Geth devs will add a contract function undefined error some time - that would have led me down the right path a lot sooner!

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.