Step 4b

Interacting with the contracts with our own scripts and the Sui Typescript SDK

Figure out how to get the flag

Take a look at the smart contract source code

The first step in figuring out how to get the flag is view the source code. The source code was provided was the event and can be viewed herearrow-up-right. Navigate to Module.move in the source directory to find the module source code.

sources/module.move
module movectf::checkin {
  use sui::event;
  use sui::tx_context::{Self, TxContext};

  struct Flag has copy, drop {
      user: address,
      flag: bool
  }

  public entry fun get_flag(ctx: &mut TxContext) {
      event::emit(Flag {
          user: tx_context::sender(ctx),
          flag: true
      })
  }
}

In the source code of the deployed module called movectf::checkin, you can see that the get_flag() function. When looking in the body of the function, you can see that the Flag event is emitted when the function is called.

You can also see that the function has the entry function modifier. This modifier means that this function can be called via a script. Functions without this modifier can only be called by other Modules on the chain.

Note that the function has a parameter, ctx: &mut TxContext . The the TxContext holds information about the transactions used to interact with the module's function and is automatically given to the module during each interaction. In this function, the sender of the transaction (the address of the account that called the function) is being used in the Flag event emittance.

Get the flag

Build script to interact with the deployed Move module

We need to build a script to interact with the Sui blockchain and call the get_flag() function. In this writeup, the scripts that will be used to interact with the modules will be written in Typescript.

Use the script to call the get_flag() function

Results from calling the script:

View the transaction on the Sui blockchain explorer

The results from the script shows the dev address as well as the transaction information, including the transaction hash which we could use to look up the transaction in the Sui block explorer.

The explorer page for the transaction with the module
The explorer page showing the events emitted during the transaction. The Flag event is emitted. Note that the user attribute is listed which we could see in the module source code.

Submit transaction hash

The transaction hash associated with the transaction where the Flag event was emitted can now be submitted.

The confirmation of the flag event being emitted in the submitted transaction hash

Last updated