3

I am running a simple contract in remix. I have an event in my contract which will be emitted just to check values of stateVariables.

contract stateVariable{
uint stateVariable1=10;
uint stateVariable2=20;
uint stateVariable3=30;
event log(uint stateVariable);
function display() public
{
   //emit log(stateVariable1,stateVariable2,stateVariable3); 
   emit log(stateVariable1); 
   emit log(stateVariable2); 
   emit log(stateVariable3); 
}

}

My question is about the format of log emitted in Remix. Why below log message contains "0" :"10" ? Is it something which shows the arguments number and it's value ?

{

"from": "0x0dcd2f752394c41875e259e00bb44fd505297caf", "topic": >> "0xf82c50f1848136e6c140b186ea0c768b7deda5efffe42c25e96336a90b26c744", "event": "log", "args": { "0": "10", "stateVariable": "10", "length": 1 } },

When i tried to display all three stateVariables it shows below :

"args": {

     **"0": "10",
     "1": "20",
     "2": "30",**
     "stateVariable1": "10",
     "stateVariable2": "20",
     "stateVariable3": "30",
     "length": 3
  }
0

In software and programming, indexes generally start at 0. So your first event is actually at index 0, which is equal to 10 here.

0

It looks like remix is expanding the args object with event parameter indexes ("0" : ..., "1": ..., ...) and parameter count ("length"). When using web3 directly you would only see "args": { "stateVariable": "10" }. See https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#contract-events-return for details.

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.