1

Here is my contract

pragma solidity ^0.4.14;
contract Sample {

  address private receiver;
  uint public amount;

  function pay(address _receiver, uint _amount) payable public returns (bool) {
    receiver = _receiver;
    amount =_amount;
    receiver.transfer(amount);
    return true;
  }
}

The error i am getting is,

transact to browser/ballot.sol:Sample.pay errored: VM error: revert. revert The transaction has been reverted to the initial state. Debug the transaction to get more information.

3

Problem: You are trying to send Ethers with the command receiver.transfer(amount); and specifying the amount as a parameter. Since your contract do not have enough ether balance it reverts the transaction.

Solution: You need to have enough ethers in your contract or you should send ethers along with the function call to solve the problem.

Change your smart contract as follows if you need to send _amount to _receiver from sender's address

pragma solidity ^0.4.14;
contract Sample {

  address private receiver;
  uint public amount;

  function pay(address _receiver) payable public returns (bool) {
    receiver = _receiver;
    receiver.transfer(msg.value);
    return true;
  }
}

And your caller function as follows

sampleContract.pay(_receiver, {value : <value in wei>});
  • Passed these params, transfer not happening "address", "{value : 1000000000000000000}" – sruthi23 Nov 27 '17 at 7:03
  • are you getting any errors? Mind sharing the code you are using for the call? – Manoj P R Nov 27 '17 at 7:45
  • not getting error but ether is not transferring, i.e not getting added to target account. I am using Remix, browser solidity compiler and just passing parameter for the function like: "address", "{value : 1000000000000000000}" – sruthi23 Nov 27 '17 at 7:57
  • Pass the parameter like this "<target address>" and change the value field that is displayed in the top section of the panel. You can find the field along with gas limit, gas price, account and environment fields. – Manoj P R Nov 27 '17 at 9:21
  • 2
    Value field in remix is used to send ethers in addition to the transaction fee. In real world scenario it reduces the given value from the contract caller's address. – Manoj P R Nov 27 '17 at 9:46

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.