0
contract A {
   function one() public {
      //transfer to B to call its fallback function
      B(addressB).transfer(value);
   }

contract B {
   function() external payable {
       someaddress.transfer(msg.value);
   }

In reality, is it impossible to do so? Otherwise, if I create an empty B's fallback function then it works. Or if I create simple function with someaddress.transfer(msg.value); and call this function from contract A as B(address).someFunction.value(value)() then it also works.

2

The thing is that the transfer method allows for 2300 gas stipend. Because the fallback has a transfer again, 2300 won't be enough. You can use

addressB.call.value(msg.value)()

which will pass all the available gas or you can do:

addressB.call.value(msg.value).gas(maxGas)()

Hope this helps

1

You can decide how much gas you give to the transfer.

The basic transfer or send give a default gas of only 2300 which is not enough for almost anything - you can just emit a log event and that's about it.

But if you use the pattern of recipient.call.value(1)() you can specify the amount of gas you pass to the recipient. You can read more for example here: https://ethereum.stackexchange.com/a/5993/31933

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.