Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
/

Maximizing TON’s Benefits with the Rift Framework
Picture Maximizing TON’s Benefits with the Rift Framework 2 | TON app

TON’s Benefits with the Rift

Discover how the Rift Framework helps maximize TON’s benefits, streamlining blockchain solutions and driving growth with efficiency and innovation.
Picture Maximizing TON’s Benefits with the Rift Framework 3 | TON app
Decentralized technology is paving the way for the future, fostering genuine democratization and fairness. The world is increasingly turning towards blockchain and its diverse applications. Among these, The Open Network (TON) stands out as a high-speed, cost-effective, and eco-friendly layer-1 blockchain, crafted to accommodate billions of users.

Harnessing Python with TON

TON offers a decentralized layer-1 blockchain renowned for its rapid and efficient transactions. Despite its advantages, the FunC and Fift programming languages associated with TON can be quite challenging for developers to master. Enter Rift.

Rift enables developers to harness the power and flexibility of Python to create and interact with TON. With Python’s intuitive syntax and object-oriented programming (OOP) capabilities, developers can easily write and test smart contracts without the need to acquire a new programming language.

Rift serves as the gateway connecting Python with the world of TON.

Streamlining Development with Rift

Rift provides a comprehensive set of tools for developing on TON. It simplifies the entire development workflow, from crafting smart contracts in Python to testing and deploying them on the TON network. With Rift’s all-in-one framework, developers only need to be familiar with Python 3.10 to start creating on TON.

Here are a few of the standout features that make Rift an essential resource for TON development:

Enhance Your Smart Contract Creation with Rift

Rift allows developers to leverage Python’s syntax and features to effortlessly build smart contracts for TON. There’s no need to master a new programming language or deal with compatibility challenges—Rift integrates the strengths of Python with TON, making blockchain development more accessible and efficient.

Class Definition

class SimpleWallet(Contract):

"""

Simple Wallet Contract.

# config

get-methods:

- seq_no

- public_key

"""

Data Model

The SimpleWallet class includes an inner class called Data, which is a model representing the contract’s state. It has two attributes:

  • seq_no: A 32-bit unsigned integer that tracks the sequence number of transactions.
  • public_key: A 256-bit unsigned integer that stores the public key used for verifying signatures.

class Data(Model):

seq_no: uint32

public_key: uint256

External Body

The ExternalBody class represents the structure of external messages received by the contract. It includes:

  • seq_no: A 32-bit unsigned integer matching the sequence number in the contract’s state.
  • valid_until: A 32-bit unsigned integer indicating the expiration time of the message.

class ExternalBody(SignedPayload):

seq_no: uint32

valid_until: uint32

Contract Data

The SimpleWallet class maintains a single instance of Data to track the current state of the wallet.

External Message Handling

The external_receive method processes incoming messages. The method performs the following steps:

  1. Parse the Message: It extracts the message body as an ExternalBody instance.
  2. Verify Validity:
    • Checks if the message’s valid_until timestamp is greater than the current time.
    • Verifies that the seq_no in the message matches the current sequence number in the state.
    • Validates the message’s signature using the stored public key.
  3. Accept the Message: If all checks pass, the message is accepted.
  4. Process References: It handles any references within the message, sending them as raw messages with the specified mode.
  5. Update State: Increments the sequence number and saves the updated state.

This contract exemplifies a simple wallet system with basic functionality for managing and verifying transactions in a blockchain environment.

Mastering TON Interaction with Rift

Rift offers a comprehensive solution for working with TON, simplifying every aspect of network engagement. It consolidates all essential TON development tools into a single interface, making it incredibly straightforward for developers to:

  • Create Messages: Easily construct and manage messages within the TON network.
  • Sign Messages: Utilize the Fift backend to securely sign messages.
  • Execute Contracts: Run and test contract codes efficiently.
  • Deploy Contracts: Seamlessly deploy smart contracts to the network.
  • Engage with the Network: Use the Tonlibjson backend for smooth network interactions.

With Rift, developers can streamline their workflow and fully harness the capabilities of the TON network.

from contracts.jetton_minter import JettonMinter

from contracts.jetton_wallet import JettonWallet

def deploy():

# Initialize the data for the JettonMinter contract

init_data = JettonMinter.Data()

init_data.admin = "EQCDRmpCsiy5fA0E1voWMpP-L4SQ2lX0liTk3zgFXcyLSYS3"

init_data.total_supply = 10**11 # This represents a total supply of 100

init_data.content = Cell() # Set content to an empty cell

init_data.wallet_code = JettonWallet.code() # Retrieve the code for the JettonWallet

# Deploy the JettonMinter contract with an initial amount

msg, addr = JettonMinter.deploy(init_data, amount=2 * 10**8)

 

# Return the deployment message and a boolean value (False)

return msg, False

Thoroughly Validate Your Contracts

Rift offers a comprehensive testing framework for the TON Virtual Machine (TVM), simplifying the process of validating contracts before their deployment on the main network. This framework delivers an intuitive interface for crafting message bodies and examining the contract’s state to verify its functionality.

from contracts.jetton_wallet import JettonWallet

from contracts.types import TransferBody

def test_transfer():

# Create and initialize wallet data

data = create_data().as_cell()

wallet = JettonWallet.instantiate(data)

 

# Prepare the transfer body

body = create_transfer_body(dest=3)

 

# Send tokens and check the result

result = wallet.send_tokens(

body.as_cell().parse(), MsgAddress.std(0, 2), int(10e9), 0

)

result.expect_ok()

def test_transfer_no_value():

# Create and initialize wallet data

data = create_data().as_cell()

wallet = JettonWallet.instantiate(data)

 

# Prepare the transfer body

body = create_transfer_body(dest=3)

 

# Attempt to send tokens with zero value and check for an error

result = wallet.send_tokens(

body.as_cell().parse(), MsgAddress.std(0, 2), 0, 0

)

result.expect_error()

In this code:

  • test_transfer() initializes a JettonWallet instance and performs a token transfer. It then verifies that the transfer was successful.
  • test_transfer_no_value() initializes a JettonWallet instance and attempts to send tokens with a zero value, checking that an error is returned.

Embrace the Future with TON

TON has the power to transform the blockchain landscape, and Rift is the ideal tool to harness its full potential. Whether you’re new to TON or a seasoned developer, Rift offers a streamlined approach to accelerate your development and realize your ideas on the TON network. Don’t miss out—start building with Rift today and become part of the TON transformation!

Begin Your Journey Today

Dive into Rift’s repository and join the Skyring Channel to stay up-to-date with the latest developments. We’re thrilled to announce that comprehensive guides will be available soon. Keep an eye out for more information!