Mastering Sui DeepBook: A Hands-On DeFi DEX Series (2)
Source: Dev.to
Environment Setup
In this section, we will install the necessary tools and dependencies to begin working with Sui DeepBook.
Bootstrapping the Boilerplate
First, set up the boilerplate for our Sui DeepBook contract. This provides a starting point for smart‑contract development.
-
Open your terminal.
-
Clone the boilerplate repository (using the
templatebranch):git clone -b template https://github.com/Rajesh-Royal/SUI-Deepbookv3-Dex -
Change into the boilerplate directory:
cd SUI-Deepbookv3-Dex
Now the boilerplate is ready. Next, install the required tools and dependencies.
Installing Sui and Dev Tools
The first step is to install Sui, Move, and the necessary development tools. Follow the instructions for your operating system.
Installing on Codespaces (Ubuntu/Debian)
If you are using GitHub Codespaces or a Linux environment:
Install required dependencies
sudo apt update
sudo apt install curl git-all cmake gcc libssl-dev pkg-config libclang-dev libpq-dev build-essential -y
Install Rust and Cargo
curl https://sh.rustup.rs -sSf | sh
When prompted, type 1 and press Enter. Then configure your shell:
source "$HOME/.cargo/env"
Install Sui binaries
cargo install --locked --git https://github.com/MystenLabs/sui.git --branch devnet sui
Verify the installation
sui --version
Installing on macOS
Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install Sui
brew install sui
Verify the installation
sui --version
Understanding the Boilerplate Code
Now that the boilerplate is set up, let’s explore its structure and the purpose of each file, preparing the main.move file for our Sui DeepBook contract.
Boilerplate Code Structure
The contract directory should have the following layout:
SUI-Deepbookv3-Dex
├── contract
│ ├── sources
│ │ ├── main-test.move
│ │ ├── main.move
│ │ ├── wbtc.move
│ ├── Move.toml
│ ├── contract-publish.sh
│ ├── README.md
└── package.json
File descriptions
sources/main-test.move– Placeholder for unit tests related to the main contract.sources/main.move– The main contract file where the Sui DeepBook logic will be implemented (currently empty).sources/wbtc.move– Example module implementing a wrapped Bitcoin (WBTC) token, showing initialization, minting, and burning functions.Move.toml– Package manifest that defines dependencies on the Sui and DeepBook frameworks and assigns a blockchain address to the contract.contract-publish.sh– Script that automates building and publishing the contract, extracting necessary information from the build output and setting environment variables for later use.