Описание изменений
This commit is contained in:
@@ -3,9 +3,13 @@ pragma solidity ^0.8.0;
|
||||
|
||||
contract MyContract {
|
||||
address public owner;
|
||||
uint256 public price;
|
||||
|
||||
event Purchase(address buyer, uint256 amount);
|
||||
|
||||
constructor() {
|
||||
owner = msg.sender;
|
||||
price = 0.01 ether; // Начальная цена 0.01 ETH
|
||||
}
|
||||
|
||||
modifier onlyOwner() {
|
||||
@@ -17,4 +21,21 @@ contract MyContract {
|
||||
require(newOwner != address(0), "New owner cannot be zero address");
|
||||
owner = newOwner;
|
||||
}
|
||||
|
||||
function setPrice(uint256 newPrice) public onlyOwner {
|
||||
price = newPrice;
|
||||
}
|
||||
|
||||
function getPrice() public view returns (uint256) {
|
||||
return price;
|
||||
}
|
||||
|
||||
function purchase(uint256 amount) public payable {
|
||||
require(msg.value == price * amount, "Incorrect payment amount");
|
||||
emit Purchase(msg.sender, amount);
|
||||
}
|
||||
|
||||
function withdraw() public onlyOwner {
|
||||
payable(owner).transfer(address(this).balance);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user