
In this tutorial, we will develop a simple storage contract that can be updated by an admin and can be used to retrieve information. This is the first tutorial in the Step-by-Step with Rift series, where we will discuss the basic primitives in Rift.
Getting Started
Install Rift
Before we begin, make sure you have a Python 3.10+ environment installed. You can then install Rift using the following command:
Initialize Project
Next, open up a terminal and run the following command to generate a bare project:
The --base option specifies the project template used to initialize with. You should see a message similar to the following:
Project structure
After initializing the project, you can open the folder with your favorite editor or IDE. If you don't have one, we recommend using VSCode. You can see the directory structure of the project as follows:
Project Configuration
The project configuration is present in the project.toml file. You will need to make changes to this file to define new targets, add test and deploy scripts, or configure rift's settings. The contents of this file are as follows:
Contracts
All your contracts will reside in the contracts/ directory. They are defined as classes that inherit the base Contract class. Contract codes are executed, and the execution graph is traced and gets translated to FunC (and TVM in the future). So if you use untraceable operations, the result will be recorded. For more specific details, visit here.
Tests
You can define test scripts in the tests/ directory. Don't forget to mention the test script in your target configuration. Test scripts are simple Python scripts; you can import contracts from the contracts package and use arbitrary Python code.
Deployers
You can define deploy scripts under the deployers directory. This script will be mentioned in target configuration and will run whenever rift deploy [TARGET] is executed.
Storage Contract
0. Specifications
In this section, we will develop a storage contract that stores an unsigned 64-bit integer value in its storage. The contract will have the following features:
- The contract's
admincan change this value by sending an internal message. - The data should be available with a get-method.
1. Configure the project
Let's start by refactoring the existing files. We will rename contracts/bare_template.py to contracts/storage.py and update its content to the following:
We will also update the project configuration in project.toml to the following:
2. Define the Contract Data
Next, we will define the contract data scheme by adding the Data class under our Storage class, which will extend Model:
3. Define contract message structure
We will also specify the contract message body structure as a Payload class:
4. Implement the change Function
The contract's internal_receive function will check whether the sender is admin and replace the data with the new value. We can access the full message via self.message and the message body with self.body:
5. Specify the get-method
We need to define a get-method so that the value will be exposed. To do this, we have two options:
- Add a config docstring to the class so that it's automatically handled during compile time:
This approach is best when we want to expose a field in our data and don't need any processing. For other use cases, we should define a get-method using the second approach.
- Define a new method in the contract with
@method_id()annotation:
6. Compiling
Our contract is complete! You can see the full implementation in this file. Let's compile it using the following command:
The built files will be available in the build/ directory.

Testing
One of the most critical aspects of contract development is ensuring correctness and security. Even minor bugs can result in significant financial losses for contract parties. Properly testing contracts with appropriate test cases is, therefore, an essential step in the development process. Fortunately, Rift includes a built-in testing framework that minimizes the hassle of testing.
To begin, let's rename the tests/test_example.py file to tests/test_storage.py and use the initial code provided:
In the test environment, we can easily import the target contract and instantiate it with an arbitrary cell as its data. We can then call its methods and analyze the results.
First, we'll proceed with testing our get_value method to ensure it can properly read from our data cell:
Then, we'll test the internal_receive method with a change_value call:
We can also test that the contract disallows unauthorized changes by testing with another admin:
To run the test command, enter the following in the command line:
The expected output is:
! 
Deploying
The first step is to define the deploy function in deployers/deploy_storage.py. The deploy function deploys the contract to the blockchain and returns a message and a boolean flag. The message carries the contract deploy code and initial data, and the boolean flag indicates whether this message will be sent independently or through your wallet as an internal message. In our case, the flag is set to False because we are sending the message through our wallet as an internal message. Here is the initial template code:
When you execute rift deploy TARGET, Rift executes the deploy function and sends the given message to the blockchain.
Now we need to construct the initial data for our contract and deploy it. We'll modify the deploy function as follows:
In this modified deploy function, we first get our wallet and its address. Then, we create the initial data for the contract, which includes the admin address and an initial value of 0. Next, we create a change body as the first message to the contract, setting the new value to 1. Finally, we send the deploy request bearing 0.1 TON for fees.
To deploy the contract on testnet, run the following command:
On the first try, you will need to configure/create a wallet with Rift and fund it. After executing the command, you should see a message indicating that the contract is getting deployed to a specific address.

The End
This tutorial has demonstrated the step-by-step process of developing and deploying a simple storage contract on testnet using Rift. This will serve as a basis for further development guides with Rift. You can find the full project implementation here. If you want to stay updated, join our community channel. We prioritize simple step-by-step guides and are continuously updating our documentation. Stay tuned! This tutorial has demonstrated the step-by-step process of developing and deploying a simple storage contract on testnet using Rift. This will serve as a basis for further development guides with Rift. If you want to stay updated, join our community channel. We prioritize simple step-by-step guides and are continuously updating our documentation. Stay tuned!


