0

i'd like to ask if it's possible to load another smart contract from an IPFS Hash or from a SmartPy url. What would be the best way to handle them with urls?

Contract A: https://smartpy.io/ide?cid=QmVPMCXXiUpe394zJFuKy2t5SeAviJzUWQsawL7z3WUVjJ&k=15243351510310b52b58

import smartpy as sp

B = sp.import_script_from_url('https://smartpy.io/ide?cid=Qmdwn3DijL1eSh8NVDUsuLNkv5G8XasHD7RzqymiwhXB6H&k=8cffde9f7bbe1d23e9eb')

class A(sp.Contract):
    def __init__(self, **kargs):
        self.init(**kargs)

    @sp.entry_point
    def x(self, params):
        pass

Contract B (it's almost the same given above): https://smartpy.io/ide?cid=QmNSdUmBL32eVp9dyB96eyBSbqtcGycb8hXcpTCNanhzMr&k=901c9fc94841b0611393

Error: invalid syntax

 SmartPy code line 3 (line 3)
   B = sp.import_script_from_url('https://smartpy.io/ide?cid=Qmdwn3DijL1eSh8NVDUsuLNkv5G8XasHD7RzqymiwhXB6H&k=8cffde9f7bbe1d23e9eb')
 SmartPy code, line 1 (line 1)
2

If you are trying to import a contact already stored by the IDE, you can do the following:

Import the following 2 contracts and name them ContractA and ContractB:

ContractA => https://smartpy.io/ide?cid=QmQRQ7eBRw9AhfgMoXhMfEpwSasakE2HFCCxQdAgs1cyZR&k=3fa7c6befc039ee5bb36

ContractB => https://smartpy.io/ide?cid=QmaZSLA3zCUHGAQWWp3vJJyF9xQ4mUqMZi4hhEY4M3f147&k=4ec858e12568f3642fa1

Then import contractB into ContractA with:

B = sp.import_stored_contract("ContractB")

enter image description here

sp.import_script_from_url will only work for plain text files that have the raw content of the contract. For example https://pastebin.com/raw/aNEYng4w

2
  • it gives me network error ;< w the raw pastebin as an example – crzy Feb 12 at 5:17
  • 1
    I think pastebin does not add CORS headers for other origins. You will have to use another host to provision the files. – Rodrigo Quelhas Feb 12 at 20:52

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.