6

I have a pre-deployed contractA with known ABI. I would like to call function func1(string,string) in the contractA (and pass the arguments) from a new contractB and send some value at the same time. So far, I managed to write the following (which does not send the arguments properly):

    contract contractB is mortal  {
        function invokeContractA() { 
            address contractAaddress= 0x1234567891234567891234567891234567891234;
            uint ValueToSend = 1234;
            contractAaddress.call.value(ValueToSend)(bytes4(sha3("func1(string,string)")),
                 "arg1TEXT", "arg2TEXT");
        }  
    }

Would appreciate your suggestions on what else is missing here (perhaps, need to convert the arguments into bytecode somehow?).

12

Here's an approach that's simpler and checked by the compiler:

contract contractA {
    function blah(int x, int y) payable {}
}

contract contractB {
    function invokeContractA() { 
        contractA a = contractA(0x1234567891234567891234567891234567891234);
        uint ValueToSend = 1234;
        a.blah.value(ValueToSend)(2, 3);
    }  
}
  • Thank you. What if I do not know the code of contractA, just the ABI? – k-zar Jun 30 '16 at 2:43
  • You don't need to know all the code, just the signatures of the functions you want to call. Put those in your contractA definition like I did there, and you're good. Really you're just defining an interface. – Dennis Peterson Jun 30 '16 at 3:25

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.