1

The Smartpy compiler allow to compile a contract (compiling the code and the initial storage) but I don't see any "compile-parameter" option, that would allow to convert a smartpy command to a michelson representation.

How can I call a deployed smartpy contract ?

ps : I tried to add a compilation target like this:

sp.add_expression_compilation_target("minting", FA12(admin=sp.address("tz1cpb3rLapo7RbsZNE3Qy6TMzqNWCxk9hXA"), config  = FA12_config(
                support_upgradable_metadata         = True,
                use_token_metadata_offchain_view    = True
            ),
            token_metadata = {
                "decimals"    : "18",             # Mandatory by the spec
                "name"        : "TestToken", # Recommended
                "symbol"      : "TEST",            # Recommended
                # Extra fields
                "icon"        : 'https://smartpy.io/static/img/logo-only.svg'
            }).mint({"address" : sp.address("tz1cpb3rLapo7RbsZNE3Qy6TMzqNWCxk9hXA"), "value" : 12}))

but the compilator give me this error:

Traceback (most recent call last):
  File "contracts/FA12.py", line 453, in <module>
    sp.add_expression_compilation_target("minting", FA12(admin=sp.address("tz1cpb3rLapo7RbsZNE3Qy6TMzqNWCxk9hXA"), config  = FA12_config(
  File "contracts/FA12.py", line 130, in mint
    sp.set_type(params, sp.TRecord(address = sp.TAddress, value = sp.TNat))
Exception: New command outside of contract (line 130 of contracts/FA12.py):
(set_type (map ("contracts/FA12.py" 130) ((literal (string "address") ("contracts/FA12.py" 130)) (literal (address "tz1cpb3rLapo7RbsZNE3Qy6TMzqNWCxk9hXA") ("contracts/FA12.py" 463))) ((literal (string "value") ("contracts/FA12.py" 130)) (literal (intOrNat 12) ("contracts/FA12.py" 130)))) (record ((address "address") (value "nat")) None) ("contracts/FA12.py" 130))

ps2: I tried to add another compilation target like this:

    sp.add_expression_compilation_target("minting", mint({"address" : sp.address("tz1cpb3rLapo7RbsZNE3Qy6TMzqNWCxk9hXA"), "value" : 12}))

but the compilator give me this error (this is why I have tried to reinit the smart contract in my previous attempt):

  File "contracts/FA12.py", line 453, in <module>
    sp.add_expression_compilation_target("minting", mint({"address" : sp.address("tz1cpb3rLapo7RbsZNE3Qy6TMzqNWCxk9hXA"), "value" : 12}))
NameError: name 'mint' is not defined

Any idea ?

1

On top of Rodrigo’s answer.

In scenarios, every call generates the corresponding Michelson parameters.

https://smartpy.io/docs/scenarios/testing#registering-and-displaying-calls-to-entry-points

1

You can use sp.add_expression_compilation_target("<name>", <expression>)

https://smartpy.io/docs/compilation_targets#expression-compilation

And then you can compile it with: ~/smartpy-cli/SmartPy.sh compile <...>

The parameters will be generated inside the <output-directory> you provided.

EDIT: In the web IDE, you can find the compiled parameters on the output panel.

enter image description here

7
  • I tried it but there is not a lot of information in the documentation on how to use compilation_target to call a contract functions. I don't know how to use it (I have updated my post with an example of compilation target). Aug 22 at 0:07
  • You are compiling the entire contract in the example you provided, for that you need sp.add_compilation_target. Aug 23 at 11:54
  • Yes I tried to only compile the function "mint" but it gives me the following error : ``` name 'mint' is not defined ``` (I have updated my post with an example). This is why I have tried to redefine the contract. Aug 23 at 12:27
  • The entrypoint calls are generated when you run the tests. You can also see them in the right panel on the web IDE after running the tests. smartpy.io/… Aug 23 at 14:32
  • Updated the answer with an image Aug 23 at 14:35

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.