Skip to main content
Add formatting for future viewers
Source Link
Shane Fontaine
  • 18.3k
  • 20
  • 56
  • 83

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 00 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();
}

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();
}

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();
}
added 564 characters in body
Source Link

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();
}

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.

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();
}
Source Link

Getting a contract's fallback payable function to fire from another contract?

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.