pragma solidity ^0.4.24;

I'm trying to call another contract's functions to return values.

I have the below which successfully returns a true/false

_childAddress.call(bytes4(keccak256("isValidChild(uint256, uint256)")), _childModule6, 6) == true)

But when I try to return an actual value like so:

uint256 tokenId = _childAddress.call(bytes4(keccak256("totalSupply()")));

I get the following error:

Type bool is not implicitly convertible to expected type uint256. tokenId

I can't find the syntax anywhere for returning a value.

Any help appreciated.

  • You should share the relevant code of each one of these contracts, since no one here can guess what it is! – goodvibration Jun 5 '19 at 13:48
  • add more code please, and use truffle, cause remix does not work always as expected – Majd TL Jun 5 '19 at 14:45

With solc v0.5 the signature of call changed it returns a tuple (bool, bytes). The first parameter indicates if the call successful and the second parameter is the result of the function.

    bool success;
    bytes memory result;
    uint totalSupply;

Make the call using abi.encodeWithSignature to encode parameters and function signature

    (success, result) = childContract.call(abi.encodeWithSignature("totalSupply()"));
    if (success) {

If the call was successful decode the result of the function

        (totalSupply) = abi.decode(result, (uint));
        return totalSupply;

With v0.4 either you create an interface for your child contract or use assemply to obtain the value returned by the call.

| improve this answer | |

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.