1

I am trying to send data from one contract to another in smartpy

Remote Contract

import smartpy as sp

class Try(sp.Contract):
    def __init__(self):
        self.init(mynum = sp.int(0))

    @sp.entry_point
    def add(self,params):
        self.data.mynum = params.num


@sp.add_test(name="try")
def test():
    obj = Try()
    scenario = sp.test_scenario()
    scenario += obj

Calling Contract / Current Contract

import smartpy as sp

class Try(sp.Contract):
    def __init__(self):
        self.init(mynum = sp.int(0))

    @sp.entry_point
    def add(self,params):
        c = sp.contract(sp.TRecord(num = sp.TInt),sp.address("KT1X6yVQccrVn8r9PCEbExy21GHwikU7KXn5"),entry_point="add").open_some()

        mydata = sp.record(num = params.num)
        sp.transfer(mydata,sp.mutez(0),c)


@sp.add_test(name="try")
def test():
    obj = Try()
    scenario = sp.test_scenario()
    scenario += obj

Error

Status: failed

    Error: proto.005-PsBabyM1.michelson_v1.runtime_error
    Error: proto.005-PsBabyM1.michelson_v1.script_rejected
       undefined

Remote Contract Address (Use Smartpy explorer) - KT1X6yVQccrVn8r9PCEbExy21GHwikU7KXn5

Calling Contract Address (Use smartpy explorer) - KT1EJCF1iU4jQkJZz1FWTbaPf7TZYGNNhXbF

1

You should remove the entry_point annotation "add" in the calling contract when the first contract has only one entry point. This is annoying but I believe it is necessary because of Tezos annotations.

That being said, we may in the future check sp.contract(...) at origination time when possible. This would have failed earlier.

I've originated one such contract KT1EJhzNtwn7WALCCqp3u2pEUGyNrqfWyUHJ and successfully interacted with your initial contract.

For people not using SmartPy explorer (e.g., https://smartpy.io/test2/explore.html?address=KT1EJhzNtwn7WALCCqp3u2pEUGyNrqfWyUHJ), the network in question is Babylonnet.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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