tact-lang / tact-docs

Tact main documentation
https://docs.tact-lang.org
54 stars 41 forks source link

Is it possible to call init() multiple times? #228

Closed mypeaceduck closed 4 months ago

mypeaceduck commented 4 months ago

Hello,

https://tact-by-example.org/06-authenticating-children

    // when deploying an instance, we must specify its index (sequence number)
    init(parent: Address, seqno: Int) {
        require(sender() == parent, "not the parent");
        self.parent = parent;
        self.seqno = seqno;
    }

why not just:

    // when deploying an instance, we must specify its index (sequence number)
    init(seqno: Int) {
        self.parent = sender();
        self.seqno = seqno;
    }

Is it possible to call init() multiple times?

mypeaceduck commented 4 months ago

Oh, it`s need for

let expectedAddress: Address = contractAddress(initOf TodoChild(myAddress(), msg.fromSeqno));

right?

novusnota commented 4 months ago

Yes, you're right. Also, "calling init" multiple times is possible via getting the init package through initOf and then deploying multiple contracts with that code and data acquired.