0
pragma solidity 0.8.13;
contract A {
    function callBFunction( address _address) public returns (bool) {
        bytes4 sig = bytes4(keccak256("bFunction()"));
        (bool success,) = _address.call(
            abi.encodePacked(sig)
        );
        return success;
    }
}
contract B {
    uint256 public num = 4;
    function bFunciton()  public returns(uint256){
        num = 996;
        return num;
    }
}

run A.callBFunction After that, the num of the B contract has not changed.

1 Answer 1

0

You have write wrong the function name in A smart contract. In this line of code:

 bytes4 sig = bytes4(keccak256("bFunction()"));

your function inside B smart contract is not called bFunction() but bFunciton().

Change the function name in line, that I described above, and it'll work.

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.