pragma solidity ^0.4.23;

contract Hotelbooking {

  event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value

 mapping(address => uint256) public balanceOf;

  //mapping (uint256 => data) accounts ;

  function transfer(address _to, uint256 _value) public returns (bool success) {
          require(balanceOf[msg.sender] >= _value);

          balanceOf[msg.sender] -= _value;

          balanceOf[_to] += _value;

          Transfer(msg.sender, _to, _value);
            return true;


My trascation code i want intract with mty truffle

Hotelbooking.deployed().then(function(i){app = i;})

app.transfer(web3.eth.accounts[1],10,{from : web3.eth.accounts[0] })

i am getting the following error

Error: VM Exception while processing transaction: revert at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1) at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1) at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1) at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1) at /usr/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:134:1 at /usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1 at Object.InvalidResponse (/usr/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)

plese help me

  • How much does accounts[0] have in balanceOf? Commented Oct 10, 2018 at 10:42
  • it is having 99.69 ether it is a test network Commented Oct 10, 2018 at 11:10
  • No no, I am talking about mapping(address => uint256) public balanceOf;. How much does app.balanceOf(web3.eth.accounts[0] ) return? Commented Oct 10, 2018 at 11:45
  • It is Showing me app.balanceOf(web3.eth.accounts[0] ) BigNumber { s: 1, e: 0, c: [ 0 ] } (i tried to convert into the .tonumber()) Commented Oct 10, 2018 at 11:52
  • 1
    Your Hotelbooking is a token contract. It has balances and a transfer function. It has nothing to do with Ether. Look up "token contract". As it stands, everybody has 0 tokens in your contract, so nobody can send anything. You need to initialise it. Commented Oct 10, 2018 at 12:25

2 Answers 2


Your balances are all zero. The require in your transfer function will always fail. You're missing a constructor to mint some coins.


constructor(uint initialAmount) {
     balanceOf[msg.sender] = initialAmount;
  • HI ivicaa I taught i have found the issue please correct me if i was wrong Thanks for your support Commented Oct 11, 2018 at 4:56

I found the issue .The function which i mentioned is for transferring my coins to another account rather than ether of one account to another

To Transfer ether see the following link

I am trying to add ether to one of my etherium account using smart contract

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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