3

I am relatively new to Ethereum, so I apologize if there is an obvious answer to this question.

I am running a private blockchain to test contracts on. I have a very simple one, where there is one member variable and one event defined. Then there are 2 functions, where each one calls the event with a single argument. With only these two functions, the events work properly. When I call "sendTransaction" on either function, there is a event log in the Transaction Receipt.

However, when I add a 3rd function, that is just as simple (all it does is call the event on a single argument), then all 3 functions stop working properly. They no longer show up in the Transaction Receipt.

I have even tried giving the transaction more gas, but it uses up all the gas I supply and still no even appears in the receipt.

Does any know why this happens?

Contact Code:

pragma solidity ^0.4.0; 
contract SetADT{ 
    struct VoterLog {
        address senderAccount;
        uint256 time;
        uint blockNumber;
    }
    mapping(uint => VoterLog) voterStatus;
    mapping(uint => uint128) voterKeys;
    uint voterIndex;

    mapping(address => bool) validNodes;

    mapping(uint => bool) contractSet; 
    event Print(bool); 
    event PrintAddr(address);

    function setTrue(uint key) external { 
        if(contractSet[key] == false) { 
            contractSet[key] = true;
        } 
        Print(contractSet[key]); 
    } 

    function getValue(uint key) external { 
        Print(contractSet[key]); 
    } 
}

When I add the following function as the third function in the contract, the events stop working (showing up in the transaction receipt).

function setAddr() {
    validNodes[msg.sender] = true;
    Print(validNodes[msg.sender]);
}

I have also test each individual function on their own in a separate contract, and they work fine. This leads me to believe that there is no error in the function code.

Thank you in advanced for any help!

  • 3
    Could you please add some sample code to demonstrate the issue? – The Officious BokkyPooBah Jan 10 '17 at 5:25
  • 3
    Please edit the question and add include the formatted source code. One source code snippet is worth of 1000 English words. – Mikko Ohtamaa Jan 10 '17 at 7:18
2

I wouldn't be able to tell you why it's happening without looking at the source, but I might be able tell you what.

Any abnormal end appears as a out-of-gas error. (This includes throw, going out of bounds with an array, division by zero, paying a non-payable function, etc.) When this happens, everything is reverted, including any events that might have occurred. If you keep adding gas with no success, then it's most likely one of those things.

EDIT:

I tried putting the full contract in Browser-Solidity and the events seemed to work fine.

However, the full, three-function contract uses much more gas when created. It might be possible that the initial transaction creating it is going out-of-gas, in which case no events will be happening, period. You could make sure using web3.eth.getCode().

  • Thank you for this information. Unfortunately, I am not sure what the error might be in my code since all the functions are very simple. I will update my post with the code – Jessica Jan 10 '17 at 22:38
1

Your contract runs perfectly on my private blockchain using geth and Browser Solidity that I downloaded to run locally and connect to geth on http://localhost:8545 .


Deployment And Execution In Browser Solidity

Here is a screen showing the deployment ("Create") of the contract and the execution of setTrue(...) using 43,324 gas and the event result true: enter image description here

Here is a screen showing the execution of getValue(...) using 22,901 gas and the second event result true: enter image description here

Here is a screen showing the execution of setAddr() using 27,867 gas and the third event result true: enter image description here


Deployment And Executing In Geth Using Browser Solidity Generated Code

Following is the code from the Web3 Deploy box in Browser Solidity:

var setadtContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"key","type":"uint256"}],"name":"getValue","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"key","type":"uint256"}],"name":"setTrue","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"setAddr","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"","type":"bool"}],"name":"Print","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"","type":"address"}],"name":"PrintAddr","type":"event"}]);
var setadt = setadtContract.new(
   {
     from: web3.eth.accounts[0], 
     data: '0x6060604052610276806100126000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480630ff4c91614610052578063975d711c1461006f5780639b8be4ee1461008c5761004d565b610002565b346100025761006d60048080359060200190919050506100a0565b005b346100025761008a6004808035906020019091905050610100565b005b346100025761009e60048050506101be565b005b7f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36004600050600083815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b50565b600015156004600050600083815260200190815260200160002060009054906101000a900460ff161515141561015e5760016004600050600083815260200190815260200160002060006101000a81548160ff021916908302179055505b7f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36004600050600083815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b50565b6001600360005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908302179055507f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b3600360005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b56', 
     gas: '4700000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })

Here are the results of pasting the code above into the geth console:

> var setadtContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"key","type":"uint256"}],"name":"getValue","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"key","type":"uint256"}],"name":"setTrue","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"setAddr","outputs":[],"payable":false,"type":"function"},{"anonymous":fa
undefined
> 
... 
...... 
......      data: '0x6060604052610276806100126000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480630ff4c91614610052578063975d711c1461006f5780639b8be4ee1461008c5761004d565b610002565b346100025761006d60048080359060200190919050506100a0565b005b346100025761008a6004808035906020019091905050610100565b005b346100025761009e60048050506101be565b005b7f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36004600050600083815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b50565b600015156004600050600083815260200190815260200160002060009054906101000a900460ff161515141561015e5760016004600050600083815260200190815260200160002060006101000a81548160ff021916908302179055505b7f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36004600050600083815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b50565b6001600360005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908302179055507f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36003600050
...... 
...... 
......     
...... 
......... 
......... 
......  })
I0111 13:29:52.055310 internal/ethapi/api.go:1045] Tx(0x30eedc837b40897b7ec5ac914b30bed3307333dcba12e70d4840b7e0bd8d5c86) created: 0x4ebb8365205f6096decbe0fcfcae91db164359bc
null [object Object]
undefined
> I0111 13:29:54.085918 miner/unconfirmed.go:105] 🔗  mined block #4704 [6c46e8d2…] reached canonical chain
I0111 13:29:54.085955 miner/unconfirmed.go:83] 🔨  mined potential block #4709 [6cc54975…], waiting for 5 blocks to confirm
I0111 13:29:54.087158 miner/worker.go:516] commit new work on block 4710 with 1 txs & 0 uncles. Took 1.210405ms
I0111 13:29:57.645780 miner/unconfirmed.go:105] 🔗  mined block #4705 [c9b78f22…] reached canonical chain
I0111 13:29:57.645928 miner/unconfirmed.go:83] 🔨  mined potential block #4710 [54b88d79…], waiting for 5 blocks to confirm
I0111 13:29:57.646092 miner/worker.go:516] commit new work on block 4711 with 0 txs & 0 uncles. Took 336.529µs
null [object Object]
Contract mined! address: 0x4ebb8365205f6096decbe0fcfcae91db164359bc transactionHash: 0x30eedc837b40897b7ec5ac914b30bed3307333dcba12e70d4840b7e0bd8d5c86

Here's the execution of setTrue(...) in geth:

> var tx = setadt.setTrue(1234, {from: eth.accounts[0]});
I0111 13:37:01.968067 internal/ethapi/api.go:1047] Tx(0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2) to: 0x4ebb8365205f6096decbe0fcfcae91db164359bc
...
> eth.getTransactionReceipt(tx)
{
  blockHash: "0x479f7ee50c7568c92e48b1dbdcfe6f90e6e349ade6f9148abb1f7630f9954f0c",
  blockNumber: 4771,
  contractAddress: null,
  cumulativeGasUsed: 43324,
  from: "0x000d1009bd8f0b1301cc5edc28ed1222a3ce671e",
  gasUsed: 43324,
  logs: [{
      address: "0x4ebb8365205f6096decbe0fcfcae91db164359bc",
      blockHash: "0x479f7ee50c7568c92e48b1dbdcfe6f90e6e349ade6f9148abb1f7630f9954f0c",
      blockNumber: 4771,
      data: "0x0000000000000000000000000000000000000000000000000000000000000001",
      logIndex: 0,
      removed: false,
      topics: ["0x2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b3"],
      transactionHash: "0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2",
      transactionIndex: 0
  }],
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000001000000000000",
  root: "0x06937bb7d67fd4a8e18ab013d76218ffab8c7d339f71f4f3bace02e8b0e56e1b",
  to: "0x4ebb8365205f6096decbe0fcfcae91db164359bc",
  transactionHash: "0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2",
  transactionIndex: 0
}

Let's retrieve the event log information, where you can see the true result:

var printEvent = setadt.Print({}, {fromBlock: 0, toBlock: 'latest'});
printEvent.watch(function(error, result){
  console.log(JSON.stringify(result));
});
...
{"address":"0x4ebb8365205f6096decbe0fcfcae91db164359bc","args":{"":true},"blockHash":"0x479f7ee50c7568c92e48b1dbdcfe6f90e6e349ade6f9148abb1f7630f9954f0c","blockNumber":4771,"event":"Print","logIndex":0,"removed":false,"transactionHash":"0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2","transactionIndex":0}

And here is the execution of setAddr() and the resulting events:

> var tx2 = setadt.setAddr({from: eth.accounts[0]});
I0111 13:43:40.814744 internal/ethapi/api.go:1047] Tx(0xa7317bc32128513df91aa45da6ec583b78904275d55457e1f8651b203d2c6c7b) to: 0x4ebb8365205f6096decbe0fcfcae91db164359bc
...
> eth.getTransactionReceipt(tx2);
{
  blockHash: "0xf5e9060cffa08aa76ed14f978e34412aa57d3fa459a178e50498c62b2e8d54dc",
  blockNumber: 4811,
  contractAddress: null,
  cumulativeGasUsed: 42867,
  from: "0x000d1009bd8f0b1301cc5edc28ed1222a3ce671e",
  gasUsed: 42867,
  logs: [{
      address: "0x4ebb8365205f6096decbe0fcfcae91db164359bc",
      blockHash: "0xf5e9060cffa08aa76ed14f978e34412aa57d3fa459a178e50498c62b2e8d54dc",
      blockNumber: 4811,
      data: "0x0000000000000000000000000000000000000000000000000000000000000001",
      logIndex: 0,
      removed: false,
      topics: ["0x2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b3"],
      transactionHash: "0xa7317bc32128513df91aa45da6ec583b78904275d55457e1f8651b203d2c6c7b",
      transactionIndex: 0
  }],
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000001000000000000",
  root: "0xea4839d4e6a4f4cb0873506bb57cc566f38833ed3593f4e02a0c6e4cf55cc726",
  to: "0x4ebb8365205f6096decbe0fcfcae91db164359bc",
  transactionHash: "0xa7317bc32128513df91aa45da6ec583b78904275d55457e1f8651b203d2c6c7b",
  transactionIndex: 0
}

> var printEvent = setadt.Print({}, {fromBlock: 0, toBlock: 'latest'});
undefined
> printEvent.watch(function(error, result){
  console.log(JSON.stringify(result));
});
...
{"address":"0x4ebb8365205f6096decbe0fcfcae91db164359bc","args":{"":true},"blockHash":"0x479f7ee50c7568c92e48b1dbdcfe6f90e6e349ade6f9148abb1f7630f9954f0c","blockNumber":4771,"event":"Print","logIndex":0,"removed":false,"transactionHash":"0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2","transactionIndex":0}
{"address":"0x4ebb8365205f6096decbe0fcfcae91db164359bc","args":{"":true},"blockHash":"0xf5e9060cffa08aa76ed14f978e34412aa57d3fa459a178e50498c62b2e8d54dc","blockNumber":4811,"event":"Print","logIndex":0,"removed":false,"transactionHash":"0xa7317bc32128513df91aa45da6ec583b78904275d55457e1f8651b203d2c6c7b","transactionIndex":0}
  • I was testing the contract solely on the geth console. I never used the Solidity Browser before. Could you please explain how you set up your private network so that I could try to recreate the results you got? – Jessica Jan 12 '17 at 2:44
  • Here's how I set up my private network for geth - ethereum.stackexchange.com/questions/9178/… . To connect Browser Solidity to geth, make sure geth has --rpc enabled. In BS, click on Environment (third cube icon from left on the top), then click on Web3 Provider. If you cannot get it working, please ask a new Question like "How do I set up a private network connected to Browser Solidity?" and I'll document it. – The Officious BokkyPooBah Jan 12 '17 at 4:00

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.