Mahendra Panchal
Mahendra Panchal

Reputation: 193

Call deployed smart contract function from new smart contract via bytes.?

As per solidity documents page

I Created and deployed following contract:

pragma solidity ^0.4.16;

contract Foo {
  uint public result;
  function bar(bytes3[2]) public pure {}
  function baz(uint32 x, bool y) public pure returns (bool r) { result = x; return y; }
  function sam(bytes, bool, uint[]) public pure {}
}

on address : '0x0aaaaaaaaaaaaaaaaaaaaaaaaaax'

Now I have created another contract to execute baz method.

pragma solidity ^0.4.16;

contract ResultUtil {
  function generateResult(address _foo, bytes _data) public {
   _foo.call(_data);   // call baz method.
  }
}

executing function generateResult("0x0aaaaaaaaaaaaaaaaaaaaaaaaaax","0xcdcd77c000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001");

function executed successfully but value of result remain 0

Upvotes: 0

Views: 503

Answers (1)

Adam Kipnis
Adam Kipnis

Reputation: 11001

You marked your function as pure which means it won't alter state. You can't alter state of a contract and return a value in one method. Use one method to change the state of the contract (not marked as pure or view) then use a different function to return the value (which WILL be pure or view).

See the Solidity documentation for more info on pure and view functions.

Upvotes: 1

Related Questions