Understanding the Relationship Between Minter and Wallet Contracts
In the Ton blockchain ecosystem, smart contracts are designed with a sharded architecture, particularly evident in token economy contracts. A critical aspect of this design is the relationship between the Minter and Wallet contracts during deployment. This article explores how these contracts are bound together and the technical nuances involved.
Key Components of Token Contracts
- Minter Contract: Responsible for token issuance and managing the overall supply.
- Wallet Contract: Handles individual user balances and transactions.
The binding between these contracts occurs during the deployment of the Minter contract, where the Wallet contract's compiled code is passed as a parameter.
Deployment Process: Binding Minter and Wallet Contracts
Step 1: Preparing the Wallet Contract Code
The Wallet contract's code (jetton_wallet_code) is compiled but not deployed independently. Instead, it is embedded into the Minter contract during deployment.
const wallet_code = await compile('JettonWallet');Step 2: Configuring the Minter Contract
The Minter contract’s configuration includes:
admin_address(jetton_master_address).- Token metadata (
content). - The precompiled Wallet contract code (
jetton_wallet_code).
const minter = JettonMinter.createFromConfig({
admin,
content,
wallet_code, // Embedded Wallet code
}, await compile('JettonMinter'));Step 3: On-Chain Storage
The Minter contract’s save_data function stores the Wallet code on-chain, binding it to the Minter:
() save_data(int total_supply, slice admin_address, cell content, cell jetton_wallet_code) impure inline {
set_data(
begin_cell()
.store_coins(total_supply)
.store_slice(admin_address)
.store_ref(content)
.store_ref(jetton_wallet_code) // Wallet code stored here
.end_cell()
);
}How Wallet Contracts Are Activated
Automatic Wallet Creation
When a user interacts with the token:
The Minter contract calculates the user’s Wallet address using their public address and the stored
jetton_wallet_code:slice get_wallet_address(slice owner_address) method_id { (..., cell jetton_wallet_code) = load_data(); return calculate_user_jetton_wallet_address(owner_address, my_address(), jetton_wallet_code); }- The Wallet contract is automatically instantiated upon the first transaction, eliminating the need for manual deployment.
Note: The Wallet contract’s logic is already on-chain via the Minter, ensuring seamless user onboarding.
FAQs
Q1: Why doesn’t the Wallet contract need separate deployment?
A1: The Wallet’s code is stored in the Minter during deployment, enabling dynamic creation when users transact.
Q2: How is the Wallet address determined?
A2: The Minter computes it using the user’s public address and the embedded jetton_wallet_code.
Q3: Can the Wallet contract be manually deployed?
A3: Yes, but it’s unnecessary since the Minter handles automatic instantiation.
Conclusion
The Ton blockchain’s token model relies on a clever binding mechanism between Minter and Wallet contracts:
- Deployment: Wallet code is passed to the Minter and stored on-chain.
- Activation: Wallets are created on-demand for users.
- Efficiency: Eliminates redundant deployments while ensuring scalability.
👉 Explore Ton blockchain’s official documentation for further details.