0

I have read in various posts that this error occurs when there is a problem with executing function. So I'm asking about this error in regards to the code I have written.

Please see below:

contract Slot_Machine is Mortal{

  // A struct type that defines state variables of a player.
  //Every player has a wallet, amount they are willing to
  //deposit and a guess.
  struct Player{
      address payable wallet;
      uint deposit;
      uint guess;
  }

  mapping (address => Player) public player;

  constructor() public{
      newPlayer(10,5);
  }

  function sendPay(address to, uint amount) public {
      player[to].wallet.transfer(amount);// **---> where the error occurs in the truffle console**

  }

I've also tried simplifying the line of code, where 'to' is an address payable type:

to.transfer(amount)

Am I missing an exception throw or something?

  • Does your Slot_Machine contract have any ETH balance? – Markus - soliditydeveloper.com Jun 20 at 8:07
  • More specifically, does it have at least amount ETH balance? – goodvibration Jun 20 at 8:18
  • No the contract itself does not have a balance. Am I calling the function from the truffle console using the accounts arrays so something like: instance.sendPay(accounts[1], 10, {from: accounts[0]}) – oBlox Jun 20 at 9:39
  • So why do you expect x.transfer(amount) to complete successfully then? – goodvibration Jun 20 at 12:10
  • Because the function was being called from one account to send ether to another account, I expected the ether to move from that the calling account to the recipient. But you're basically saying that the function call will move ether from the contract balance itself to the recipient despite the call coming from a different external account? If so, then I get that. But now I'm wondering, how to send ether from one EOA to another via a contract call? – oBlox Jun 20 at 13:48

Your Answer

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

Browse other questions tagged or ask your own question.