I've taken the below contract as an example from a tutorial and changed items highlighted in bold, as per IDE errors.
What the contract should do is allocate ownership of the item to the account that deploys the contract, then when 2 ether is paid, change the ownership to the account that made the payment. When I deploy the contract, the ownership isnt allocated to the account, instead it has the address 0x000..., and when i use the buy function, ownership does not transfer and ether is not deducted from the buyers account. Any help would be appreciated.
pragma solidity ^0.4.0;
contract SalesContract {
address **public** owner;
bool public isSold = false;
string public salesDescription = "Honda Civic";
uint public price = 2 ether;
function SaleContract() {
owner = msg.sender;
}
function Buy() **public** payable {
if(msg.value >= price) {
**owner.transfer(address(this).balance)**;
owner = msg.sender;
isSold = true;
} else {
revert();
}
}
}
Original code from tutorial:
pragma solidity ^0.4.0;
contract SalesContract {
address public owner;
bool public sold = false;
string public salesDescription = 'Volvo V40 HF 56 32';
uint price = 2 ether;
function SalesContract() payable {
owner = msg.sender;
}
function buy() payable {
if(msg.value >= price) {
owner.transfer(this.balance);
owner = msg.sender;
sold = true;
} else {
revert();
}
}
}