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
accounts[0]
have inbalanceOf
?mapping(address => uint256) public balanceOf;
. How much doesapp.balanceOf(web3.eth.accounts[0] )
return?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.