Skip to content

Commit

Permalink
iota-move-raffle-tutorial: small rearrangements
Browse files Browse the repository at this point in the history
  • Loading branch information
teunvw14 committed Dec 25, 2024
1 parent a15349c commit c2eb56c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions content/posts/iota-move-raffle-tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ You might be able to come up with some more useful functionality - we'll keep it

# Writing the raffle smart contract

## Starting out: Creating the `Raffle` and `RaffleTicket` structs

Let's get to writing the raffle smart contract. Create a new IOTA Move project, and open up the newly created folder in your code editor.

```bash
Expand All @@ -39,6 +37,8 @@ $ cd raffle
$ code .
```

## Starting out: Creating the `Raffle` and `RaffleTicket` structs

Let's start out by defining a `Raffle` struct and a `RaffleTicket` struct in `sources/raffle.move`. Make sure to add the `use` imports at the top, we will need those later.

```rust
Expand Down Expand Up @@ -267,7 +267,9 @@ $ iota client ptb --move-call $PACKAGE_ID::raffle::create_raffle \
'<0x2::iota::IOTA>' $TICKET_PRICE_NANO $RAFFLE_DURATION_S @0x6
```

This command should show you that the `Raffle` has been created. Make sure to export the `Raffle`'s ObjectID (see image below) as an environment variable `RAFFLE_ID`. We will need it in the next few commands.
Here, `0x6` is the address of the shared `Clock` object. Because it's an address, the IOTA Client PTB CLI requires us to prefix this hex value with an `@`.

The above command should give you output showing that the `Raffle` has been created. Make sure to export the `Raffle`'s ObjectID (see image below) as an environment variable `RAFFLE_ID`. We will need it in the next few commands.

![The Raffle ObjectID in the command output](raffle-id.png)

Expand All @@ -283,7 +285,7 @@ The output of this command should show you that a `RaffleTicket` was created. Ex

![The RaffleTicket ObjectID in the command output](raffle-ticket-id.png)

Then, to determine who's won the raffle (it's probably you!), resolve the raffle by calling the `resolve` function. If you do this fast enough (or if you set a really high raffle duration), you will get an error with code `0 = ERaffleNotResolvableYet`. This is good; it means that the raffle is working as intended! Wait a little longer and try again. (Or create a new raffle that has a shorter duration.)
Then, to determine who's won the raffle (it's probably you!), resolve the raffle by calling the `resolve` function. If you do this fast enough (or if you set a really high raffle duration), you will get an error with code `0 = ERaffleNotResolvableYet`. This is good; it means that the raffle is working as intended! Wait a little longer and try again. (Or create a new raffle that has a shorter duration.) Here again we have to pass in the `Clock` shared object at address `0x6`, but also the `Random` shared object, which is at address `0x8`.
```bash
$ iota client ptb --move-call $PACKAGE_ID::raffle::resolve \
'<0x2::iota::IOTA>' @$RAFFLE_ID @0x6 @0x8
Expand Down

0 comments on commit c2eb56c

Please sign in to comment.