0

I am beginner in Solidity, So my problem maybe simple. I have two contracts "BankA" and "customer". Whenever i deploy BankA in Truffle network and call pay() the following Error will emerge:

Error: Returned error: VM Exception while processing transaction: revert at PromiEvent (C:\Users\lenovo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\promievent.js:9:1)

What is the solution. Thank you.

BankA:

pragma solidity ^0.5.12;

import "./customer.sol";
contract BankA{
  function pay() public returns(uint256){
    customer client=new customer();
    address(client).transfer(1000);
    return address(client).balance;
  }
  function() external payable{}

  }

customer:

pragma solidity^0.5.12;
contract customer{
  function() external payable{}
  }
}
  • What exactly is the point of this contract? Cause by calling pay() you create a new contract of type costumer and try sending it 1000 wei. Although, contract BankA has no balance. We need more information to help. – João Quintanilha Feb 6 at 12:04
  • if you add a fallback function (function to transfer funds to BankA), it will have funds later to transfer to contract customer. – João Quintanilha Feb 6 at 12:07
1

It looks as though it should work provided BankA has sufficient funds.

Keep in mind that this:

address(client).transfer(1000);

cannot work if it doesn't have sufficient funds to send 1000 to client.

Therefore, either invoke with {value: 1000} (or more), or use the fallback for a sinple transfer of some funds to BankA. Otherwise, it will fail for insufficient funds.

Hope it helps.

p.s. Consider address(client).transfer(msg.value); to forward whatever was received.

| improve this answer | |

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.