Skip to content

Commit 243aaac

Browse files
committed
first commit
0 parents  commit 243aaac

11 files changed

+19718
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
.env
3+
coverage
4+
coverage.json
5+
typechain
6+
typechain-types
7+
8+
#Hardhat files
9+
cache
10+
artifacts
11+

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Sample Hardhat Project
2+
3+
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.
4+
5+
Try running some of the following tasks:
6+
7+
```shell
8+
npx hardhat help
9+
npx hardhat test
10+
GAS_REPORT=true npx hardhat test
11+
npx hardhat node
12+
npx hardhat run scripts/deploy.js
13+
```

contracts/Lock.sol

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.9;
3+
4+
// Import this file to use console.log
5+
import "hardhat/console.sol";
6+
7+
contract Lock {
8+
uint public unlockTime;
9+
address payable public owner;
10+
11+
event Withdrawal(uint amount, uint when);
12+
13+
constructor(uint _unlockTime) payable {
14+
require(
15+
block.timestamp < _unlockTime,
16+
"Unlock time should be in the future"
17+
);
18+
19+
unlockTime = _unlockTime;
20+
owner = payable(msg.sender);
21+
}
22+
23+
function withdraw() public {
24+
// Uncomment this line to print a log in your terminal
25+
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
26+
27+
require(block.timestamp >= unlockTime, "You can't withdraw yet");
28+
require(msg.sender == owner, "You aren't the owner");
29+
30+
emit Withdrawal(address(this).balance, block.timestamp);
31+
32+
owner.transfer(address(this).balance);
33+
}
34+
}

contracts/vWorld.sol

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.4;
4+
5+
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
6+
7+
contract Vworld is ERC721 {
8+
uint224 public cost = 1 ether;
9+
uint16 public constant maxSupply = 3;
10+
uint16 public totalSupply = 0;
11+
12+
struct area {
13+
string name;
14+
address owner;
15+
uint128 posX;
16+
uint128 posY;
17+
uint128 sizeX;
18+
uint128 sizeY;
19+
}
20+
21+
area[] public areas;
22+
constructor(
23+
string memory _name,
24+
string memory _symbol,
25+
uint256 _cost
26+
) ERC721(_name, _symbol) {
27+
cost = uint224(_cost);
28+
areas.push(
29+
area("area1", address(0), 0, 50, 50, 50)
30+
);
31+
areas.push(
32+
area("area2", address(0), 50, 50, 50, 50)
33+
);
34+
areas.push(
35+
area("area3", address(0), 0, 0, 50, 100)
36+
);
37+
}
38+
39+
function mint(uint _id) public payable {
40+
uint256 supply = totalSupply;
41+
require(supply <= maxSupply);
42+
require(areas[_id - 1].owner == address(0));
43+
require(msg.value >= cost);
44+
45+
// NOTE: tokenID always starts from 1, but the array starts from 0
46+
areas[_id - 1].owner = msg.sender;
47+
totalSupply += 1;
48+
49+
_safeMint(msg.sender, _id);
50+
}
51+
52+
function transferFrom(
53+
address from,
54+
address to,
55+
uint256 tokenId
56+
) public override {
57+
require(
58+
_isApprovedOrOwner(_msgSender(), tokenId),
59+
"ERC721: transfer caller is not owner nor approved"
60+
);
61+
62+
// Update Building ownership
63+
areas[tokenId - 1].owner = to;
64+
65+
_transfer(from, to, tokenId);
66+
}
67+
68+
function safeTransferFrom(
69+
address from,
70+
address to,
71+
uint256 tokenId,
72+
bytes memory _data
73+
) public override {
74+
require(
75+
_isApprovedOrOwner(_msgSender(), tokenId),
76+
"ERC721: transfer caller is not owner nor approved"
77+
);
78+
79+
// Update Building ownership
80+
areas[tokenId - 1].owner = to;
81+
82+
_safeTransfer(from, to, tokenId, _data);
83+
}
84+
85+
// Public View Functions
86+
function getAreas() public view returns (area[] memory) {
87+
return areas;
88+
}
89+
90+
function getArea(uint256 _id) public view returns (area memory) {
91+
return areas[_id - 1];
92+
}
93+
94+
95+
}

hardhat.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("@nomicfoundation/hardhat-toolbox");
2+
// require("@nomiclabs/hardhat-waffle");
3+
4+
require("@nomicfoundation/hardhat-chai-matchers");
5+
6+
/** @type import('hardhat/config').HardhatUserConfig */
7+
module.exports = {
8+
solidity: "0.8.9",
9+
};

0 commit comments

Comments
 (0)