Skip to content

Instantly share code, notes, and snippets.

@mobigaurav
Created August 16, 2021 03:32
Show Gist options
  • Save mobigaurav/db24b2dac10690f4a928e31b9ffea6b5 to your computer and use it in GitHub Desktop.
Save mobigaurav/db24b2dac10690f4a928e31b9ffea6b5 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.4+commit.c7e474f2.js&optimize=false&runs=200&gist=
pragma solidity ^0.8.4;
contract PropertyTransferApp {
address public contractOwner;
constructor() public {
contractOwner = msg.sender;
}
modifier onlyOwner(){
require(msg.sender == contractOwner);
_;
}
struct Property {
uint256 id;
string name;
string owner;
uint256 value;
uint256 area;
bool exists;
}
mapping(uint256 => Property) public properties;
function addProperty(
uint256 _propertyid,
string memory _name,
string memory _owner,
uint256 _value,
uint256 _area
)public onlyOwner {
require(_value > 0, "Property value must be greater than 0");
properties[_propertyid].name = _name;
properties[_propertyid].owner = _owner;
properties[_propertyid].value = _value;
properties[_propertyid].area = _area;
properties[_propertyid].exists = true;
}
function queryProperty(uint256 _propertyid)
public view returns(
string memory name,
string memory owner,
uint256 area,
uint256 value
){
require(properties[_propertyid].exists, "Property must be present to query");
return(
properties[_propertyid].name,
properties[_propertyid].owner,
properties[_propertyid].area,
properties[_propertyid].value
);
}
function transferPropertyOwnership(
uint256 _propertyid, string memory _newOwner) public {
require(properties[_propertyid].exists, "Property must be present before transfer");
properties[_propertyid].owner = _newOwner;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment