I have read a number of posts about making calls between contracts, but I can't get this simple example to work that involves two contracts that are already deployed on my private Ethereum blockchain.
The pattern I'm trying to create is:
i- 'Caller' receives call to 'proxyRequest' function
ii- Caller uses the the _target parameter and calls the 'registrationRequest' function at the supplied address.
iii- 'UserRegistered' event in 'CallMe' should fire.
But the problem is that the 'call' function in 'Caller' always returns false. Any pointers would be appreciated.
If I use Web3 and create a transaction that calls the 'registrationRequest' function directly in 'CallMe', then it works fine.
contract Caller
{
event SendingTransaction(address indexed _requestor, uint8 indexed action);
address public minter;
bytes public email; // hash of the email address
modifier onlyOwner {
if (msg.sender != minter)
throw;
_;
}
function() {
throw;
}
function Caller(bytes _email) {
// constructor
minter= msg.sender;
email= _email;
}
function proxyRequest(address _target, string _payload) onlyOwner public {
SendingTransaction(_target, 1);
// Event fires OK when I subscribe to it via Web3 code.
if (!_target.call("registrationRequest",_target, _payload))
{
SendingTransaction(_target, 2);
// Event fires OK when I subscribe to it via Web3 code.
}
else
{
SendingTransaction(_target, 3);
// Event NEVER fires
}
}
}
Second contract.
pragma solidity ^0.4.7;
contract CallMe
{
event UserRegistered(address indexed _from, string _attr);
address public minter; // keep track of the entity that created the contract
modifier onlyOwner {
if (msg.sender != minter)
throw;
_;
}
function CallMe() {
minter = msg.sender;
}
function() {
throw;
}
function registrationRequest(address _toAdd, string _code) {
// this event fires ok if I invoke it via web3
// this event DOES NOT fire ok if function invoked by 'Caller'
UserRegistered(_toAdd, _code);
}
function getMinter() constant returns (address) {
return minter;
}
}