0

My contract (contract A) is meant to send txs to another contract (Contract B). I want to end up having the fallback payable function of Contract B get called. I try to accomplish this by making a function in Contract A to take in an address (contract B address) and then transfer 0 eth to contract B from contract A.

function txTest(address recipient_addr) payable external
{        
  recipient_addr.transfer(0);      
}

However this currently does not work even if the contract address I put in as the recipient_addr has a fallback payable function.

If I use another non contract address as the recipient_addr then transfer will go off without issue.

Is it possible to have Contract A manage to call Contract B's fallback payable function?

Thank you for the help.

EDIT: The actual fallback function that should be called.

 function () external payable {
    buyObject(msg.sender);
}

function buyObject(address _beneficiary) onlyValidPurchase
onlyBuyer(_beneficiary)
onlyValidAddress(_beneficiary) public payable {
    uint numTokens = calculateTokens();
    shopSettings.fundsRaised = shopSettings.fundsRaised.add(msg.value);
    object.mint(_beneficiary, numTokens);
    ObjectPurchase(msg.sender, _beneficiary, msg.value, numTokens);
    forwardFunds();
}
3
  • The code you shared is correct and will trigger a payable fallback function in recipient_adr if it has one. If you're still having trouble, you'll need to share the full code (including the code behind recipient_adr) and how you're deploying the contract's and passing the address to this function, as well as the exact error you're seeing when you say it "does not work."
    – user19510
    Commented Mar 15, 2018 at 19:21
  • I have added in the fallback function code. From the reading I have done would it be correct to say that the fallback function does not succeed because the operations of the fallback function would exceed the 2300 gas stipend that transfer / send has for the fallback function? Commented Mar 15, 2018 at 19:48
  • Yes, I believe you're correct. If you want to forward more gas, you can use recipient_addr.call.value(n)(), where n is the amount of wei you want to send.
    – user19510
    Commented Mar 15, 2018 at 19:51

0

Your Answer

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