0

I am trying replicate the program given at the following link: What is a function Selector

However, I am not using the function selector. I am using the name of the function explicitly to invoke it by associating it with contract'ss address and calldata syntax. I have two problems first I can't understand how to retrieve the arguments returned by the called function. Secondly I am getting the syntax error:

solc calwoFSelector.sol calwoFSelector.sol:12:25: Error: Member "func" not found or not visible after argument-dependent lookup in address. bool success =dest.func.value()(uint256(789), uint8(123));

                    ^-------^

My complete code is:

pragma solidity ^0.5.1;

  contract Contract1 {
    function func(uint256 x, uint8 y) public returns (uint32, uint32)  {}
  }

  contract Contract2 {
     Contract1 public contract1 = new Contract1();
        function func() public returns (uint32, uint32) {
           uint32[2] memory ret;
           address dest = address(contract1);
           bool success      =dest.func.value()(uint256(789), uint8(123));
           return (ret[0], ret[1]);
       }
   }
zak100
  • 1,406
  • 1
  • 13
  • 37

1 Answers1

1

While you have knowledge about the code of Contract1 you can call the function directly. You can declare the return arguments (arg1, arg2) with the call.

pragma solidity ^0.5.1;

    contract Contract1 {
        function func(uint256 x, uint8 y) public returns (uint32, uint32)  {
            return (uint32(x), uint32(y));
        }
    }

    contract Contract2 {

        Contract1 public contract1 = new Contract1();

        function func() public returns (uint32, uint32) {
            (uint32 arg1, uint32 arg2) = contract1.func(uint256(789), uint8(123));
            return (arg1, arg2);
        }
    }
alberto
  • 3,343
  • 2
  • 12
  • 21
  • What is the advantage of using function selector in the provided link? – zak100 Jul 01 '19 at 02:30
  • @zak100 Function selector or signature is used when you don't have the ABI of the deployed contract, in this case Contract1, and you want to call a function of it. – alberto Jul 01 '19 at 08:10