pragma solidity ^0.8.0;
contract RandomRewardPool {
address[] public participants;
uint public totalAmount;
constructor() {
totalAmount = 0;
}
function joinPool() public payable {
require(msg.value > 0, "Katılım ücreti gereklidir.");
participants.push(msg.sender);
totalAmount += msg.value;
}
function distributeRewards() public {
require(participants.length >= 3, "En az 3 katılımcı gereklidir.");
uint reward1 = (totalAmount * 50) / 100; // Birinciye %50
uint reward2 = (totalAmount * 30) / 100; // İkinciye %30
uint reward3 = (totalAmount * 20) / 100; // Üçüncüye %20
uint[] memory randomIndexes = generateRandomIndexes();
payable(participants[randomIndexes[0]]).transfer(reward1);
payable(participants[randomIndexes[1]]).transfer(reward2);
payable(participants[randomIndexes[2]]).transfer(reward3);
// Havuzu sıfırla
participants = new address[](0);
totalAmount = 0;
}
function generateRandomIndexes() private view returns (uint[] memory) {
uint[] memory indexes = new uint[](3);
// Rasgele indeksleri oluştur
for (uint i = 0; i < 3; i++) {
indexes[i] = uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, i))) % participants.length;
}
return indexes;
}
}bu tarz bir kontratla ve metamask bağlatısıyla kolayca yapabilirsin