0

I'm trying to call another contract from mine. It seems like I can't feed sp.contract with an entrypoint string that comes from an argument (it works perfectly fine with an explicit string like "XXX" instead of "entryPoint") because it might be missing when my contract is getting called. How can I do it anyway?

import smartpy as sp

@sp.module
def main():
    class caller(sp.Contract):
        def __init__(self):
            pass

        @sp.entrypoint
        def call(self, contractAddress, entryPoint, str1, str2):
            c = sp.contract(sp.list[sp.string], contractAddress, entryPoint).unwrap_some()
            sp.transfer([str1, str2], sp.mutez(0), contractAddress)

1 Answer 1

0

Do not specify the entrypoint.

An address can hold the entrypoint information. In this case it has the form KT1XXX%<entrypoint_name>.

@sp.entrypoint
def call(self, contractAddress, str1, str2):
    c = sp.contract(sp.list[sp.string], contractAddress).unwrap_some()
    sp.transfer([str1, str2], sp.mutez(0), contractAddress)

For example, one can call this entrypoint with contractAddress being sp.to_address(sp.self_entrypoint("my_entrypoint"))

Your Answer

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

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