Startseite
Willkommen im Solidity Community Forum
Beiträge
39- Experten Q&AMar 29, 2025
How to generate random Number between 1&2 without VRF?
So I was making a coinflip game which assigns head- 1 and tails -2 and when user places bet on polygon chain.... smart contract generates a random number between 1 and 2 and if the outcome is same...user gets double - (5 % as fee to the owner of contract) ! from a pool and if outcome is different then user loses all and the lost amount is deposited in the pool - (3% as fee to the owner) (to fund winners)... but any way to make genrate a random number? I have no funds at all so I can't afford chainlink VRF to generate. So is there any other secure way for this? plus I am pritty new to solidity so I made this code with help of chat gpt but I don't it works....can anyone help to make the code better? code- // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract CoinFlip { address public owner; uint256 public contractBalance; event BetPlaced(address indexed player, uint256 amount, bool choice); event BetResult(address indexed player, uint256 amount, bool won); constructor() { owner = msg.sender; } function placeBet(bool choice) external payable { require(msg.value > 0, "Bet amount must be greater than 0"); bool outcome = (block.timestamp % 2 == 0); // Simple pseudo-random outcome if (outcome == choice) { uint256 winAmount = (msg.value * 2 * 95) / 100; require(address(this).balance >= winAmount, "Insufficient contract balance"); payable(msg.sender).transfer(winAmount); emit BetResult(msg.sender, winAmount, true); } else { uint256 lostAmount = (msg.value * 97) / 100; contractBalance += lostAmount; emit BetResult(msg.sender, msg.value, false); } emit BetPlaced(msg.sender, msg.value, choice); } function depositFunds() external payable { require(msg.sender == owner, "Only owner can deposit funds"); contractBalance += msg.value; } function withdrawFunds(uint256 amount) external { require(msg.sender == owner, "Only owner can withdraw funds"); require(amount <= address(this).balance, "Insufficient contract balance"); payable(owner).transfer(amount); contractBalance -= amount; } } `
- Smart Contract
- Solidity
00 - Experten Q&AMar 29, 2025
Wie generiere ich eine Zufallszahl zwischen 1 und 2 ohne VRF?
Also habe ich ein Coinflip-Spiel entwickelt, bei dem Kopf- 1 und Schwanz -2 zugewiesen werden und wenn der Benutzer eine Wette auf eine Polygonkette platziert... generiert der Smart Contract eine Zufallszahl zwischen 1 und 2 und wenn das Ergebnis dasselbe ist... bekommt der Nutzer das Doppelte - (5% als Gebühr für den Besitzer des Vertrags)! aus einem Pool und wenn das Ergebnis anders ist, verliert der Benutzer alles und der verlorene Betrag wird in den Pool eingezahlt - (3% als Gebühr für den Besitzer) (an die Fondsgewinner)... aber gibt es eine Möglichkeit, eine Zufallszahl zu generieren? Ich habe überhaupt kein Geld, also kann ich es mir nicht leisten, Chainlink VRF zu generieren. Gibt es dafür also einen anderen sicheren Weg? Außerdem bin ich ziemlich neu in Solidity, also habe ich diesen Code mit Hilfe von Chat GPT erstellt, aber ich funktioniert nicht... kann jemand helfen, den Code zu verbessern? Code- // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract CoinFlip { address public owner; uint256 public contractBalance; event BetPlaced(address indexed player, uint256 amount, bool choice); event BetResult(address indexed player, uint256 amount, bool won); constructor() { owner = msg.sender; } function placeBet(bool choice) external payable { require(msg.value > 0, "Bet amount must be greater than 0"); bool outcome = (block.timestamp % 2 == 0); // Simple pseudo-random outcome if (outcome == choice) { uint256 winAmount = (msg.value * 2 * 95) / 100; require(address(this).balance >= winAmount, "Insufficient contract balance"); payable(msg.sender).transfer(winAmount); emit BetResult(msg.sender, winAmount, true); } else { uint256 lostAmount = (msg.value * 97) / 100; contractBalance += lostAmount; emit BetResult(msg.sender, msg.value, false); } emit BetPlaced(msg.sender, msg.value, choice); } function depositFunds() external payable { require(msg.sender == owner, "Only owner can deposit funds"); contractBalance += msg.value; } function withdrawFunds(uint256 amount) external { require(msg.sender == owner, "Only owner can withdraw funds"); require(amount <= address(this).balance, "Insufficient contract balance"); payable(owner).transfer(amount); contractBalance -= amount; } } `
- Smart Contract
- Solidity
00 - DiskussionFeb 27, 2025
Reise zur intelligenten Vertragsprüfung
Welchen Rat geben Sie jemandem, der gerade erst mit der Prüfung intelligenter Verträge beginnt
- Smart Contract
- Solidity
- Yul
01 - DiskussionFeb 24, 2025
Hallo Leute, ich bin neu hier. Ich hatte gehofft, jemand könnte mir Links geben, um Solidität effektiv zu lernen.
//SDPX-Lizenz-ID: MIT Pragma Solidität 0.8.24; Vertrag Hallo Welt { string public Hallo Welt; } //Musste hier einfach etwas hinzufügen
- Smart Contract
- Solidity
02 - DiskussionDec 09, 2024
Einsteiger in Solidity
Nachdem ich den Anfängerkurs über Cyfrin Updraft besucht habe, versuche ich etwas aufzubauen, um das Wissen zu festigen, aber es ist, als ob ich nichts wüsste. Das macht mich wirklich traurig. Welchen Rat werdet ihr geben
- Smart Contract
- Solidity
23Beste Antwort - DiskussionSep 13, 2024
Seeking Freelance Opportunities for Beginner Solidity Developer"
I have been studying Solidity for a couple of weeks and do not have any previous IT background. Are there any opportunities for me to get freelance work or earn money with my current skills?
- Solidity
- Use cases
00 - DiskussionJul 24, 2024
Formatting/Hello
I am new to Solidity! I wanted to say hello to this awesome community in hopes that it will get me out of my shell, and hopefully meet new people. I have zero programming experience, but love crypto. When posting questions in these forums is there a certain format I should post my question in, and/or any not so obvious rules I should follow in these forums? Thank you for taking the time to read, and leaving a reply!
- Smart Contract
- Solidity
- Use cases
01 - DiskussionJul 13, 2024
Career Path in WEB3 Auditing: Project Building or Learning Auditing First?
Hi everyone, I've recently completed the Solidity and Foundry basic and advanced courses with Cyfrin Updraft. I'm contemplating my next steps and considering a career in Solidity. Should I start learning smart contract auditing at this stage, or would it be more beneficial to first create some projects to solidify my current knowledge? Looking forward to your advice!
- Smart Contract
- Solidity
01 - Experten Q&AJun 04, 2024
How often does the solidity syntax change
I'd like to know how often the solidity syntax rules are changed and the best newsletter to follow up on the most recent updates
- Smart Contract
- Solidity
- Language Grammar
- Solidity Compiler
11 - DiskussionMay 31, 2024
Reentrancy Vulnerability
Hello everyone , I've noticed that the offer function uses the .call{value: amount}("") method to send Ether to the recipient's address. Could anyone provide insight into whether this function is indeed vulnerable to reentrancy and suggest any best practices or modifications to mitigate such risks? function _offer(address to, uint256 amount) internal { balance -= amount; (bool success, ) = to.call{value: amount}(""); if (!success) { revert TransferFailed(address(0), address(this), to, amount); } } `
- Smart Contract
- Solidity
- Solidity Compiler
01
- 76
- 50
- 46
- 37
- 36
- 25
- 25
- 25
- 20
- 18
Verdiene deinen Anteil an 1000 Sui
Sammle Reputationspunkte und erhalte Belohnungen für deine Hilfe beim Wachstum der Sui-Community.
- Solidity
- Smart Contract
- Solidity Compiler
- Use cases
- Yul
- Optimizer
- Language Grammar
- Internals
- Private
- My ERC721 contract successfully deploys, but I can't verify the contract's source code with hardhat21
- Solidity and ethers.js Compute Different Addresses from the Same Signature21
- can't understand what are the locations(uint256)22
- How to reverse keccak256 in solidity22
- Clarification on Gas Refunds and Comparison Between "require" and "revert" in Smart Contracts21