[Ethereum] Call contract and send value from Solidity

contract-developmentcontract-invocationsolidity

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

Best Answer

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);
    }  
}
Related Topic