Transaction Hash:
Block:
18804934 at Dec-17-2023 09:44:35 AM +UTC
Transaction Fee:
0.00486771590686605 ETH
$14.23
Gas Used:
149,430 Gas / 32.575225235 Gwei
Emitted Events:
| 117 |
PurchaseContract.PurchaseMade( from=[Sender] 0x5189112951c31d038280cb2b44f60a8dd9f85c0d, to=0x3d79695ac6d0d238ddec33f407778f0ae607ffa6, listHash=8E116640AC158FCB65A6AA464843E784C50826E019AB03376DDAB28317BEDEB8 )
|
Account State Difference:
| Address | Before | After | State Difference | ||
|---|---|---|---|---|---|
| 0x3D79695a...ae607ffa6 | 0.507402424698732688 Eth | 0.951342424698732688 Eth | 0.44394 | ||
| 0x51891129...DD9F85c0d |
0.54379375475283315 Eth
Nonce: 1252
|
0.0859260388459671 Eth
Nonce: 1253
| 0.45786771590686605 | ||
|
0x95222290...5CC4BAfe5
Miner
| (beaverbuild) | 5.956830507333879616 Eth | 5.956846944633879616 Eth | 0.0000164373 | |
| 0xBc962E2e...aE2a8085F | 2.263033623764682777 Eth | 2.272093623764682777 Eth | 0.00906 |
Execution Trace
ETH 0.453
PurchaseContract.buy( ethsId=A907D0DE44E3C6CBA7369021EDDC3BBD8976D5DAB9FE836D99F5D096FB558FC7, listId=A6E0C20176DDCDE687EA33D8CE9BF1A3436B000F49027D8EAE880B759369873B, listAddress=0x3D79695aC6d0D238DdEC33F407778f0ae607ffa6, price=453000000000000000 )
- ETH 0.44394
0x3d79695ac6d0d238ddec33f407778f0ae607ffa6.CALL( )
buy[PurchaseContract (ln:34)]
Purchase[PurchaseContract (ln:39)]transfer[PurchaseContract (ln:44)]payable[PurchaseContract (ln:44)]PurchaseMade[PurchaseContract (ln:47)]
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract PurchaseContract {
address public owner;
uint256 public feePercentage = 2;
struct Purchase {
bytes32 ethsId;
bytes32 listId;
address listAddress;
uint256 price;
bool isPurchased;
}
mapping(bytes32 => Purchase) public purchases;
event PurchaseMade(address from, address to, bytes32 listHash);
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can call this function.");
_;
}
function setFeePercentage(uint256 newFee) public onlyOwner {
feePercentage = newFee;
}
function buy(bytes32 ethsId, bytes32 listId, address listAddress, uint256 price) public payable {
bytes32 purchaseHash = keccak256(abi.encodePacked(ethsId, listId));
require(!purchases[purchaseHash].isPurchased, "This item is already purchased.");
require(msg.value == price, "Incorrect price.");
purchases[purchaseHash] = Purchase(ethsId, listId, listAddress, price, true);
uint256 fee = (price * feePercentage) / 100;
uint256 amountToSend = price - fee;
payable(listAddress).transfer(amountToSend);
// The fee remains in the contract
emit PurchaseMade(msg.sender, listAddress, purchaseHash);
}
function withdraw(uint256 amount) public onlyOwner {
uint256 balance = address(this).balance;
require(amount > 0, "Amount must be greater than 0");
require(balance >= amount, "Insufficient funds in contract");
payable(owner).transfer(amount);
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "New owner cannot be the zero address");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}