<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by suraj vastri on Medium]]></title>
        <description><![CDATA[Stories by suraj vastri on Medium]]></description>
        <link>https://medium.com/@vastrii?source=rss-495539d68f66------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8vSWxULAkN9-csj7YBpUdA.jpeg</url>
            <title>Stories by suraj vastri on Medium</title>
            <link>https://medium.com/@vastrii?source=rss-495539d68f66------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:49:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vastrii/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Casinc: A Secure and Transparent Betting Smart Contract]]></title>
            <link>https://coinsbench.com/building-casinc-a-secure-and-transparent-betting-smart-contract-e800a95d5c96?source=rss-495539d68f66------2</link>
            <guid isPermaLink="false">https://medium.com/p/e800a95d5c96</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[foundry]]></category>
            <dc:creator><![CDATA[suraj vastri]]></dc:creator>
            <pubDate>Thu, 23 Jan 2025 14:40:59 GMT</pubDate>
            <atom:updated>2025-01-27T10:46:45.379Z</atom:updated>
            <content:encoded><![CDATA[<p>Blockchain technology continues to revolutionize industries by introducing transparency, immutability, and security. One intriguing use case is decentralized gaming and betting platforms. In this blog, I’ll walk you through the Casinc smart contract — a secure, transparent betting platform I developed using Solidity. Let’s dive into the functionality, logic, and key security measures employed.</p><h3>Overview of Casinc</h3><p>Casinc is a decentralized betting smart contract built on Ethereum. It allows users to deposit funds, place bets, and withdraw their winnings. Admins manage game parameters and approve withdrawal requests. Casinc prioritizes security and fairness, ensuring users can trust the platform.</p><h3>Key Features</h3><ul><li><strong>Deposits:</strong> Users can deposit Ether into the platform to participate in games.</li><li><strong>Betting:</strong> Users place bets with customizable parameters, such as bet amount and multiplier.</li><li><strong>Winnings:</strong> If a user wins, the winnings are stored in their account and can be withdrawn after a cooldown period.</li><li><strong>Admin Controls:</strong> Admins can set game parameters, approve or decline withdrawal requests, and pause or resume the contract.</li></ul><h3>Contract Architecture</h3><p>The Casinc architecture consists of two main components:</p><ol><li><strong>Casinc Contract:</strong> The core logic for user interaction, including deposits, betting, and withdrawals.</li><li><strong>Admin Contract:</strong> A multisig-enabled contract that grants admins privileges, such as approving withdrawals and setting game parameters.</li></ol><p>Below is a simplified diagram of the workflow:</p><ul><li><strong>User Actions:<br></strong>1<strong>. </strong>Deposit funds to the Casinc contract.<br>2. Place bets with specified parameters.<br>3. Request a withdrawal of winnings after a waiting period.</li><li><strong>Admin Actions:<br></strong>1.<strong> </strong>Validate withdrawal requests and ensure sufficient contract balance.<br>2. Update game parameters dynamically.</li></ul><h3>Core Functionalities Explained</h3><h3>1. Deposits</h3><p>To play, users must first deposit Ether into the contract. This deposit is tracked in a mapping of user addresses to their respective balances. Here’s the Solidity code:</p><pre>function createDeposit() external payable whenNotPaused {<br>    require(msg.value &gt; 0, &quot;Deposit must be greater than zero&quot;);<br>    deposits[msg.sender] += msg.value;<br>    emit DepositCreated(msg.sender, msg.value);<br>}</pre><h3>2. Betting Logic</h3><p>Users can place bets within a predefined range. The contract simulates a game where outcomes are pseudo-random. Winning bets are rewarded based on the specified multiplier:</p><pre>function playGame(uint256 bet, uint256 multiplier) external whenNotPaused {<br>    require(bet &gt;= gameParameters.minBet, &quot;Bet is below the minimum limit&quot;);<br>    require(bet &lt;= gameParameters.maxBet, &quot;Bet exceeds the maximum limit&quot;);<br>    require(multiplier &lt;= gameParameters.multiplierLimit, &quot;Multiplier exceeds the limit&quot;);<br>    require(deposits[msg.sender] &gt;= bet, &quot;Insufficient balance&quot;);</pre><pre>    deposits[msg.sender] -= bet;</pre><pre>    bool won = (block.timestamp % 2 == 0); // Basic randomness for demonstration<br>    uint256 winningsAmount = 0;<br>    if (won) {<br>        winningsAmount = bet * multiplier;<br>        winnings[msg.sender] += winningsAmount;<br>    }</pre><pre>    emit GamePlayed(msg.sender, bet, winningsAmount);<br>}</pre><h3>3. With****drawal Process</h3><p>The withdrawal process is a two-step mechanism to ensure security:</p><ol><li><strong>Initiate Withdrawal:</strong> Users can request a withdrawal, locking the winnings for admin review. The winnings are held in a pending state for at least 24 hours:</li></ol><pre>function initiateWithdrawal() external whenNotPaused {<br>    uint256 amount = winnings[msg.sender];<br>    require(amount &gt; 0, &quot;No winnings available to withdraw&quot;);</pre><pre>    winnings[msg.sender] = 0;<br>    PendingWithdrawal storage pendingWithdrawal = pendingWithdrawals[msg.sender];<br>    pendingWithdrawal.amount += amount;<br>    pendingWithdrawal.unlockTime = block.timestamp + 1 days;<br>    emit WithdrawalRequested(msg.sender, amount);<br>}</pre><ol><li><strong>Execute Withdrawal:</strong> Once approved by the admin, users can withdraw their funds:</li></ol><pre>function executeWithdrawal() external whenNotPaused {<br>    PendingWithdrawal memory pendingWithdrawal = pendingWithdrawals[msg.sender];<br>    require(pendingWithdrawal.approved, &quot;Withdrawal not approved&quot;);<br>    require(pendingWithdrawal.unlockTime &lt;= block.timestamp, &quot;Withdrawal is still locked&quot;);</pre><pre>    uint256 amount = pendingWithdrawal.amount;<br>    unclaimedWithdrawalAmount -= amount;<br>    delete pendingWithdrawals[msg.sender];<br>    (bool success, ) = payable(msg.sender).call{value: amount}(&quot;&quot;);<br>    require(success, &quot;Failed to send Ether&quot;);<br>    emit WithdrawalExecuted(msg.sender, amount);<br>}</pre><h3>4. Admin Validation</h3><p>Admins can approve or decline withdrawal requests. This step ensures the platform’s balance remains sufficient to handle payouts:</p><pre>function decideWithdrawalRequest(address user, bool approved) external onlyAdmin {<br>    PendingWithdrawal storage pendingWithdrawal = pendingWithdrawals[user];<br>    require(!pendingWithdrawal.approved &amp;&amp; !pendingWithdrawal.declined, &quot;Already decided&quot;);</pre><pre>    if (!approved) {<br>        pendingWithdrawal.declined = true;<br>        return;<br>    }</pre><pre>    uint256 amount = pendingWithdrawal.amount;<br>    unclaimedWithdrawalAmount += amount;<br>    require(address(this).balance &gt;= unclaimedWithdrawalAmount, &quot;Insufficient contract balance&quot;);<br>    pendingWithdrawal.approved = true;<br>}</pre><h3>Security Measures</h3><ol><li><strong>Admin Control with Multisig:</strong> Withdrawal approvals are managed by a multisig admin contract, reducing the risk of single-point failures or malicious activity.</li><li><strong>Withdrawal Locks:</strong> Pending withdrawals are locked for 24 hours, providing admins enough time to verify requests.</li><li><strong>Pause Mechanism:</strong> The contract can be paused in case of an emergency, preventing malicious activity.</li><li><strong>Sufficient Balance Checks:</strong> The contract ensures that the balance is adequate before approving any withdrawal.</li><li><strong>Safe Ether Transfers:</strong> Ether transfers are executed using .call, a safer alternative to .transfer or .send.</li></ol><h3>Closing Thoughts</h3><p>Casinc demonstrates how blockchain can enable secure and transparent betting platforms. With features like admin control, withdrawal locks, and secure payment mechanisms, it ensures user trust and platform reliability.</p><p>This contract is an excellent foundation, but there are opportunities to enhance it further — for example, integrating Chainlink VRF for provably fair randomness and improving scalability with Layer 2 solutions. As we continue to innovate in Web3, the potential for decentralized gaming platforms like Casinc is limitless.</p><p>Got feedback or ideas? Feel free to share them!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e800a95d5c96" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/building-casinc-a-secure-and-transparent-betting-smart-contract-e800a95d5c96">Building Casinc: A Secure and Transparent Betting Smart Contract</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>