Deploying to network
Summary: In previous steps, we developed and tested our smart contracts, ensuring their correctness.
In this part of the guide, we will proceed with the deployment of previously developed smart contracts and cover interaction with them on-chain.
Address and initial state
We already know that address is a unique identifier of a smart contract
on the network, used to send transactions and verify the sender upon receiving. However, we still haven't discussed how it's created. The common formula for a smart contract address looks like this:
address = hash(state_init(code, data))
The address of a smart contract is a hash of the aggregated initial code and data of the smart contract upon deployment. This simple mechanism has a few important consequences:
You already know the address
In TON, any address that doesn't have any data is considered in the nonexistent
state. Nevertheless, when we created a wallet using the wallet app in the Getting started section, we were still able to get the address of our future wallet smart contract from the wallet app before its deployment and examine it in the explorer.
The reason behind this is that creating your private and public key pair through a mnemonic phrase, where the second key is part of the initial data of the smart contract, makes the state_init
of our contract fully determined:
- code is one of the standard wallet implementations, like
v5r1
. - data is the
public_key
along with other default initialized fields.
This makes it possible to calculate the future wallet smart contract address.
Magic storage member
In previous steps, we deliberately didn't explain the purpose of ctxID
and ID
stored in our smart contract's state and why they remained untouched in all the smart contract functionality. Now, their purpose should start to become clearer.
Since we can't deploy a smart contract with the same state_init
, the only way to provide the same initial code and "same" initial data is to create a separate field in it, ensuring additional uniqueness. This, in the case of a wallet, gives you the opportunity to have the same key pair for several wallet smart contracts.