2

I want to call another solidity contract's method using Call/DelegateCall. Although the transaction seems successful, but I did not get the expected result, and it shows "Although one or more Error Occurred [Out of gas] Contract Execution Completed" message.

I am new to solidity code and I use remix to compile and deploy contract on ropsten testnet. I am not sure whether I make some silly mistake. Here are my two contract code:

pragma solidity ^0.4.6;

contract Callee {
    uint[] public values;

    function getValue(uint initial) public view returns(uint) {
        return initial + 150;
    }
    
    function storeValue(uint value) public {
        values.push(value);
    }
    
    function getValues() public view returns(uint) {
        return values.length;
    }
}
pragma solidity ^0.4.6;

contract Caller {
    function someUnsafeAction(address addr) public {
        addr.call(bytes4(keccak256("storeValue(uint256)")), 100);
    }
}

I deployed the Callee contract and the Caller contract from remix on ropsten testnet using my meta mask account, then passed the Callee contract address, "0x300997B17aEC75F636Ced66570Af76c05Dd380c9" to the Caller's someUnsafeAction method. The transaction went through, but I did not get the expected result, the value "100" is not saved into the Callee contract (https://ropsten.etherscan.io/address/0x300997b17aec75f636ced66570af76c05dd380c9).

Here is transaction (https://ropsten.etherscan.io/tx/0x625f7cac9aec9613f3e1ab81fbe06a4f57b85517e89521775cdaad2a3a656c5e)

Any help is appreciated. Thanks

  • 1
    0The gas limite used, around 23k gas, is too little. Try something like 100k or 1M gas. – Ismael Jul 10 at 21:59
  • This question is very well written. The coding example is a complete MVP, which allows one to literally copy-paste the code and test it. The contract is verified on Etherscan, making it easy to test it not only locally, but also on the public network where it is deployed. This is something that unfortunately cannot be said on 95% of the questions here. Well done! – goodvibration Jul 11 at 2:06
  • And BTW, you have two values already stored in the values array - 50 and 500. – goodvibration Jul 11 at 2:15
  • @Ismael, you are right, after I increated the gas limit to 1M, I got the expected result. The value "100" is saved into Callee's values. – Ming Wu Jul 11 at 14:09
  • @goodvibration, thank you for your comment. I try to make the question clear so the problem can be reproduced. – Ming Wu Jul 11 at 14:10
1

As Ismael has mentioned, the solution is to when the meta mask window is poped up for your confiramtion of transaction, we can edit(increase) the gas limit there to get our expected result.

| 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.