Проверенный контрактТочноеMIT
BuddhaBless
Адрес0x2fa19caaf24924130dabf0bebbc42117be035790
- Баланс
0,0001 ETH
- Транзакций
2
- Компилятор
solc 0.8.24
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.24+commit.e11b9ed9
- Язык
- solidity
- Оптимизация
- Нет
- Версия EVM
- paris
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 21 869 567
- Транзакция создания
- 0x6994337a27…51ca83c05b
contracts/BuddhaBless.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract BuddhaBless {
struct Buddha {
uint id;
string name;
uint256 totalDonations; // Total Ether received as donations
address user; // Address of the Buddha's owner/creator
}
struct Prayer {
uint256 id;
string prayer; // Prayer message
uint256 donation; // Amount of Ether donated
uint256 createdAt; // Timestamp when the prayer was created
address user; // Address of the user who made the prayer
}
mapping(uint => Buddha) public buddhas; // Mapping of Buddha ID to Buddha struct
mapping(uint256 => Prayer) public prayers; // Mapping of Prayer ID to Prayer struct
uint public nextBuddhaId = 1; // Counter for Buddha IDs
uint256 public nextPrayerId = 1; // Counter for Prayer IDs
address public owner; // Address of the contract owner
uint public defaultBuddhaId; // ID of the default Buddha
event BuddhaAdded(uint indexed buddhaId, string name, address user);
event Prayed(uint256 indexed prayerId, uint indexed buddhaId, address indexed user, string prayer, uint256 donation);
event DonationTransferred(address to, uint256 amount); // Event for tracking transfers
modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can perform this action");
_;
}
constructor() {
owner = msg.sender;
// Initialize the contract with a default Buddha
defaultBuddhaId = nextBuddhaId++;
buddhas[defaultBuddhaId] = Buddha(defaultBuddhaId, "Gautama Buddha", 0, msg.sender);
emit BuddhaAdded(defaultBuddhaId, "Gautama Buddha", msg.sender);
}
// Function to add a new Buddha by the contract owner
function addBuddha(string memory name) public onlyOwner {
uint buddhaId = nextBuddhaId++;
buddhas[buddhaId] = Buddha(buddhaId, name, 0, msg.sender);
emit BuddhaAdded(buddhaId, name, msg.sender);
}
// Function to submit a prayer with a donation (Ether must be > 0)
function submitPrayer(string memory prayerMessage, uint buddhaId) public payable {
require(msg.value > 0, "A donation is required to submit a prayer.");
// If no specific Buddha ID is provided, use the default Buddha
if (buddhaId == 0) {
buddhaId = defaultBuddhaId;
}
require(buddhas[buddhaId].id != 0, "Buddha does not exist");
// Create the new prayer
uint256 prayerId = nextPrayerId++;
Prayer memory newPrayer = Prayer(prayerId, prayerMessage, msg.value, block.timestamp, msg.sender);
prayers[prayerId] = newPrayer;
// Update the Buddha's total donations
buddhas[buddhaId].totalDonations += msg.value;
emit Prayed(prayerId, buddhaId, msg.sender, prayerMessage, msg.value);
}
// Function to retrieve a specific Buddha by ID
function getBuddha(uint buddhaId) public view returns (Buddha memory) {
require(buddhas[buddhaId].id != 0, "Buddha does not exist");
return buddhas[buddhaId];
}
// Function to retrieve a specific prayer by ID
function getPrayer(uint256 prayerId) public view returns (Prayer memory) {
return prayers[prayerId];
}
// Function for the owner to withdraw all funds from the contract
function withdraw() public onlyOwner {
uint balance = address(this).balance;
require(balance > 0, "No funds to withdraw");
payable(owner).transfer(balance);
}
// Function to transfer a custom amount of Ether to a specified address
function transferDonation(address payable to, uint256 amount) public onlyOwner {
require(amount > 0, "Amount must be greater than zero");
require(amount <= address(this).balance, "Insufficient contract balance");
// Transfer the specified amount to the given address
to.transfer(amount);
// Emit an event for tracking the transfer
emit DonationTransferred(to, amount);
}
}
Настройки компилятораПоказать
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "paris",
"remappings": []
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.