1
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.

Aleksandr
  • 149
  • 12

2 Answers2

3

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

Jaime
  • 8,340
  • 1
  • 12
  • 20
2

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

Lauri Peltonen
  • 29,391
  • 3
  • 20
  • 57