Introduction
In the world of blockchain, addresses play a crucial role, serving as both the location for asset storage and the bridge for smart contract interactions. This article will guide you through an in-depth understanding of smart contract addresses on the TON blockchain and how to easily convert between different formats.
Section 1: The Relationship Between Smart Contracts and Addresses
On the TON blockchain, everything can be seen as a smart contract. Smart contracts are built using the Actor model, and each actor (smart contract) requires an address to receive and process messages. This is similar to our real life where everyone has a home address to receive letters and packages.
Section 2: Composition of Addresses on the TON Blockchain
Smart contract addresses on the TON blockchain primarily consist of two parts: the workchain ID and the account ID.
-
Workchain ID: The workchain ID is a signed 32-bit integer used to identify different workchains. Currently, the TON blockchain mainly operates the main chain (workchain_id=-1) and the basic workchain (workchain_id=0).
-
Account ID: The account ID is a hash function of the smart contract object, specifically SHA-256. It is determined by the compiled code and initial state of the smart contract. Each smart contract generates a unique account ID upon deployment based on this information.
Section 3: Raw Addresses vs. User-Friendly Addresses
Raw Address
A raw address is the complete representation of a smart contract address, formatted as [decimal workchain ID]:[64 hexadecimal digits of the account ID]
. For example: -1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260
.
User-Friendly Address
A user-friendly address is a more secure and user-friendly address format that includes the following four parts:
- Flag: 1 byte, indicating the type and purpose of the address.
- Workchain ID: 1 byte, indicating the workchain where the address is located.
- Account ID: 32 bytes, representing the account address of the smart contract.
- Address Verification: 2 bytes, used to verify the correctness of the address.
User-friendly addresses are generated through base64 or base64url encoding and are 48 characters in length, excluding spaces. For example: kf/8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15+KsQHFLbKSMiYIny
(base64 encoded).
Section 4: Address Conversion and Security
Address Conversion
With the help of TON API and other tools, users can easily convert raw addresses to user-friendly addresses and vice versa. This helps to improve the usability and security of addresses.
Security
User-friendly addresses have the following advantages:
- Verifying the correctness of addresses to prevent erroneous transfers.
- Adding special flag bits to enhance transaction flexibility.
- Preventing accidents when sharing addresses on the internet.
Conclusion
Through this article, we hope you now have a deeper understanding of smart contract addresses on the TON blockchain. Mastering the format and conversion methods of addresses will help us conduct transactions and interactions safely and conveniently on the TON blockchain. In practice, please be attentive to the correctness of addresses to avoid asset losses due to address errors.