I have one contract which creates and stores another contract, so in the creator contract I have something like:


Which is basically a map where the address of all the created children are stored. Now the problem comes when I want to get a children and interact with it (read data/execute a function). I've tried using the sp.contract() function but I can't seem to get it working. Any example code snippets or advice?

Thanks in advance.

2 Answers 2


AFAIK it's not possible to read the data of another contract (but this is probably changing when the Hangzhou protocol is adopted).

The following is an example of calling an entry point on another contract, but note that some of my comments about what the purpose of "open_some()" is are wrong, and I'm being much more explicit about types than you might need to be (no need to make every params a sp.TRecord but it's at least consistent).


It's not available on smartpy.io yet, hopefully it will be soon, for now you can just copy/paste from there and experiment.


You are missing a few parameters: documentation

Also, you may want to use sp.big_map instead of sp.map if you expect to have many child contracts.

In the snippet below, inside entry_point ep I build a typed contract that will be used to call an entry_point named some_entrypoint on a child contract, where the input parameter is of type sp.TUnit.

import smartpy as sp

class MyContract(sp.Contract):
    def __init__(self, **kargs):
            children = sp.map(
                    0: sp.record(
                        balance = 10,
                        address = sp.address("KT1Tezooo1zzSmartPyzzSTATiCzzzwwBFA1")
                tkey = sp.TNat,
                tvalue = sp.TRecord(
                        balance = sp.TNat,
                        address = sp.TAddress

    def ep(self):
        child = self.data.children.get(0, message = "User does not exist")
        contract = sp.contract(
            entry_point = "some_entrypoint"
        sp.transfer(sp.unit, sp.tez(0), contract)

@sp.add_test(name = "Minimal")
def test():
    scenario = sp.test_scenario()
    c1 = MyContract(x = 12)
    scenario += c1
  • Hi, thanks for the answer. Imagine i wanted to access a children data variable, like children.data.title, how would I do that?
    – TzDev
    Nov 8, 2021 at 11:39
  • Updated the example to show how you can do it. Nov 8, 2021 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.