Welcome back to the Mastering Sui DeepBook series!
In Part 1, we introduced the core concepts of the Sui blockchain, the Move programming language, and the DeepBook protocol. We outlined what we're going to build: a fully functional Decentralised Exchange (DEX) leveraging DeepBook's central limit order book (CLOB) architecture.
In this second instalment, we will roll up our sleeves and get our hands dirty. We'll set up our development environment, install the necessary tools, and bootstrap the project boilerplate. By the end of this tutorial, you'll have a working local environment ready for smart contract development.
Environment Setup
In this section, we will install the necessary tools and dependencies to begin working with Sui DeepBook.
Bootstrapping the Boilerplate
Firstly, let's set up the boilerplate for our Sui DeepBook contract. This boilerplate provides a starting point for your smart contract development.
Open your terminal.
Clone the boilerplate repository using the following command. We use the
templatebranch which contains the starter code:
git clone -b template https://github.com/Rajesh-Royal/SUI-Deepbookv3-Dex
- Change into the boilerplate directory:
cd SUI-Deepbookv3-Dex
Now we have the boilerplate set up, let's explore installing the necessary tools and dependencies.
Installing Sui and Dev Tools
The first step is to install Sui, Move, and the necessary dev tools. Follow the instructions below based on your operating system.
Installing on Codespaces (Ubuntu/Debian)
If you are using GitHub Codespaces or a Linux environment, follow these steps.
- Install Required Dependencies Run the following commands to install the 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 Run the following command to install Rust and Cargo.
curl https://sh.rustup.rs -sSf | sh
Type 1 and press Enter when prompted. After installation, configure your shell:
source "$HOME/.cargo/env"
- Install Sui Binaries You can install Sui directly using Cargo (this may take a while):
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 Installation
sui --version
Understanding the Boilerplate Code
Now that we've set up the boilerplate, let's explore the structure of the provided code, understand the purpose of each file, and prepare the main.move file for our Sui DeepBook contract.
Boilerplate Code Structure
You should see the following code structure in your contract directory:
SUI-Deepbookv3-Dex
├── contract
│ ├── sources
│ │ ├── main-test.move
│ │ ├── main.move
│ │ ├── wbtc.move
│ ├── Move.toml
│ ├── contract-publish.sh
│ ├── README.md
└── package.json
Let's explore the purpose of each file inside the contract folder:
-
sources/main-test.move: An empty file for potential unit tests related to the main contract. -
sources/main.move: The main file where our Sui DeepBook contract will be implemented. This file is currently empty but will be populated in the next section. -
sources/wbtc.move: Thewbtc.movefile contains a basic implementation of a wrapped Bitcoin (WBTC) module. It showcases the structure of a token on the Sui blockchain, including initialization, minting, and burning functions. -
Move.toml: This file defines the package information for our smart contract. It specifies dependencies on the Sui and DeepBook frameworks, which provide essential functionalities for blockchain development. Additionally, it assigns an address to our smart contract on the blockchain. -
contract-publish.sh: This script automates the build and publishing process of the smart contract. It extracts necessary information from the build output and sets environment variables for subsequent use.
Top comments (0)