0

I am trying to make a Parent-Contract which has a function which spends ERC-20 Tokens. I want to call this function from different Child-Contracts (which are deployed independently) using Delegatecall. I tried following sample-code:

contract Parent {
    
    address reciever;
    MyERC20 token;
    
    constructor(address _token) public {
        reciever = msg.sender;
        token = MyERC20(_token);
    }
    
    function payReciever(uint256 amount) public {
        
        token.transfer(reciever, amount);
        
    }
    
}

contract Child {
    
    address child;
    
    constructor(address _child) public {
        child = _child;
    }
    
    function transfer(uint amount) public returns (bool) {
        
        (bool success, bytes memory data) = child.delegatecall(
            abi.encodeWithSignature("payReciever(uint256)", amount)
        );
        return success;
        
    }
    
}

So summarized, I want that payReciever() is called with the state of Child and then executes the transfer using Child as the sender.

Unfortunately, the delegatecall returns false and I can´t quite figure out why.

What is msg.sender in token.transfer()? What could be the problem in the above Code?

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.