<?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 Ryan Adhitama Putra on Medium]]></title>
        <description><![CDATA[Stories by Ryan Adhitama Putra on Medium]]></description>
        <link>https://medium.com/@ryanadhitama?source=rss-1a0a4c76d13e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_hViU2g8hNTXJrgxK8Ymdg.jpeg</url>
            <title>Stories by Ryan Adhitama Putra on Medium</title>
            <link>https://medium.com/@ryanadhitama?source=rss-1a0a4c76d13e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:00:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ryanadhitama/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[How to Create a Match the Colors Game on the Sui Blockchain Using Move]]></title>
            <link>https://blog.stackademic.com/how-to-create-a-match-the-colors-game-on-the-sui-blockchain-using-move-7215aadfd8ee?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7215aadfd8ee</guid>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[move]]></category>
            <category><![CDATA[match-color]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Sun, 26 Jan 2025 13:25:13 GMT</pubDate>
            <atom:updated>2025-01-27T05:51:31.312Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUxd25JVqNvTyWxoG1bnHQ.png" /></figure><p>In this tutorial, we will create a <strong>Match the Colors</strong> game using the Move programming language on the Sui blockchain. Players will attempt to match a randomly generated target color to win. This tutorial will guide you through writing and deploying the smart contract.</p><h3>Introduction</h3><p>The Match the Colors game allows players to:</p><ul><li>Select a color from a list of predefined colors.</li><li>Attempt to match their selected color with a randomly generated target color.</li><li>Win if their selected color matches the target color.</li></ul><p>We will implement:</p><ol><li>A Move smart contract for the game logic.</li><li>Randomness to generate the target color.</li><li>Event emission to record game results.</li></ol><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new match_colors</pre><p>This will create a directory named match_colors with the following structure:</p><pre>match_colors/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── match_colors.move<br>└── tests/<br>    └── match_colors_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd match_colors</pre><p>Replace the contents of sources/match_colors.move with the code for your module (explained in the following steps).</p><h3>2. Module Definition</h3><pre>module match_colors::match_colors;</pre><p>The match_colors::match_colors module defines a smart contract for a match colors game built on the Sui blockchain using the Move programming language.</p><h3>3. Import Statements</h3><pre>use sui::{<br>    random::Random,<br>    event,<br>};</pre><ul><li><strong>random::Random</strong>: Provides functionality to generate random numbers.</li><li><strong>event</strong>: Used to emit events that log game results for transparency.</li></ul><h3>4. Struct Definition: ColorMatchResult</h3><pre>public struct ColorMatchResult has copy, drop, store {<br>    player: address,        // Player&#39;s address<br>    target_color: u8,       // Randomly generated target color (index)<br>    player_color: u8,       // Color chosen by the player (index)<br>    outcome: u8,            // 0: Loss, 1: Win<br>}</pre><ul><li><strong>player</strong>: The address of the player who played the game.</li><li><strong>target_color</strong>: The randomly generated target color (1 to 4).</li><li><strong>player_color</strong>: The color chosen by the player (1 to 4).</li><li><strong>outcome</strong>: The game result (0 = loss, 1 = win).</li></ul><h3>5. Entry Function: play</h3><pre>entry fun play(<br>    player_color: u8,       // Player&#39;s chosen color (index)<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Validate the player&#39;s chosen color<br>    assert!(player_color &gt;= 1 &amp;&amp; player_color &lt;= 4, INVALID_COLOR);<br><br>    // Generate a random target color (1 to 4, representing a color index)<br>    let target_color = generate_random_color(random, ctx);<br><br>    // Determine the outcome<br>    let outcome = if (target_color == player_color) { WIN } else { LOSS };<br><br>    // Emit the game result as an event<br>    let player = ctx.sender();<br>    event::emit(ColorMatchResult {<br>        player,<br>        target_color,<br>        player_color,<br>        outcome,<br>    });<br>}</pre><ul><li><strong>player_color</strong>: The color index chosen by the player.</li><li><strong>random</strong>: A reference to the random generator object.</li><li><strong>ctx</strong>: The transaction context.</li></ul><p>The function:</p><ol><li>Validates the player’s color choice.</li><li>Generates a random target color using generate_random_color.</li><li>Compares the two colors and determines the outcome.</li><li>Emits the result as an event.</li></ol><h3>6. Random Color Generation: generate_random_color</h3><pre>fun generate_random_color(random: &amp;Random, ctx: &amp;mut TxContext): u8 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % 4 + 1) as u8 // Colors: 1 (Red), 2 (Green), 3 (Blue), 4 (Yellow)<br>}</pre><ul><li>Generates a random number between 1 and 4 to represent the target color.</li><li>Maps numbers to colors: 1 = Red, 2 = Green, 3 = Blue, 4 = Yellow.</li></ul><h3>7. Full Source Code</h3><pre>module match_colors::match_colors;<br><br>use sui::{<br>    random::Random,<br>    event,<br>};<br><br>/// Struct to store the game result<br>public struct ColorMatchResult has copy, drop, store {<br>    player: address,        // Player&#39;s address<br>    target_color: u8,       // Randomly generated target color (index)<br>    player_color: u8,       // Color chosen by the player (index)<br>    outcome: u8,            // 0: Loss, 1: Win<br>}<br><br>// === Constants ===<br>const LOSS: u8 = 0;         // Indicates a loss<br>const WIN: u8 = 1;          // Indicates a win<br>const INVALID_COLOR: u64 = 1; // Error code for invalid color<br><br>// === Public-Mutative Functions ===<br><br>/// Play the Match the Colors game<br>entry fun play(<br>    player_color: u8,       // Player&#39;s chosen color (index)<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Validate the player&#39;s chosen color<br>    assert!(player_color &gt;= 1 &amp;&amp; player_color &lt;= 4, INVALID_COLOR);<br><br>    // Generate a random target color (1 to 4, representing a color index)<br>    let target_color = generate_random_color(random, ctx);<br><br>    // Determine the outcome<br>    let outcome = if (target_color == player_color) { WIN } else { LOSS };<br><br>    // Emit the game result as an event<br>    let player = ctx.sender();<br>    event::emit(ColorMatchResult {<br>        player,<br>        target_color,<br>        player_color,<br>        outcome,<br>    });<br>}<br><br>// === Private Functions ===<br><br>/// Generate a random color index (1 to 4)<br>fun generate_random_color(random: &amp;Random, ctx: &amp;mut TxContext): u8 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % 4 + 1) as u8 // Colors: 1 (Red), 2 (Green), 3 (Blue), 4 (Yellow)<br>}</pre><h3>8. Deploy the Module</h3><p>Follow these steps to deploy your match_colors module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0xbc638dc3562cababa4e5ad2c2a5460d000c2ef17563052f3ea2a0c8964f82269">Package</a></p><h3>9. Interact Using Sui Client</h3><h4>Play the Match the Colors Game</h4><p>Call the play function with the following command:</p><pre>sui client call \<br>  --package &lt;PackageId&gt; \<br>  --module match_colors \<br>  --function play \<br>  --args &lt;Player_Color&gt; &lt;Random_ObjectId&gt; \<br>  --gas-budget 10000000</pre><ul><li>Replace &lt;PackageId&gt; with the ID of your deployed match_colors module.</li><li>Replace &lt;Player_Color&gt; with the color index you want to select (1 to 4).</li><li>Replace &lt;Random_ObjectId&gt; with the ID of the Random object in your environment.</li></ul><p>For Example</p><pre>sui client call \<br>  --package 0xbc638dc3562cababa4e5ad2c2a5460d000c2ef17563052f3ea2a0c8964f82269 \<br>  --module match_colors \<br>  --function play \<br>  --args 1 0x0000000000000000000000000000000000000000000000000000000000000008 \<br>  --gas-budget 10000000</pre><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7215aadfd8ee" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-create-a-match-the-colors-game-on-the-sui-blockchain-using-move-7215aadfd8ee">How to Create a Match the Colors Game on the Sui Blockchain Using Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Jackpot Game Smart Contract on Sui Blockchain with Move]]></title>
            <link>https://blog.stackademic.com/how-to-create-a-jackpot-game-smart-contract-on-sui-blockchain-with-move-8d464c1c2dff?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d464c1c2dff</guid>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[jackpot]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[move]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Sun, 19 Jan 2025 07:35:56 GMT</pubDate>
            <atom:updated>2025-01-20T06:40:16.996Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUxd25JVqNvTyWxoG1bnHQ.png" /></figure><p>In this tutorial, we will create a <strong>Jackpot Game</strong> smart contract using the Move programming language on the Sui blockchain. Players spin a virtual slot, and if the result consists of three identical numbers, they win the jackpot. Otherwise, they lose.</p><h3>Introduction</h3><p>The Jackpot Game allows players to:</p><ul><li>Spin a slot machine that generates three random numbers (0–9).</li><li>Win if all three numbers are the same (e.g., 777, 222).</li><li>View game results through emitted events.</li></ul><p>We will implement:</p><ol><li>A Move smart contract for the game logic.</li><li>Randomness to generate numbers for the slot spin.</li><li>Event emission for game results.</li></ol><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new jackpot</pre><p>This will create a directory named jackpot with the following structure:</p><pre>jackpot/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── jackpot.move<br>└── tests/<br>    └── jackpot_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd jackpot</pre><p>Replace the contents of sources/jackpot.move with the code for your module (explained in the following steps).</p><h3>2. Module Definition</h3><pre>module jackpot::jackpot;</pre><p>The jackpot::jackpot module defines a smart contract for a jackpot game built on the Sui blockchain using the Move programming language.</p><h3>3. Import Statements</h3><pre>use sui::{<br>    random::Random,<br>    event,<br>};</pre><ul><li><strong>random::Random</strong>: Provides functionality to generate random numbers.</li><li><strong>event</strong>: Used to emit events that log game results for transparency.</li></ul><h3>4. Struct Definition: JackpotResult</h3><pre>public struct JackpotResult has copy, drop, store {<br>    player: address,         // Address of the player<br>    numbers: vector&lt;u8&gt;,    // The three numbers generated<br>    outcome: u8,            // 0: Loss, 1: Win<br>}</pre><ul><li><strong>player</strong>: The address of the player who spun the slot machine.</li><li><strong>numbers</strong>: A vector storing the three randomly generated numbers.</li><li><strong>outcome</strong>: The result of the spin (“0” for loss, “1” for win).</li></ul><h3>5. Entry Function: spin</h3><pre>/// Play the jackpot game<br>entry fun spin(<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Generate three random numbers between 0 and 9<br>    let numbers = generate_numbers(random, ctx);<br><br>    // Determine if the player wins (all numbers are the same)<br>    let outcome = if (numbers[0] == numbers[1] &amp;&amp; numbers[1] == numbers[2]) {<br>        WIN<br>    } else {<br>        LOSS<br>    };<br><br>    // Emit the result as an event<br>    let player = ctx.sender();<br>    event::emit(JackpotResult {<br>        player,<br>        numbers,<br>        outcome,<br>    });<br>}</pre><ul><li><strong>random</strong>: A reference to the random generator object.</li><li><strong>ctx</strong>: The transaction context.</li></ul><p>The function:</p><ol><li>Generates three random numbers using generate_numbers.</li><li>Checks if all three numbers are the same.</li><li>Emits a JackpotResult event with the outcome.</li></ol><h3>6. Number Generation: generate_numbers</h3><pre>fun generate_numbers(random: &amp;Random, ctx: &amp;mut TxContext): vector&lt;u8&gt; {<br>    let mut gen = random.new_generator(ctx);<br>    let mut numbers: vector&lt;u8&gt; = vector::empty();<br>    vector::push_back(&amp;mut numbers, (gen.generate_u64() % 10) as u8);<br>    vector::push_back(&amp;mut numbers, (gen.generate_u64() % 10) as u8);<br>    vector::push_back(&amp;mut numbers, (gen.generate_u64() % 10) as u8);<br>    numbers<br>}</pre><ul><li>Uses randomness to generate three numbers between 0 and 9.</li><li>Initializes an empty vector and appends the numbers to it.</li></ul><h3>7. Full Source Code</h3><pre>module jackpot::jackpot;<br><br>use sui::{<br>    random::Random,<br>    event,<br>};<br><br>/// Struct to store the jackpot result<br>public struct JackpotResult has copy, drop, store {<br>    player: address,         // Address of the player<br>    numbers: vector&lt;u8&gt;,    // The three numbers generated<br>    outcome: u8,            // 0: Loss, 1: Win<br>}<br><br>// === Constants ===<br>const LOSS: u8 = 0;         // Indicates a loss<br>const WIN: u8 = 1;          // Indicates a win<br><br>// === Public-Mutative Functions ===<br><br>/// Play the jackpot game<br>entry fun spin(<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Generate three random numbers between 0 and 9<br>    let numbers = generate_numbers(random, ctx);<br><br>    // Determine if the player wins (all numbers are the same)<br>    let outcome = if (numbers[0] == numbers[1] &amp;&amp; numbers[1] == numbers[2]) {<br>        WIN<br>    } else {<br>        LOSS<br>    };<br><br>    // Emit the result as an event<br>    let player = ctx.sender();<br>    event::emit(JackpotResult {<br>        player,<br>        numbers,<br>        outcome,<br>    });<br>}<br><br>// === Private Functions ===<br><br>/// Generate three random numbers between 0 and 9<br>fun generate_numbers(random: &amp;Random, ctx: &amp;mut TxContext): vector&lt;u8&gt; {<br>    let mut gen = random.new_generator(ctx);<br><br>    // Create a vector and append three random numbers<br>    let mut numbers: vector&lt;u8&gt; = vector::empty();<br>    vector::push_back(&amp;mut numbers, (gen.generate_u64() % 10) as u8);<br>    vector::push_back(&amp;mut numbers, (gen.generate_u64() % 10) as u8);<br>    vector::push_back(&amp;mut numbers, (gen.generate_u64() % 10) as u8);<br><br>    numbers<br>}</pre><h3>8. Deploy the Module</h3><p>Follow these steps to deploy your jackpot module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0x5a640be616adc642e0204ad89b6cba4f284c44f61af07ab18fdaf44210701acd">Package</a></p><h3>9. Interact Using Sui Client</h3><h4>Play the Jackpot Game</h4><p>Call the spin function with the following command:</p><pre>sui client call \<br>  --package &lt;PackageId&gt; \<br>  --module jackpot \<br>  --function spin \<br>  --args &lt;Random_ObjectId&gt; \<br>  --gas-budget 10000000</pre><ul><li>Replace &lt;PackageId&gt; with the ID of your deployed jackpot module.</li><li>Replace &lt;Random_ObjectId&gt; with the ID of the Random object in your environment.</li></ul><p>For Example</p><pre>sui client call \<br>  --package 0x5a640be616adc642e0204ad89b6cba4f284c44f61af07ab18fdaf44210701acd \<br>  --module jackpot \<br>  --function spin \<br>  --args 0x0000000000000000000000000000000000000000000000000000000000000008 \<br>  --gas-budget 10000000</pre><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d464c1c2dff" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-create-a-jackpot-game-smart-contract-on-sui-blockchain-with-move-8d464c1c2dff">How to Create a Jackpot Game Smart Contract on Sui Blockchain with Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Spin-the-Wheel Smart Contract on Sui Blockchain Using Move]]></title>
            <link>https://blog.stackademic.com/how-to-create-a-spin-the-wheel-smart-contract-on-sui-blockchain-using-move-7fb4284e34cf?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fb4284e34cf</guid>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[move]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[spin-wheel]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Tue, 07 Jan 2025 02:05:32 GMT</pubDate>
            <atom:updated>2025-01-07T04:52:57.868Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsfCgqPYWO3hrfU2fRTP8Q.png" /></figure><p>In this tutorial, we will learn how to create a “Spin the Wheel” game smart contract using the Move programming language on the Sui blockchain. Players spin a wheel with customizable segments and payout multipliers. The result is determined randomly, and an event logs the player’s spin outcome.</p><h3>Introduction</h3><p>This game allows players to:</p><ul><li>Define the number of segments on the wheel (4–20).</li><li>Assign payout multipliers to each segment.</li><li>Spin the wheel and receive a multiplier based on the segment landed on.</li></ul><p>You will implement the following:</p><ol><li>A Move smart contract for the game logic.</li><li>A randomness-based spin mechanic.</li><li>Events to log spin results.</li></ol><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new spinwheel</pre><p>This will create a directory named spinwheel with the following structure:</p><pre>spinwheel/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── spinwheel.move<br>└── tests/<br>    └── spinwheel_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd spinwheel</pre><p>Replace the contents of sources/spinwheel.move with the code for your module (explained in the following steps).</p><h3>2. Module Definition</h3><pre>module spinwheel::spinwheel;</pre><p>The spinwheel::spinwheel module defines a smart contract for a Spin The Wheel game built on the Sui blockchain using the Move programming language.</p><h3>3. Import Statements</h3><pre>use sui::{<br>    random::Random,<br>    event,<br>};</pre><ul><li><strong>random::Random</strong>: Provides functionality to generate random numbers.</li><li><strong>event</strong>: Used to emit events that log game results for transparency.</li></ul><h3>4. Struct Definition: SpinResult</h3><pre>public struct SpinResult has copy, drop, store {<br>    player: address,<br>    spin_result: u64,  // The segment number landed on<br>    multiplier: u64,  // Payout multiplier for the segment<br>}</pre><ul><li><strong>player</strong>: The address of the player who spun the wheel.</li><li><strong>spin_result</strong>: The segment number where the wheel stopped.</li><li><strong>multiplier</strong>: The payout multiplier for the landed segment.</li></ul><h3>5. Constants</h3><pre>const INVALID_SEGMENTS: u64 = 1;<br>const MIN_SEGMENTS: u8 = 4;  // Minimum number of segments on the wheel<br>const MAX_SEGMENTS: u8 = 20; // Maximum number of segments on the wheel</pre><ul><li><strong>INVALID_SEGMENTS</strong>: Error code used when the number of segments is invalid.</li><li><strong>MIN_SEGMENTS</strong>: Minimum allowable number of segments (4).</li><li><strong>MAX_SEGMENTS</strong>: Maximum allowable number of segments (20).</li></ul><h3>6. Entry Function: spin</h3><pre>entry fun spin(<br>    num_segments: u8,<br>    multipliers: vector&lt;u64&gt;,<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Validate the number of segments<br>    assert!(num_segments &gt;= MIN_SEGMENTS &amp;&amp; num_segments &lt;= MAX_SEGMENTS, INVALID_SEGMENTS);<br><br>    // Ensure multipliers length matches the number of segments<br>    assert!(vector::length(&amp;multipliers) == num_segments as u64, 1);<br><br>    // Generate the spin result (random segment index)<br>    let spin_result = generate_spin_result(num_segments, random, ctx);<br><br>    // Determine the multiplier for the segment landed on<br>    let multiplier = multipliers[spin_result as u64];<br><br>    // Emit the result as an event<br>    let player = ctx.sender();<br>    event::emit(SpinResult {<br>        player,<br>        spin_result,<br>        multiplier,<br>    });<br>}</pre><ul><li>Validates that num_segments is within the allowed range (4–20).</li><li>Checks that the multipliers vector has the correct length to match the number of segments.</li><li>Generates a random spin result and determines the corresponding multiplier.</li><li>Emits a SpinResult event with the game details.</li></ul><h3>7. Random Spin Generation: generate_spin_result</h3><pre>fun generate_spin_result(num_segments: u8, random: &amp;Random, ctx: &amp;mut TxContext): u64 {<br>    let mut gen = random.new_generator(ctx);<br>    let random_number = gen.generate_u64();<br>    let segment = random_number % (num_segments as u64); // Cast num_segments to u64<br><br>    segment<br>}</pre><ul><li>Uses randomness to generate a number between 0 and num_segments - 1.</li><li>Ensures compatibility by casting num_segments to the same type as the random number (u64).</li></ul><h3>8. Full Source Code</h3><pre>module spinwheel::spinwheel;<br><br>use sui::{<br>    random::Random,<br>    event,<br>};<br><br>/// Struct to store the result of a spin<br>public struct SpinResult has copy, drop, store {<br>    player: address,<br>    spin_result: u64,  // The segment number landed on<br>    multiplier: u64,  // Payout multiplier for the segment<br>}<br><br>// === Constants ===<br>const INVALID_SEGMENTS: u64 = 1;<br>const MIN_SEGMENTS: u8 = 4;  // Minimum number of segments on the wheel<br>const MAX_SEGMENTS: u8 = 20; // Maximum number of segments on the wheel<br><br>// === Public-Mutative Functions ===<br><br>/// Spin the wheel and calculate the result<br>entry fun spin(<br>    num_segments: u8,<br>    multipliers: vector&lt;u64&gt;,<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Validate the number of segments<br>    assert!(num_segments &gt;= MIN_SEGMENTS &amp;&amp; num_segments &lt;= MAX_SEGMENTS, INVALID_SEGMENTS);<br><br>    // Ensure multipliers length matches the number of segments<br>    assert!(vector::length(&amp;multipliers) == num_segments as u64, 1);<br><br>    // Generate the spin result (random segment index)<br>    let spin_result = generate_spin_result(num_segments, random, ctx);<br><br>    // Determine the multiplier for the segment landed on<br>    let multiplier = multipliers[spin_result as u64];<br><br>    // Emit the result as an event<br>    let player = ctx.sender();<br>    event::emit(SpinResult {<br>        player,<br>        spin_result,<br>        multiplier,<br>    });<br>}<br><br>// === Private Functions ===<br><br>/// Generate a random spin result (segment index between 0 and `num_segments - 1`)<br>fun generate_spin_result(num_segments: u8, random: &amp;Random, ctx: &amp;mut TxContext): u64 {<br>   let mut gen = random.new_generator(ctx);<br><br>    // Generate a random number and calculate the segment index<br>    let random_number = gen.generate_u64();<br>    let segment = random_number % (num_segments as u64); // Cast num_segments to u64<br><br>    segment<br>}</pre><h3>9. Deploy the Module</h3><p>Follow these steps to deploy your spinwheel module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0x42f79866f445dcef3d65439b9f87442beebabf0f7032a74553daa1d74024b901">Package</a></p><h3>10. Interact Using Sui Client CLI</h3><p>Call the spin function with the following command:</p><pre>sui client call \<br>  --package &lt;PackageId&gt; \<br>  --module spinwheel \<br>  --function spin \<br>  --args &lt;num_segments&gt; &#39;[&lt;multiplier1&gt;, &lt;multiplier2&gt;, ...]&#39; &lt;Random_ObjectId&gt; \<br>  --gas-budget 10000000</pre><ul><li>Replace &lt;PackageId&gt; with the ID of your deployed spinwheel module.</li><li>Replace &lt;num_segments&gt; with the number of segments (4–20).</li><li>Replace the multipliers array with values matching the number of segments.</li><li>Replace &lt;Random_ObjectId&gt; with the ID of the Random object in your environment.</li></ul><p>Example</p><pre>sui client call \<br>  --package &#39;0x42f79866f445dcef3d65439b9f87442beebabf0f7032a74553daa1d74024b901&#39; \<br>  --module spinwheel \<br>  --function spin \<br>  --args 6 &#39;[0,1,2,1,3,0]&#39; &#39;0x0000000000000000000000000000000000000000000000000000000000000008&#39; \<br>  --gas-budget 10000000</pre><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fb4284e34cf" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-create-a-spin-the-wheel-smart-contract-on-sui-blockchain-using-move-7fb4284e34cf">How to Create a Spin-the-Wheel Smart Contract on Sui Blockchain Using Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Range Dice Smart Contract on Sui Blockchain with Move]]></title>
            <link>https://blog.stackademic.com/how-to-create-a-range-dice-smart-contract-on-sui-blockchain-with-move-822f50f8f21b?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/822f50f8f21b</guid>
            <category><![CDATA[move]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[dice]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Wed, 01 Jan 2025 04:29:31 GMT</pubDate>
            <atom:updated>2025-01-06T06:40:53.241Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsfCgqPYWO3hrfU2fRTP8Q.png" /></figure><p>This tutorial explains how to create a range dice game smart contract in Move, deployed on the Sui blockchain. Players choose a target value and bet whether a randomly rolled number will be “less” or “more” than their chosen value. The random roll is within the range of 1,000 to 100,000.</p><h3>Introduction</h3><p>In this game, players:</p><ul><li>Choose a target number within the range of 1,000–100,000.</li><li>Bet whether the roll result will be less or more than the target.</li><li>Receive a result event indicating their outcome (Win or Loss).</li></ul><p>This tutorial covers how to:</p><ol><li>Implement a Move smart contract for the game.</li><li>Use randomness to generate outcomes within a custom range.</li><li>Emit events to log game results.</li></ol><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new rangedice</pre><p>This will create a directory named rangedice with the following structure:</p><pre>rangedice/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── rangedice.move<br>└── tests/<br>    └── rangedice_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd rangedice</pre><p>Replace the contents of sources/rangedice.move with the code for your module (explained in the following steps).</p><h3>2. Module Definition</h3><pre>module rangedice::game;</pre><p>The rangedice::game module defines a smart contract for a range dice game built on the Sui blockchain using the Move programming language.</p><h3>3. Import Statements</h3><pre>use sui::{<br>    random::Random,<br>    event,<br>};</pre><ul><li><strong>random::Random</strong>: Provides functionality to generate random numbers.</li><li><strong>event</strong>: Used to emit events that log game results for transparency.</li></ul><h3>4. Struct Definition: RangeDiceResult</h3><pre>/// Struct to store the dice roll result<br>public struct RangeDiceResult has copy, drop, store {<br>    player: address,<br>    target: u64,<br>    roll: u64,<br>    bet_type: u8,  // 0: Less, 1: More<br>    outcome: u8,   // 0: Loss, 1: Win<br>}</pre><ul><li><strong>player</strong>: The player&#39;s address.</li><li><strong>target</strong>: The target number chosen by the player.</li><li><strong>roll</strong>: The randomly generated number.</li><li><strong>bet_type</strong>: Indicates the player&#39;s bet type (0 for &quot;Less,&quot; 1 for &quot;More&quot;).</li><li><strong>outcome</strong>: Indicates the game outcome (0 for Loss, 1 for Win).</li></ul><h3>5. Function: generate_roll</h3><pre>fun generate_roll(random: &amp;Random, ctx: &amp;mut TxContext): u64 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % (MAX_RANGE - MIN_RANGE + 1) + MIN_RANGE)<br>}</pre><ul><li>Generates a random number between 1,000 and 100,000 using modular arithmetic.</li><li>Ensures that the roll result is within the defined range.</li></ul><h3>6. Entry Function: roll</h3><pre>entry fun roll(<br>    target: u64,<br>    bet_type: u8, // 0: Less, 1: More<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // ...<br>}</pre><ul><li>Validates the target number and bet type.</li><li>Generates a random roll using the generate_roll function.</li><li>Compares the roll with the target based on the player’s bet type to determine the outcome.</li><li>Emits a RangeDiceResult event containing the game details.</li></ul><h3>7. Full Source Code</h3><pre>module rangedice::game;<br><br>use sui::{<br>    random::Random,<br>    event,<br>};<br><br>/// Struct to store the dice roll result<br>public struct RangeDiceResult has copy, drop, store {<br>    player: address,<br>    target: u64,<br>    roll: u64,<br>    bet_type: u8,  // 0: Less, 1: More<br>    outcome: u8,   // 0: Loss, 1: Win<br>}<br><br>// === Constants ===<br>const MIN_RANGE: u64 = 1000; // Minimum value of the range<br>const MAX_RANGE: u64 = 100000; // Maximum value of the range<br>const INVALID_TARGET: u64 = 1;<br>const INVALID_BET_TYPE: u64 = 2;<br>const LOSS: u8 = 0;<br>const WIN: u8 = 1;<br>const LESS: u8 = 0;<br>const MORE: u8 = 1;<br><br>// === Public-Mutative Functions ===<br><br>/// Roll the dice and check the result based on the player&#39;s bet<br>entry fun roll(<br>    target: u64,<br>    bet_type: u8, // 0: Less, 1: More<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Validate the target number<br>    assert!(target &gt;= MIN_RANGE &amp;&amp; target &lt;= MAX_RANGE, INVALID_TARGET);<br><br>    // Validate the bet type<br>    assert!(bet_type == LESS || bet_type == MORE, INVALID_BET_TYPE);<br><br>    // Generate a random roll<br>    let roll = generate_roll(random, ctx);<br><br>    // Determine the outcome based on the bet type<br>    let outcome = if (bet_type == LESS &amp;&amp; roll &lt; target) {<br>        WIN<br>    } else if (bet_type == MORE &amp;&amp; roll &gt; target) {<br>        WIN<br>    } else {<br>        LOSS<br>    };<br><br>    // Emit the result as an event<br>    let player = ctx.sender();<br>    event::emit(RangeDiceResult {<br>        player,<br>        target,<br>        roll,<br>        bet_type,<br>        outcome,<br>    });<br>}<br><br>// === Private Functions ===<br><br>/// Generate a random number between MIN_RANGE and MAX_RANGE<br>fun generate_roll(random: &amp;Random, ctx: &amp;mut TxContext): u64 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % (MAX_RANGE - MIN_RANGE + 1) + MIN_RANGE)<br>}</pre><h3>8. Deploy the Module</h3><p>Follow these steps to deploy your game module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0xcd1f71b22c07c308ddb8bc7635bab105fabe76cde77a4c9ac63162813f3e367e">Package</a></p><h3>9. Interact Using Sui Client</h3><h4>Roll the Dice</h4><p>Use the following command to test the roll function:</p><pre>sui client call \<br>  --package &lt;PackageId&gt; \<br>  --module game \<br>  --function roll \<br>  --args &lt;target&gt; &lt;bet_type&gt; &lt;Random_ObjectId&gt; \<br>  --gas-budget 10000000</pre><ul><li>Replace &lt;PackageId&gt; with the ID of your deployed rangedice module.</li><li>Replace &lt;target&gt; with a value between 1,000 and 100,000.</li><li>Replace &lt;bet_type&gt; with 0 for &quot;Less&quot; or 1 for &quot;More.&quot;</li><li>Replace &lt;Random_ObjectId&gt; with the ID of the Random object available in your Sui environment.</li></ul><p>For Example</p><pre>sui client call \<br>  --package &quot;0xcd1f71b22c07c308ddb8bc7635bab105fabe76cde77a4c9ac63162813f3e367e&quot; \<br>  --module game \<br>  --function roll \<br>  --args 10000 1 &quot;&quot;0x0000000000000000000000000000000000000000000000000000000000000008&quot;&quot; \<br>  --gas-budget 10000000</pre><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=822f50f8f21b" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-create-a-range-dice-smart-contract-on-sui-blockchain-with-move-822f50f8f21b">How to Create a Range Dice Smart Contract on Sui Blockchain with Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Limbo Game Smart Contract on Sui Blockchain Using Move]]></title>
            <link>https://blog.stackademic.com/how-to-build-a-limbo-game-smart-contract-on-sui-blockchain-using-move-0c19975bc03e?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c19975bc03e</guid>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[move]]></category>
            <category><![CDATA[limbo]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Mon, 30 Dec 2024 00:13:14 GMT</pubDate>
            <atom:updated>2025-01-06T06:31:02.134Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUxd25JVqNvTyWxoG1bnHQ.png" /></figure><p>In this tutorial, you’ll learn how to build a <strong>Limbo Game</strong> smart contract on the Sui blockchain using the Move programming language. The Limbo Game allows players to bet on a target multiplier and see if a randomly generated multiplier meets or exceeds their choice.</p><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new limbo</pre><p>This will create a directory named limbo with the following structure:</p><pre>limbo/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── limbo.move<br>└── tests/<br>    └── limbo_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd limbo</pre><p>Replace the contents of sources/limbo.move with the code for your module (explained in the following steps).</p><h3>2. Module Definition</h3><pre>module limbo::game;</pre><p>The limbo::game module defines a smart contract for a Limbo game built on the Sui blockchain using the Move programming language.</p><h3>3. Import Statements</h3><pre>use sui::{<br>    random::Random,<br>    event,<br>};</pre><ul><li><strong>random::Random</strong>: Provides functionality to generate random numbers.</li><li><strong>event</strong>: Used to emit events that log game results for transparency.</li></ul><h3>4. Struct Definition</h3><pre>public struct LimboResult has copy, drop, store {<br>    player: address,<br>    target_multiplier: u64,<br>    generated_multiplier: u64,<br>    outcome: u8, // 0: Loss, 1: Win<br>}</pre><ul><li><strong>player</strong>: Stores the player&#39;s address.</li><li><strong>target_multiplier</strong>: The multiplier the player sets as their target.</li><li><strong>generated_multiplier</strong>: The random multiplier generated by the game.</li><li><strong>outcome</strong>: Indicates if the player won (1) or lost (0).</li></ul><p>The struct is marked with <strong>copy</strong>, <strong>drop</strong>, and <strong>store</strong>, making it suitable for event storage.</p><h3>5. Constants</h3><pre>const MAX_MULTIPLIER: u64 = 10; // Maximum multiplier in the game<br>const LOSS: u8 = 0;<br>const WIN: u8 = 1;</pre><ul><li><strong>MAX_MULTIPLIER</strong>: Sets the upper limit for the random multiplier.</li><li><strong>LOSS</strong> and <strong>WIN</strong>: Represent the possible outcomes of the game.</li></ul><h3>6. Public Entry Function</h3><pre>entry fun play(<br>    target_multiplier: u64,<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    assert!(target_multiplier &gt;= 1 &amp;&amp; target_multiplier &lt;= MAX_MULTIPLIER, 1);<br><br>    let generated_multiplier = generate_multiplier(random, ctx);<br>    let (outcome) = if (generated_multiplier &gt;= target_multiplier) {<br>        WIN<br>    } else {<br>        LOSS<br>    };<br><br>    let player = ctx.sender();<br>    event::emit(LimboResult {<br>        player,<br>        target_multiplier,<br>        generated_multiplier,<br>        outcome,<br>    });<br>}</pre><ul><li><strong>target_multiplier</strong>: The player&#39;s desired threshold.</li><li><strong>generate_multiplier</strong>: A private function called to create a random multiplier.</li></ul><p><strong>Outcome Logic</strong>:</p><ul><li>If the generated multiplier is <strong>greater than or equal to</strong> the target multiplier, the player wins.</li><li>Otherwise, the player loses.</li></ul><p>Emits a LimboResult event to record the game&#39;s outcome.</p><h3>7. Private Function</h3><pre>fun generate_multiplier(random: &amp;Random, ctx: &amp;mut TxContext): u64 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % MAX_MULTIPLIER + 1)<br>}</pre><ul><li><strong>generate_multiplier</strong>: Produces a random number between 1 and MAX_MULTIPLIER using the random::Random module.</li><li>The % operator ensures the random value falls within the valid range.</li></ul><h3>8. Full Source Code</h3><pre>module limbo::game;<br><br>use sui::{<br>    random::Random,<br>    event,<br>};<br><br>/// Struct to store the game result<br>public struct LimboResult has copy, drop, store {<br>    player: address,<br>    target_multiplier: u64,<br>    generated_multiplier: u64,<br>    outcome: u8, // 0: Loss, 1: Win<br>}<br><br>// === Constants ===<br>const MAX_MULTIPLIER: u64 = 10; // Maximum multiplier in the game<br>const LOSS: u8 = 0;<br>const WIN: u8 = 1;<br><br>// === Public-Mutative Functions ===<br><br>/// Play the Limbo game<br>entry fun play(<br>    target_multiplier: u64,<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Validate the target multiplier<br>    assert!(target_multiplier &gt;= 1 &amp;&amp; target_multiplier &lt;= MAX_MULTIPLIER, 1);<br><br>    // Generate a random multiplier<br>    let generated_multiplier = generate_multiplier(random, ctx);<br><br>    // Determine if the player wins or loses<br>    let (outcome) = if (generated_multiplier &gt;= target_multiplier) {<br>        WIN<br>    } else {<br>        LOSS<br>    };<br><br>    // Emit the game result as an event<br>    let player = ctx.sender();<br>    event::emit(LimboResult {<br>        player,<br>        target_multiplier,<br>        generated_multiplier,<br>        outcome,<br>    });<br>}<br><br>// === Private Functions ===<br><br>/// Generate a random multiplier between 1 and MAX_MULTIPLIER<br>fun generate_multiplier(random: &amp;Random, ctx: &amp;mut TxContext): u64 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % MAX_MULTIPLIER + 1)<br>}</pre><h3>9. Deploy the Module</h3><p>Follow these steps to deploy your limbo module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0x3db1ff915abfef589bf68cdfd3fe633e56bfc7a7c8c2554122e5b0733bd385cf">Package</a></p><h3>10. Interact Using Sui Client CLI</h3><p>Use the following command to test the play function:</p><pre>sui client call \<br>  --package &lt;PackageId&gt; \<br>  --module game \<br>  --function play \<br>  --args &lt;target_multiplier&gt; &lt;Random_ObjectId&gt; \<br>  --gas-budget 10000000</pre><p>Replace:</p><ul><li>&lt;PackageId&gt;: With the ID of the deployed Limbo module.</li><li>&lt;target_multiplier&gt;: The player&#39;s chosen multiplier.</li><li>&lt;Random_ObjectId&gt;: A valid Random object available in your Sui environment.</li></ul><p>For Example</p><pre>sui client call \<br>  --package &quot;0x3db1ff915abfef589bf68cdfd3fe633e56bfc7a7c8c2554122e5b0733bd385cf&quot; \<br>  --module game \<br>  --function play \<br>  --args 8 &quot;0x0000000000000000000000000000000000000000000000000000000000000008&quot; \<br>  --gas-budget 10000000</pre><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c19975bc03e" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-build-a-limbo-game-smart-contract-on-sui-blockchain-using-move-0c19975bc03e">How to Build a Limbo Game Smart Contract on Sui Blockchain Using Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Dice Game Smart Contract on Sui Blockchain Using Move]]></title>
            <link>https://blog.stackademic.com/how-to-create-a-dice-game-smart-contract-on-sui-blockchain-using-move-bb990b8937f0?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb990b8937f0</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[dice-game]]></category>
            <category><![CDATA[move]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Sun, 29 Dec 2024 03:33:03 GMT</pubDate>
            <atom:updated>2025-01-06T06:28:10.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUxd25JVqNvTyWxoG1bnHQ.png" /></figure><p>This tutorial guides you through creating a simple dice game smart contract using Move on the Sui blockchain. The contract allows players to roll a die and record the results via events.</p><h3>Introduction</h3><p>A dice game is a simple yet fun application where players roll a die to get a random number between 1 and 6. This tutorial demonstrates how to:</p><ul><li>Implement a smart contract for rolling a dice.</li><li>Use randomness in Move to generate outcomes.</li><li>Emit events to log the results of the dice rolls.</li></ul><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new dice</pre><p>This will create a directory named dice with the following structure:</p><pre>dice/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── dice.move<br>└── tests/<br>    └── dice_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd dice</pre><p>Replace the contents of sources/dice.move with the code for your module (explained in the following steps).</p><h3>2. Module Definition</h3><pre>module dice::dice;</pre><p>This defines the <strong>dice</strong> module under the dice package. It encapsulates the logic and structure for the dice roll game.</p><h3>3. Struct Definition: DiceRoll</h3><pre>public struct DiceRoll has copy, drop, store {<br>    player: address,<br>    player_roll: u8,<br>    chosen_roll: u8,<br>    outcome: u8, // 0: Loss, 1: Win<br>}</pre><ul><li><strong>player</strong>: The player&#39;s address.</li><li><strong>player_roll</strong>: The randomly generated dice roll.</li><li><strong>chosen_roll</strong>: The number the player chooses.</li><li><strong>outcome</strong>: Indicates whether the player won (1) or lost (0).</li></ul><h3>4. Entry Function: roll</h3><pre>entry fun roll(<br>    chosen_roll: u8,<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Validate player&#39;s chosen number<br>    assert!(chosen_roll &gt;= 1 &amp;&amp; chosen_roll &lt;= 6, INVALID_CHOICE);<br><br>    // Generate the player&#39;s dice roll<br>    let player_roll = generate_dice_roll(random, ctx);<br><br>    // Determine the outcome (Win or Loss)<br>    let outcome = if (player_roll == chosen_roll) { WIN } else { LOSS };<br><br>    // Emit the result as an event<br>    let player = ctx.sender();<br>    event::emit(DiceRoll {<br>        player,<br>        player_roll,<br>        chosen_roll,<br>        outcome,<br>    });<br>}</pre><p><strong>Input Parameters</strong>:</p><ul><li><strong>chosen_roll</strong>: The number (1-6) that the player guesses.</li><li><strong>random</strong>: Reference to the Random object to generate a dice roll.</li><li><strong>ctx</strong>: The transaction context used to identify the player and emit events.</li></ul><p><strong>Process</strong>:</p><ul><li>Validates that the player’s chosen number is between 1 and 6 using assert!.</li><li>Calls the generate_dice_roll function to generate a random dice roll.</li><li>Compares the generated roll (player_roll) with the player&#39;s chosen number (chosen_roll).</li><li>Sets the outcome to WIN if the numbers match, otherwise LOSS.</li></ul><p><strong>Output</strong>:</p><ul><li>Emits a DiceRoll event containing the player&#39;s address, roll result, chosen number, and game outcome.</li></ul><h3>5. Private Function: generate_dice_roll</h3><pre>fun generate_dice_roll(random: &amp;Random, ctx: &amp;mut TxContext): u8 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % 6 + 1) as u8<br>}</pre><p><strong>Purpose</strong>:</p><ul><li>Simulates rolling a six-sided dice.</li></ul><p><strong>Process</strong>:</p><ul><li>Creates a random number generator using the Random object and transaction context (ctx).</li><li>Generates a random unsigned 64-bit integer.</li><li>Reduces it to a range of 1–6 by using the modulo operator % 6 and adding 1.</li></ul><p><strong>Output</strong>:</p><ul><li>Returns a random number between 1 and 6 as an unsigned 8-bit integer (u8).</li></ul><h3>6. Full Source Code</h3><pre>module dice::dice;<br><br>use sui::{<br>    event,<br>    random::Random,<br>};<br><br>/// Struct to store the dice roll result<br>public struct DiceRoll has copy, drop, store {<br>    player: address,<br>    player_roll: u8,<br>    chosen_roll: u8,<br>    outcome: u8, // 0: Loss, 1: Win<br>}<br><br>// === Constants ===<br>const INVALID_CHOICE: u64 = 1;<br>const LOSS: u8 = 0;<br>const WIN: u8 = 1;<br><br>// === Public-Mutative Functions ===<br><br>/// Roll the dice and compare the result with the player&#39;s choice<br>entry fun roll(<br>    chosen_roll: u8,<br>    random: &amp;Random,<br>    ctx: &amp;mut TxContext<br>) {<br>    // Validate player&#39;s chosen number<br>    assert!(chosen_roll &gt;= 1 &amp;&amp; chosen_roll &lt;= 6, INVALID_CHOICE);<br><br>    // Generate the player&#39;s dice roll<br>    let player_roll = generate_dice_roll(random, ctx);<br><br>    // Determine the outcome (Win or Loss)<br>    let outcome = if (player_roll == chosen_roll) { WIN } else { LOSS };<br><br>    // Emit the result as an event<br>    let player = ctx.sender();<br>    event::emit(DiceRoll {<br>        player,<br>        player_roll,<br>        chosen_roll,<br>        outcome,<br>    });<br>}<br><br>// === Private Functions ===<br><br>/// Generate a random dice roll (1 to 6)<br>fun generate_dice_roll(random: &amp;Random, ctx: &amp;mut TxContext): u8 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % 6 + 1) as u8<br>}</pre><h3>7. Deploy the Module</h3><p>Follow these steps to deploy your dice module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0xd2588abd5b95e7938fc55454e9f0454d0fcaa956b24b3832bc54d4a8964b9dec">Package</a></p><h3>8. Interact Using Sui Client CLI</h3><p>Use the following command to test the roll function:</p><pre>sui client call \<br>  --package &lt;PackageId&gt; \<br>  --module dice \<br>  --function roll \<br>  --args &lt;Chosen_Roll&gt; &lt;Random_ObjectId&gt; \<br>  --gas-budget 10000000</pre><ul><li>Replace &lt;PackageId&gt; with your deployed module&#39;s ID.</li><li>Replace &lt;Chosen_Roll&gt; with the player&#39;s chosen number (1-6).</li><li>Replace &lt;Random_ObjectId&gt; with the ID of the Random object.</li></ul><p>For Example</p><pre>sui client call \<br>  --package &#39;0xd2588abd5b95e7938fc55454e9f0454d0fcaa956b24b3832bc54d4a8964b9dec&#39; \<br>  --module dice \<br>  --function roll \<br>  --args 1 &#39;0x0000000000000000000000000000000000000000000000000000000000000008&#39; \<br>  --gas-budget 10000000</pre><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb990b8937f0" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-create-a-dice-game-smart-contract-on-sui-blockchain-using-move-bb990b8937f0">How to Create a Dice Game Smart Contract on Sui Blockchain Using Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Rock-Paper-Scissors Smart Contract on Sui Blockchain Using Move]]></title>
            <link>https://blog.stackademic.com/how-to-build-a-rock-paper-scissors-smart-contract-on-sui-blockchain-using-move-336e988f9c72?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/336e988f9c72</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[rock-paper-scissors]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[move]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Sat, 28 Dec 2024 10:11:04 GMT</pubDate>
            <atom:updated>2025-01-06T06:28:07.001Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsfCgqPYWO3hrfU2fRTP8Q.png" /></figure><p>This tutorial walks you through creating a Rock-Paper-Scissors smart contract using Move on the Sui blockchain. The contract allows players to compete in a game of Rock-Paper-Scissors, with results being randomly generated for the opponent and recorded via events.</p><h3>Introduction</h3><p>Rock-Paper-Scissors is a classic game where players choose between Rock, Paper, or Scissors, and the outcome is determined by simple rules:</p><ul><li>Rock beats Scissors</li><li>Scissors beat Paper</li><li>Paper beats Rock</li></ul><p>This tutorial demonstrates how to:</p><ul><li>Implement a smart contract for the game.</li><li>Use randomness in Move for generating opponent choices.</li><li>Emit events to track game results.</li></ul><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new rps</pre><p>This will create a directory named rps with the following structure:</p><pre>rps/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── rps.move<br>└── tests/<br>    └── rps_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd rps</pre><p>Replace the contents of sources/rps.move with the code for your module (explained in the following steps).</p><h3>2. Module Definition</h3><pre>module rps::rps;</pre><p>This defines the <strong>rps</strong> module under the rps package. It encapsulates the logic and structure for the rock paper scissors game.</p><h3>3. Struct Definition: GameResult</h3><pre>public struct GameResult has copy, drop, store {<br>    player: address,<br>    player_choice: u8,<br>    opponent_choice: u8,<br>    outcome: u8,<br>}</pre><ul><li><strong>player</strong>: The player&#39;s address.</li><li><strong>player_choice</strong>: The choice made by the player (1 for Rock, 2 for Paper, 3 for Scissors).</li><li><strong>opponent_choice</strong>: The randomly generated choice for the opponent.</li><li><strong>outcome</strong>: The result of the game (0 for a draw, 1 for a win, 2 for a loss).</li></ul><h3>4. Function: generate_choice</h3><pre>fun generate_choice(random: &amp;Random, ctx: &amp;mut TxContext): u8 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % 3 + 1) as u8<br>}</pre><p>Uses randomness to generate a number between 1 and 3 representing the opponent&#39;s choice.</p><h3>5. Function: determine_outcome</h3><pre>fun determine_outcome(player_choice: u8, opponent_choice: u8): u8 {<br>    if (player_choice == opponent_choice) {<br>        DRAW<br>    } else if (<br>            (player_choice == 1 &amp;&amp; opponent_choice == 3) || // Rock beats Scissors<br>            (player_choice == 2 &amp;&amp; opponent_choice == 1) || // Paper beats Rock<br>            (player_choice == 3 &amp;&amp; opponent_choice == 2)    // Scissors beats Paper<br>    ) {<br>        WIN<br>    } else {<br>        LOSS<br>    }<br>}</pre><ul><li>Compares the player’s choice with the opponent’s choice to determine the outcome.</li><li>Returns 0 for a draw, 1 for a win, and 2 for a loss.</li></ul><h3>6. Entry Function: play</h3><pre>entry fun play(<br>    random: &amp;Random,<br>    player_choice: u8,<br>    ctx: &amp;mut TxContext<br>) {<br>    assert!(player_choice &gt;= 1 &amp;&amp; player_choice &lt;= 3, INVALID_CHOICE);<br><br>    let opponent_choice = generate_choice(random, ctx);<br>    let outcome = determine_outcome(player_choice, opponent_choice);<br>    let player = ctx.sender();<br><br>    event::emit(GameResult {<br>        player,<br>        player_choice,<br>        opponent_choice,<br>        outcome,<br>    });<br>}</pre><ul><li>Ensures the player’s choice is valid (1, 2, or 3).</li><li>Generates the opponent’s choice and determines the game’s outcome.</li><li>Emits a GameResult event containing the player&#39;s address, choices, and the outcome.</li></ul><h3>7. Full Source Code</h3><pre>module rps::rps;<br><br>use sui::{<br>    random::Random,<br>    event,<br>};<br><br>/// Struct to store game result<br>public struct GameResult has copy, drop, store {<br>    player: address,<br>    player_choice: u8,<br>    opponent_choice: u8,<br>    outcome: u8,<br>}<br>const INVALID_CHOICE: u64 = 1;<br>const DRAW: u8 = 0;<br>const WIN: u8 = 1;<br>const LOSS: u8 = 2;<br><br>// === Public-Mutative Functions ===<br><br>/// Play a game of Rock-Paper-Scissors<br>entry fun play(<br>    random: &amp;Random,<br>    player_choice: u8,<br>    ctx: &amp;mut TxContext<br>) {<br>    assert!(player_choice &gt;= 1 &amp;&amp; player_choice &lt;= 3, INVALID_CHOICE);<br><br>    let opponent_choice = generate_choice(random, ctx);<br>    let outcome = determine_outcome(player_choice, opponent_choice);<br>    let player = ctx.sender();<br><br>    event::emit(GameResult {<br>        player,<br>        player_choice,<br>        opponent_choice,<br>        outcome,<br>    });<br>}<br><br>// === Private Functions ===<br><br>/// Generate the opponent&#39;s random choice (1: Rock, 2: Paper, 3: Scissors)<br>fun generate_choice(random: &amp;Random, ctx: &amp;mut TxContext): u8 {<br>    let mut gen = random.new_generator(ctx);<br>    (gen.generate_u64() % 3 + 1) as u8<br>}<br><br>/// Determine the outcome of the game<br>fun determine_outcome(player_choice: u8, opponent_choice: u8): u8 {<br>    // Determine outcome<br>    if (player_choice == opponent_choice) {<br>        DRAW<br>    } else if (<br>            (player_choice == 1 &amp;&amp; opponent_choice == 3) || // Rock beats Scissors<br>            (player_choice == 2 &amp;&amp; opponent_choice == 1) || // Paper beats Rock<br>            (player_choice == 3 &amp;&amp; opponent_choice == 2)    // Scissors beats Paper<br>    ) {<br>        WIN<br>    } else {<br>        LOSS<br>    }<br>}</pre><h3>8. Deploy the Module</h3><p>Follow these steps to deploy your rps module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0xcffbbb6c9c46003603f7c963c9f17ab26f1805d32128d94b43a4c5d632b685fc">Package</a></p><h3>9. Interact Using Sui Client</h3><p>Use the following command to test the play function:</p><pre>sui client call \<br>  --package &lt;PackageId&gt; \<br>  --module rps \<br>  --function play \<br>  --args &lt;Random_ObjectId&gt; 2 \<br>  --gas-budget 10000000</pre><ul><li>Replace &lt;PackageId&gt; with the ID of your deployed rps module.</li><li>Replace &lt;Random_ObjectId&gt; with the ID of the Random object.</li><li>The last argument (2) is the player&#39;s choice (e.g., 1 for Rock, 2 for Paper, 3 for Scissors).</li></ul><p>For Example</p><pre>sui client call \<br>  --package &quot;0xcffbbb6c9c46003603f7c963c9f17ab26f1805d32128d94b43a4c5d632b685fc&quot; \<br>  --module rps \<br>  --function play \<br>  --args &quot;0x0000000000000000000000000000000000000000000000000000000000000008&quot; 2 \<br>  --gas-budget 10000000</pre><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=336e988f9c72" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-build-a-rock-paper-scissors-smart-contract-on-sui-blockchain-using-move-336e988f9c72">How to Build a Rock-Paper-Scissors Smart Contract on Sui Blockchain Using Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Coin Flip Game Smart Contract on Sui Blockchain Using Move]]></title>
            <link>https://blog.stackademic.com/how-to-build-a-coin-flip-game-smart-contract-on-sui-blockchain-using-move-96a4ea011a20?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/96a4ea011a20</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[move]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[coin-flip]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Fri, 27 Dec 2024 18:21:28 GMT</pubDate>
            <atom:updated>2025-01-06T06:28:02.389Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsfCgqPYWO3hrfU2fRTP8Q.png" /></figure><p>This tutorial explains how to create a coin flip smart contract using Move on the Sui blockchain. The contract allows players to bet on the outcome of a virtual coin flip, and it emits events to record the results.</p><h3>Introduction</h3><p>The coin flip game is a simple betting game where players predict the outcome of a coin toss. This tutorial demonstrates how to:</p><ul><li>Implement a smart contract module for the coin flip game.</li><li>Use randomness in Move for generating outcomes.</li><li>Emit events to track results.</li></ul><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new coinflip</pre><p>This will create a directory named coinflip with the following structure:</p><pre>coinflip/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── coinflip.move<br>└── tests/<br>    └── coinflip_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd coinflip</pre><p>Replace the contents of sources/coinflip.move with the code for your module (explained in the following steps).</p><h3>2. Module Definition</h3><pre>module coinflip::coinflip;</pre><p>This defines the <strong>CoinFlip</strong> module under the coinflip package. It encapsulates the logic and structure for the coin flip game.</p><h3>3. Imports SUI event and random</h3><pre>use sui::{<br>    event,<br>    random::Random<br>};</pre><ul><li><strong>event</strong>: Allows the contract to emit events, which are useful for logging and tracking on-chain actions.</li><li><strong>random::Random</strong>: Provides random number generation capabilities, essential for implementing the coin flip logic.</li></ul><h3>4. Struct Definition: Flip</h3><pre>public struct Flip has copy, drop, store {<br>    player: address,<br>    player_won: bool,<br>    bet: bool,<br>}</pre><p>The Flip struct represents the outcome of a coin flip. It includes:</p><ul><li>player: The address of the player who flipped the coin.</li><li>player_won: A boolean indicating whether the player&#39;s prediction matched the coin flip result.</li><li>bet: The player&#39;s prediction (true for heads, false for tails).</li></ul><p><strong>Access Modifiers:</strong></p><ul><li>public: The struct is accessible outside the module.</li><li>has copy, drop, store: Specifies the struct&#39;s storage and memory capabilities:</li><li>copy: Instances of Flip can be copied.</li><li>drop: Instances can be discarded.</li><li>store: Instances can be stored in the Sui blockchain&#39;s storage.</li></ul><h3>5. Private Function: flip_impl</h3><p>This function implements the core logic for the coin flip.</p><pre>fun flip_impl(<br>    random: &amp;Random, <br>    bet: bool, <br>    ctx: &amp;mut TxContext<br>): bool {<br>    let mut gen = random.new_generator(ctx);<br><br>    let result = gen.generate_bool();<br><br>    result == bet<br>}</pre><p><strong>Inputs</strong>:</p><ul><li>random: A reference to the Sui Random object, used to generate random values.</li><li>bet: The player&#39;s prediction (true or false).</li><li>ctx: The transaction context, required for creating or managing on-chain resources.</li></ul><p><strong>Logic</strong>:</p><ul><li>Creates a random generator using the random.new_generator(ctx) method.</li><li>Generates a random boolean value (true or false).</li><li>Compares the generated value (result) with the player&#39;s bet and returns whether they match.</li></ul><p><strong>Output</strong>:</p><ul><li>Returns true if the player won (prediction matched the result).</li><li>Returns false otherwise.</li></ul><h3>6. Entry Function: flip</h3><pre>entry fun flip(random: &amp;Random, bet: bool, ctx: &amp;mut TxContext) {<br>    let player_won = flip_impl(random, bet, ctx);<br>    let player = ctx.sender();<br><br>    event::emit(Flip {<br>        player,<br>        player_won,<br>        bet,<br>    });<br>}</pre><p>This is the public entry point for flipping the coin.</p><p><strong>Inputs</strong>:</p><ul><li>random: A reference to the Sui Random object.</li><li>bet: The player&#39;s prediction for the coin flip.</li><li>ctx: The transaction context.</li></ul><p><strong>Logic</strong>:</p><ol><li>Calls flip_impl to determine if the player won.</li><li>Retrieves the address of the player using ctx.sender().</li><li>Emits a Flip event with the player&#39;s address, whether they won, and their bet.</li></ol><p><strong>Event Emission</strong>:</p><pre>event::emit(Flip {<br>    player,<br>    player_won,<br>    bet,<br>});</pre><ul><li>The Flip event logs the result of the coin flip to the blockchain.</li></ul><h3>7. Full Source Code</h3><pre>module coinflip::coinflip;<br><br>use sui::{<br>    event,<br>    random::Random<br>};<br><br>public struct Flip has copy, drop, store {<br>    player: address,<br>    player_won: bool,<br>    bet: bool,<br>}<br><br>// === Private Functions ===<br>fun flip_impl(<br>    random: &amp;Random, <br>    bet: bool, <br>    ctx: &amp;mut TxContext<br>): bool {<br>    let mut gen = random.new_generator(ctx);<br><br>    let result = gen.generate_bool();<br><br>    result == bet<br>}<br><br>// === Public-Mutative Functions ===<br>entry fun flip(random: &amp;Random, bet: bool, ctx: &amp;mut TxContext) {<br>    let (player_won) = flip_impl(random,  bet, ctx);<br>    let player = ctx.sender();<br><br>    event::emit(Flip {<br>        player,<br>        player_won,<br>        bet<br>    });<br>}</pre><h3>8. Deploy the Module</h3><p>Follow these steps to deploy your coinflip module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0xdf9fe77476b037e4d18850983811af3585d111e13758d36ed56fa6bca50eee53">Package</a></p><h3>9. Interact Using Sui Client</h3><p>Use the following command to test the flip function:</p><pre>sui client call \<br>  --package &lt;PackageId&gt; \<br>  --module coinflip \<br>  --function flip \<br>  --args &lt;Random_ObjectId&gt; true \<br>  --gas-budget 10000000</pre><ul><li>Replace &lt;PackageId&gt; with the ID of your deployed coinflip module.</li><li>Replace &lt;Random_ObjectId&gt; with the ID of the Random object.</li><li>The last argument (true) is the player&#39;s bet (true for heads, false for tails).</li></ul><p>Example</p><pre>sui client call --package 0xdf9fe77476b037e4d18850983811af3585d111e13758d36ed56fa6bca50eee53 \<br>    --module coinflip \<br>    --function flip \<br>    --args &quot;0x0000000000000000000000000000000000000000000000000000000000000008&quot; true \<br>    --gas-budget 10000000</pre><h3>Conclusion</h3><p>You have successfully created a coin flip smart contract on the Sui blockchain. This contract uses randomness for fair results and emits events to log outcomes.</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96a4ea011a20" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-build-a-coin-flip-game-smart-contract-on-sui-blockchain-using-move-96a4ea011a20">How to Build a Coin Flip Game Smart Contract on Sui Blockchain Using Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create an NFT Smart Contract on Sui Blockchain Using Move]]></title>
            <link>https://blog.stackademic.com/how-to-create-an-nft-smart-contract-on-sui-blockchain-using-move-f1e88e160259?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1e88e160259</guid>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[move]]></category>
            <category><![CDATA[sui]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Fri, 27 Dec 2024 06:14:23 GMT</pubDate>
            <atom:updated>2025-01-06T06:27:57.746Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsfCgqPYWO3hrfU2fRTP8Q.png" /></figure><p>This tutorial walks you through the process of creating an NFT smart contract using Move on the Sui blockchain. The module allows users to mint, transfer, update, and burn NFTs with essential metadata such as name, description, and URL.</p><h3>Introduction</h3><p>An NFT (Non-Fungible Token) is a unique digital asset representing ownership of specific items or data. This smart contract defines an example NFT structure that can be minted by anyone on the Sui blockchain. It also includes utility functions to manage and interact with the NFTs.</p><h3>Features of the NFT Smart Contract:</h3><ul><li>Mint NFTs with a name, description, and URL.</li><li>Transfer NFTs to another address.</li><li>Update the description of an NFT.</li><li>Burn an NFT to remove it permanently.</li></ul><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new nft</pre><p>This will create a directory named nft with the following structure:</p><pre>nft/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── nft.move<br>└── tests/<br>    └── nft_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd nft</pre><p>Replace the contents of sources/nft.move with the code for your module (explained in the following steps).</p><h3>2. Define the NFT Structure</h3><p>In the sources/nft.move file, define the NFT structure:</p><pre>module nft::nft;<br><br>use std::string;<br>use sui::{event, url::{Self, Url}};<br><br>/// An example NFT that can be minted by anybody<br>public struct NFT has key, store {<br>    id: UID,<br>    /// Name for the token<br>    name: string::String,<br>    /// Description of the token<br>    description: string::String,<br>    /// URL for the token<br>    url: Url,<br>}</pre><p><strong>Breakdown:</strong></p><ol><li><strong>UID</strong>: Each NFT has a unique identifier.</li><li><strong>name</strong>: A human-readable name for the NFT.</li><li><strong>description</strong>: A short description providing details about the NFT.</li><li><strong>url</strong>: A URL pointing to the NFT&#39;s associated media or metadata.</li></ol><h3>3. Add NFT Events</h3><p>Define an event to emit whenever an NFT is minted:</p><pre>public struct NFTMinted has copy, drop {<br>    /// The Object ID of the NFT<br>    object_id: ID,<br>    /// The creator of the NFT<br>    creator: address,<br>    /// The name of the NFT<br>    name: string::String,<br>}</pre><p>This event logs information about the minted NFT, including its ID, creator’s address, and name.</p><h3>4. Public View Functions</h3><p>Add utility functions to retrieve NFT properties:</p><pre>/// Get the NFT&#39;s `name`<br>public fun name(nft: &amp;NFT): &amp;string::String {<br>    &amp;nft.name<br>}<br><br>/// Get the NFT&#39;s `description`<br>public fun description(nft: &amp;NFT): &amp;string::String {<br>    &amp;nft.description<br>}<br><br>/// Get the NFT&#39;s `url`<br>public fun url(/service/nft: &amp;NFT): &amp;Url {<br>    &amp;nft.url<br>}</pre><p>These functions allow users to query the name, description, and url of an NFT.</p><h3>5. Entrypoint Functions</h3><h4><strong>Mint an NFT</strong></h4><pre>#[allow(lint(self_transfer))]<br>public fun mint_to_sender(<br>    name: vector&lt;u8&gt;,<br>    description: vector&lt;u8&gt;,<br>    url: vector&lt;u8&gt;,<br>    ctx: &amp;mut TxContext,<br>) {<br>    let sender = ctx.sender();<br>    let nft = NFT {<br>        id: object::new(ctx),<br>        name: string::utf8(name),<br>        description: string::utf8(description),<br>        url: url::new_unsafe_from_bytes(url),<br>    };<br><br>    event::emit(NFTMinted {<br>        object_id: object::id(&amp;nft),<br>        creator: sender,<br>        name: nft.name,<br>    });<br><br>    transfer::public_transfer(nft, sender);<br>}</pre><p>This function mints a new NFT and transfers it to the creator’s address. It emits an NFTMinted event.</p><h4>Transfer an NFT</h4><pre>public fun transfer(nft: NFT, recipient: address, _: &amp;mut TxContext) {<br>    transfer::public_transfer(nft, recipient)<br>}</pre><p>This function transfers an NFT to a specified recipient address.</p><h4>Update the Description</h4><pre>public fun update_description(<br>    nft: &amp;mut NFT,<br>    new_description: vector&lt;u8&gt;,<br>    _: &amp;mut TxContext,<br>) {<br>    nft.description = string::utf8(new_description);<br>}</pre><p>This function updates the description field of the NFT.</p><h4>Burn the NFT</h4><pre>public fun burn(nft: NFT, _: &amp;mut TxContext) {<br>    let NFT { id, name: _, description: _, url: _ } = nft;<br>    id.delete();<br>}</pre><p>This function deletes an NFT permanently.</p><h3>6. Full Source Code</h3><pre>module nft::nft;<br><br>use std::string;<br>use sui::{event, url::{Self, Url}};<br><br>/// An example NFT that can be minted by anybody<br>public struct NFT has key, store {<br>    id: UID,<br>    /// Name for the token<br>    name: string::String,<br>    /// Description of the token<br>    description: string::String,<br>    /// URL for the token<br>    url: Url,<br>}<br><br>// ===== Events =====<br><br>public struct NFTMinted has copy, drop {<br>    /// The Object ID of the NFT<br>    object_id: ID,<br>    /// The creator of the NFT<br>    creator: address,<br>    /// The name of the NFT<br>    name: string::String,<br>}<br><br>// ===== Public view functions =====<br><br>/// Get the NFT&#39;s `name`<br>public fun name(nft: &amp;NFT): &amp;string::String {<br>    &amp;nft.name<br>}<br><br>/// Get the NFT&#39;s `description`<br>public fun description(nft: &amp;NFT): &amp;string::String {<br>    &amp;nft.description<br>}<br><br>/// Get the NFT&#39;s `url`<br>public fun url(/service/nft: &amp;NFT): &amp;Url {<br>    &amp;nft.url<br>}<br><br>// ===== Entrypoints =====<br><br>#[allow(lint(self_transfer))]<br>/// Create a new testnet_nft<br>public fun mint_to_sender(<br>    name: vector&lt;u8&gt;,<br>    description: vector&lt;u8&gt;,<br>    url: vector&lt;u8&gt;,<br>    ctx: &amp;mut TxContext,<br>) {<br>    let sender = ctx.sender();<br>    let nft = NFT {<br>        id: object::new(ctx),<br>        name: string::utf8(name),<br>        description: string::utf8(description),<br>        url: url::new_unsafe_from_bytes(url),<br>    };<br><br>    event::emit(NFTMinted {<br>        object_id: object::id(&amp;nft),<br>        creator: sender,<br>        name: nft.name,<br>    });<br><br>    transfer::public_transfer(nft, sender);<br>}<br><br>/// Transfer `nft` to `recipient`<br>public fun transfer(nft: NFT, recipient: address, _: &amp;mut TxContext) {<br>    transfer::public_transfer(nft, recipient)<br>}<br><br>/// Update the `description` of `nft` to `new_description`<br>public fun update_description(<br>    nft: &amp;mut NFT,<br>    new_description: vector&lt;u8&gt;,<br>    _: &amp;mut TxContext,<br>) {<br>    nft.description = string::utf8(new_description)<br>}<br><br>/// Permanently delete `nft`<br>public fun burn(nft: NFT, _: &amp;mut TxContext) {<br>    let NFT { id, name: _, description: _, url: _ } = nft;<br>    id.delete()<br>}</pre><h3>7. Deploy the Module</h3><p>Follow these steps to deploy your nft module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 100000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0x949df1bcdfcc24107fd8b72e7276ff416474921451d87d67f6ac5a45c1ae09eb">Package</a></p><p>By the end of this tutorial, you’ll have a functional NFT module deployed on Sui, enabling you to create and manage unique digital assets.</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1e88e160259" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-create-an-nft-smart-contract-on-sui-blockchain-using-move-f1e88e160259">How to Create an NFT Smart Contract on Sui Blockchain Using Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating and Deploying a Custom Coin on Sui Blockchain Using Move]]></title>
            <link>https://blog.stackademic.com/creating-and-deploying-a-custom-coin-on-sui-blockchain-using-move-48d681f30a77?source=rss-1a0a4c76d13e------2</link>
            <guid isPermaLink="false">https://medium.com/p/48d681f30a77</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[sui]]></category>
            <category><![CDATA[move]]></category>
            <category><![CDATA[coins]]></category>
            <dc:creator><![CDATA[Ryan Adhitama Putra]]></dc:creator>
            <pubDate>Thu, 26 Dec 2024 03:37:20 GMT</pubDate>
            <atom:updated>2025-01-06T06:27:53.219Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsfCgqPYWO3hrfU2fRTP8Q.png" /></figure><p>In this tutorial, you will learn how to create a custom coin on the Sui blockchain using the Move programming language. We will define a new coin module called RYN that represents a fungible token with customizable properties such as the coin&#39;s name, symbol, and decimal precision. By the end of this guide, you&#39;ll have a fully functioning custom token that can be minted, transferred, and used within your Sui-based applications.</p><p>The Sui blockchain’s unique object-centric model and Move’s resource-oriented programming approach make it ideal for building secure and efficient token contracts. Whether you’re creating a utility token for your decentralized app or experimenting with tokenomics, this guide provides a solid foundation for your coin development.</p><h3>Prerequisites</h3><p>Before diving into the coding, make sure you have the following set up:</p><ul><li><strong>Sui CLI</strong>: Required for deploying contracts. <a href="https://docs.sui.io/guides/developer/getting-started/sui-install">Install Sui CLI</a>.</li><li><strong>Code Editor</strong>: A good editor like VS Code or IntelliJ with the Move plugin.</li></ul><h3>1. Set Up a Sui Move Project</h3><p>Run the following command to scaffold a new Sui Move project:</p><pre>sui move new coins</pre><p>This will create a directory named coins with the following structure:</p><pre>coins/<br>├── Move.lock<br>├── Move.toml<br>├── sources/<br>│   └── coins.move<br>└── tests/<br>    └── coins_tests.move</pre><p>Navigate to the Project Directory</p><pre>cd coins</pre><p>Replace the contents of sources/coins.move with the code for your module (explained in the following steps).</p><h3>2. <strong>Create the Module</strong></h3><p>We start by defining a new module in the Move language. The module serves as the container for the custom coin logic.</p><pre>module coins::ryn;</pre><p>Here, coins is the package name, and ryn is the module name. This is where we’ll implement all the functionality for our custom coin.</p><h3>3. Importing Dependencies</h3><pre>use sui::coin;</pre><ul><li><strong>sui::coin</strong>: This module provides utility functions for creating and managing custom coins in the Sui framework.</li></ul><h3>4. Defining the Coin Struct</h3><pre>public struct RYN has drop {}</pre><ul><li><strong>RYN</strong>: This is the struct representing your custom coin.</li><li><strong>has drop</strong>: The drop ability is essential for objects that need to be created, transferred, or destroyed.</li></ul><h3>5. Initialization Function</h3><p><strong>Purpose</strong>: The init function initializes the RYN coin, mints the first supply, and transfers it to the creator&#39;s account.</p><pre>#[allow(lint(share_owned))]<br>fun init(witness: RYN, ctx: &amp;mut TxContext) {<br>    let (treasury, metadata) = coin::create_currency(<br>        witness, 9, b&quot;RYN&quot;, b&quot;Ryn&quot;, <br>        b&quot;&quot;, option::none(), ctx<br>    );<br>    <br>    transfer::public_share_object(metadata);<br>    transfer::public_transfer(treasury, ctx.sender())<br>}</pre><p><strong>Parameters:</strong></p><ul><li><strong>witness: RYN</strong>: A &quot;proof&quot; that the struct RYN is valid for creating the coin.</li><li><strong>ctx: &amp;mut TxContext</strong>: A mutable transaction context to track object creation and operations.</li></ul><p><strong>coin::create_currency: </strong>This function creates a new currency with specific parameters:</p><ul><li>witness: Type of the coin being created.</li><li>9: Number of decimal places for the token (e.g., 1 RYN = 1,000,000,000 smallest units).</li><li>b&quot;RYN&quot;: Coin&#39;s symbol.</li><li>b&quot;Ryn&quot;: Coin&#39;s name.</li><li>b&quot;&quot;: Optional metadata URL (empty here).</li><li>option::none(): No additional options provided.</li><li>ctx: Transaction context.</li></ul><p><strong>The function returns two objects:</strong></p><ul><li><strong>treasury</strong>: The initial supply of the token.</li><li><strong>metadata</strong>: Metadata object for the coin, including name, symbol, and decimals.</li></ul><p><strong>Making Objects Public:</strong></p><pre>transfer::public_share_object(metadata);</pre><p>Shares the metadata object publicly so others can query or interact with it.</p><p><strong>Transferring Initial Coins:</strong></p><pre>transfer::public_transfer(treasury, ctx.sender())</pre><p>Transfers the treasury (initial supply) to the transaction sender.</p><p><strong>Here is The Full Code</strong></p><pre>module coins::ryn;<br><br>use sui::coin;<br><br>public struct RYN has drop {}<br><br>#[allow(lint(share_owned))]<br>fun init(witness: RYN, ctx: &amp;mut TxContext) {<br>    let (treasury, metadata) = coin::create_currency(<br>        witness, 9, b&quot;RYN&quot;, b&quot;Ryn&quot;, <br>        b&quot;&quot;, option::none(), ctx<br>    );<br>    <br>    transfer::public_share_object(metadata);<br>    transfer::public_transfer(treasury, ctx.sender())<br>}</pre><h3>6. Deploy the Module</h3><p>Follow these steps to deploy your coins module:</p><p><strong>Compile the Contract</strong><br>Navigate to the project directory and run:</p><pre>sui move build</pre><p><strong>Publish the Contract</strong><br>Use the Sui CLI to publish the module:</p><pre>sui client publish --gas-budget 10000000</pre><p><strong>Deployed Package</strong></p><p><a href="https://testnet.suivision.xyz/package/0xbc09655049c4b3145a84bc8160c225db899c0813531d2f84c2f0c38d0514a530">Package</a></p><h3>Summary</h3><p>This custom coin module:</p><ol><li>Uses the sui::coin library to create a new coin type with customizable properties.</li><li>Defines the RYN coin struct as the core type of the module.</li><li>Provides an init function to mint the initial supply of RYN tokens and transfer them to the creator.</li></ol><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48d681f30a77" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/creating-and-deploying-a-custom-coin-on-sui-blockchain-using-move-48d681f30a77">Creating and Deploying a Custom Coin on Sui Blockchain Using Move</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>