<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shubham on Medium]]></title>
        <description><![CDATA[Stories by Shubham on Medium]]></description>
        <link>https://medium.com/@0xshubham.shakti?source=rss-0b1743a0664c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Shubham on Medium</title>
            <link>https://medium.com/@0xshubham.shakti?source=rss-0b1743a0664c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:52:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@0xshubham.shakti/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Parent-Child Pattern in Tact: A Smarter Way to Build on TON]]></title>
            <link>https://medium.com/@0xshubham.shakti/the-parent-child-pattern-in-tact-a-smarter-way-to-build-on-ton-7d20f6dbe3d8?source=rss-0b1743a0664c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d20f6dbe3d8</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Shubham]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 12:00:56 GMT</pubDate>
            <atom:updated>2025-04-20T12:10:25.587Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UyWUDqY-yBhBaj7euZYCLg.png" /></figure><p>Understand how to deploy contracts from contracts in Tact</p><blockquote><em>Every parent creates children. But what if those children could live independently and still respond when called?</em><br> That’s exactly what smart contracts can do on the <strong>TON blockchain</strong> — and today, we’ll walk through it, step by step.</blockquote><h3>Understanding TON and TACT</h3><p>Let’s break it down without the buzzwords</p><h3>1. TON Blockchain</h3><p>TON stands for <strong>The Open Network</strong>, originally developed by the team behind Telegram. Think of it as a super-fast, scalable blockchain that’s built to support real-world use cases like payments, games, apps, and more — all directly inside Telegram too.</p><p>TON isn’t just a layer 1 blockchain — it’s an ecosystem.</p><ul><li>It’s designed to handle <strong>millions of users</strong>.</li><li>It has low fees and fast transactions.</li><li>It supports <strong>smart contracts</strong> (our focus today)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LzGVo0o1SCsWgU5oocrV-Q.png" /><figcaption>TON (The Open Network) in a nutshell</figcaption></figure><h3>2. What Are Smart Contracts?</h3><p>Imagine a vending machine.</p><p>You put in ₹50 and press the “Coke” button — it checks the money, finds the product, and gives it to you. No middleman.</p><p>That’s a <strong>smart contract</strong>.<br> It’s an automatic program on the blockchain that does things when certain conditions are met.</p><p>Smart contracts can:</p><ul><li>Transfer tokens</li><li>Create NFTs</li><li>Run apps</li><li>Even… deploy other contracts (yup!)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJi83xl5d7XTnqJebMiKBg.png" /><figcaption>Understanding the working of smart contracts</figcaption></figure><h3>3. What Is Tact?</h3><p><strong>Tact</strong> is a new programming language made just for TON smart contracts. It’s simple, readable, and beginner-friendly — especially compared to other blockchain languages like Solidity or Rust.</p><blockquote>If smart contracts are recipes, <strong>Tact is the cookbook language.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Af9Ynpm5sU9KCNAut9eT-w.png" /></figure><h3>Parent-Child Relationship (Smart Contracts That Deploy Other Smart Contracts)</h3><p>Yes, you read that right.</p><p>In blockchain development — especially on TON using Tact, there’s a common architectural approach called the Parent-Child contract pattern.<br>It’s a design where:</p><ul><li>You have <strong>o</strong>ne main contract (called the Parent) that controls the logic and coordination.</li><li>It can dynamically deploy multiple instances of another contract (called the Child).</li><li>Each child contract is isolated, independent, and aware of its unique identity.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cFGr20UYy-AlyUSgIg9AJA.png" /></figure><blockquote>This pattern is especially useful when you want to separate storage or logic per entity — like user tasks, items, NFTs, proposals, or levels in a game.</blockquote><p>In this blog, we are referring to the<a href="https://tact-by-example.org/06-parent-child"><strong> <em>Parent-Child Relationship code snippet</em></strong><em> </em></a>from Tact by example. Let’s explore both contracts individually, starting with the child, and then we’ll go back to how the parent controls them.</p><h3>Step 1: The &#39;TodoChild’ Smart Contract</h3><p>We will first understand the following smart contract in detailed manner:</p><pre>import &quot;@stdlib/deploy&quot;;<br><br>// we have multiple instances of the children<br>contract TodoChild {<br><br>    seqno: Int as uint64;<br> <br>    // when deploying an instance, we must specify its index (sequence number)<br>    init(seqno: Int) {<br>        self.seqno = seqno;<br>    }<br><br>    // this message handler will just debug print the seqno so we can see when it&#39;s called<br>    receive(&quot;identify&quot;) {<br>        dump(self.seqno);<br>    }<br>}</pre><p><strong>Purpose of this contract:</strong> It stores a unique identifier (seqno) and responds to messages.</p><pre>contract TodoChild {<br>    seqno: Int as uint64;</pre><ul><li>The child contract defines a single field: seqno, which stands for <strong>sequence number</strong>.</li><li>It’s cast as a uint64 — an unsigned 64-bit integer. This makes it efficient for TON storage and computation.</li></ul><pre>init(seqno: Int) {<br>        self.seqno = seqno;<br>    }</pre><ul><li>init(...) is the <strong>initialization function</strong> (called when the contract is deployed).</li><li>It takes in a number and assigns it to self.seqno. This ensures each child knows its position: <strong>Task #1</strong>, <strong>Task #2</strong>, and so on.</li></ul><pre>receive(&quot;identify&quot;) {<br>        dump(self.seqno);<br>    }</pre><ul><li>This is a <strong>message handler</strong>.</li><li>When the contract receives the message &quot;identify&quot; (as a string), it calls dump(self.seqno), which is used for <strong>debugging</strong>.</li><li>This would log the value so you can see which child you’re talking to.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9SaqJzWYeuFnxk5w34UvOw.png" /><figcaption>Overview of “TodoChild” contract structure</figcaption></figure><p><strong>Related Analogy:<br></strong>Each TodoChild is like a <strong>sticky note</strong> with a task number on it. Ask “who are you?” and it replies, “I’m task number 3!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*OPUG4Iw_lgE5szQiXAT6Ag.gif" /><figcaption>The variable “seqno” contains an integer value</figcaption></figure><h3>Step 2: The &#39;TodoParent’ Smart Contract</h3><p>We will first understand the following smart contract in detailed manner:</p><pre>import &quot;@stdlib/deploy&quot;;<br><br>// we have one instance of the parent<br>contract TodoParent with Deployable {<br><br>    numChildren: Int as uint64;<br> <br>    init() {<br>        self.numChildren = 0;<br>    }<br><br>    // this message handler will cause the contract to deploy another child<br>    receive(&quot;deploy another&quot;) {<br>        self.numChildren = self.numChildren + 1;<br>        let init: StateInit = initOf TodoChild(self.numChildren);<br>        send(SendParameters{<br>            to: contractAddress(init),<br>            value: ton(&quot;0.1&quot;),              // pay for message, the deployment and give some TON for storage<br>            mode: SendIgnoreErrors,<br>            code: init.code,                // attaching the state init will cause the message to deploy<br>            data: init.data,<br>            body: &quot;identify&quot;.asComment()    // we must piggyback the deployment on another message<br>        });<br>    }<br><br>    get fun numChildren(): Int {<br>        return self.numChildren;<br>    }<br>}</pre><p><strong>Purpose of this contract:</strong> It acts as the controller. It can deploy child contracts dynamically and keeps track of how many have been created.</p><pre>contract TodoParent with Deployable {<br>    numChildren: Int as uint64;</pre><ul><li>TodoParent is marked with the Deployable trait — which tells the compiler that this contract can be <strong>deployed directly by users</strong>.</li><li>It has a field numChildren that acts as a <strong>counter</strong> to track how many children it has deployed.</li></ul><pre>    init() {<br>        self.numChildren = 0;<br>    }</pre><ul><li>The init() function is called during deployment.</li><li>It simply starts the counter at zero — no children yet.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HiHnmR_eLRBSqd-W9TqdZw.png" /><figcaption>User interaction and co-relation between TodoParent Contract and TodoChild contract</figcaption></figure><h3>Deploying a Child Contract: The Core Logic</h3><pre>    receive(&quot;deploy another&quot;) {<br>        self.numChildren = self.numChildren + 1;</pre><p>When the parent receives a &quot;deploy another&quot; message, it:</p><ol><li>Increments the child count.</li><li>Prepares to deploy a new TodoChild.</li></ol><pre>        let init: StateInit = initOf TodoChild(self.numChildren);</pre><ul><li>StateInit is a <strong>data structure in TON</strong> that contains everything needed to deploy a contract: code + initial state.</li><li>initOf TodoChild(...) prepares a new TodoChild contract instance, passing the current numChildren as the argument for its seqno.</li></ul><p>Now, the contract has the <strong>blueprint</strong> for the child — including what code to run and what value to initialize.</p><pre>        send(SendParameters{<br>            to: contractAddress(init),<br>            value: ton(&quot;0.1&quot;),<br>            mode: SendIgnoreErrors,<br>            code: init.code,<br>            data: init.data,<br>            body: &quot;identify&quot;.asComment()<br>        });</pre><p>Let’s break down the <strong>send()</strong> function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*XWmFAhz2HWOMd7A7ZvDVgA.png" /></figure><p><strong>Technical Insight:</strong><br>This is how Tact lets us <strong>“piggyback”</strong> a deployment on a message. We’re deploying the contract <em>and</em> sending it an initial message in one atomic action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0N3cCfrrnVG9OX-Wamn7Rg.png" /><figcaption>Overview of the deployment process: parent and child contract message interconnection</figcaption></figure><p><strong>Result:</strong><br> A new TodoChild is deployed. It initializes with a sequence number and immediately responds with &quot;identify&quot; — confirming its creation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MiwUpFsRZEHhECsJaQtMUA.png" /><figcaption>Steps of smart contract deployment</figcaption></figure><h3>Get Function to Track Total Children</h3><pre>    get fun numChildren(): Int {<br>        return self.numChildren;<br>    }</pre><p>This is a <strong>getter method</strong>, accessible as an off-chain call.<br>You can query the parent contract and ask: <em>“Hey, how many children have you created so far?”</em></p><p>It returns an Int (the count), helping external apps, bots, or explorers read this data.</p><h3>TL;DR: Key Takeaways</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUgr7sMyaeeFPNuBUerhRg.png" /></figure><h3>Real-World Use Cases &amp; Inspiration</h3><p>Let’s look at how this Parent-Child smart contract pattern can be used in actual Web3 applications:</p><ul><li><strong>NFT Collections: </strong>The parent contract acts as the NFT controller, while each NFT is deployed as an individual child contract with its own metadata and owner.</li><li><strong>DAO Voting Systems: </strong>A DAO can use the parent to deploy a new child contract for every proposal. Each proposal then manages its own vote counts, deadlines, and logic.</li><li><strong>Real-World Asset Tokenization (RWAs) : </strong>A registry contract (parent) can tokenize assets like real estate or gold by deploying a child contract for each property or vault, containing its unique data and legal details.</li><li><strong>Gaming Applications : </strong>The game engine (parent) can spawn player characters, enemies, levels, or items as child contracts, each with its own logic, stats, or behavior.</li><li><strong>Freelance &amp; Service Agreements : </strong>A job platform can use a parent contract to deploy a child smart contract for every agreement between a freelancer and a client — tracking deliverables, payment, and deadlines.</li><li><strong>Subscription or Membership Systems : </strong>A platform can issue time-based or tiered subscription contracts (children) for each user, allowing custom expiration rules or benefits.</li><li><strong>Event Ticketing : </strong>A ticket factory (parent) deploys a smart contract for each ticket or seat, making it traceable, tradable, and verifiable on-chain.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*FmchqgWSKofAQe02S1Gp_w.gif" /></figure><h3>Conclusion</h3><p>By now, you’ve learned more than just a coding pattern — you’ve taken your first step toward <strong>thinking like a blockchain architect</strong>.</p><p>This Parent-Child contract structure shows us one powerful idea:</p><blockquote><strong>Smart contracts don’t need to do everything themselves. They can create, delegate, and organize.</strong></blockquote><p>In traditional programming, this is like breaking a big task into smaller functions.</p><p>In smart contract development, it’s about <strong>breaking logic across contracts</strong> to make things scalable, modular, and future-proof.</p><p>So what’s next?</p><ul><li>Try deploying your own parent-child contracts.</li><li>Modify the child to store more data like descriptions or timestamps.</li><li>Add a “delete” or “update” feature to experiment with lifecycle management.</li></ul><p>And if you got this far — you’re already ahead of most who start learning Web3. Now take that knowledge and <strong>build something meaningful</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*BpAUj7_StfUCOVpfUfjEgg.gif" /></figure><p>Thank you for reading. Follow me for more insightful content like this!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d20f6dbe3d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>