Can we parse a varialble of type sp.TAddress to sp.TString like this:

strAddress = sp.string(sp.address("tz1-add")) or strAddress = str(sp.address("tz1-add"))?

Smart Contract Example:

import smartpy as sp

class SmartContract(sp.Contract):
    def init(self):
        self.init(fromAddress = "")

    def transferEvent(self, params):
        self.data.fromAddress = sp.string(params.fromAddress)

if "templates" not in name:
    @sp.add_test(name = "Smart Contract")
    def test():

        c1 = SmartContract()

        scenario = sp.test_scenario()
        scenario += c1

        scenario.h1("Smart Contract")
        scenario += c1.transferEvent(strAddress = sp.address("tz1MFYTrMMhh7QBq8NRP6QMU2gcrcGhjSTrv"))

        scenario.verify(c1.data.fromAddress == "tz1MFYTrMMhh7QBq8NRP6QMU2gcrcGhjSTrv")

As Error I get:

Error: Error in Scenario Literal format error: (string(attr(params 8)fromAddress 9)) Traceback (most recent call last):

enter image description here



No, you can't. Addresses are not convertible to strings in Michelson (short of really cheating with internals).

That being said, the error message could be a bit more explicit.

Also, what is your use case? The general understanding is that this operation is useless.

  • So, I want to call a method of a smart contract A from a smart contract B where the method accepts a string. The smart contract B, the caller, passes an address as param to the method called in smart contract A. – Daly Feb 6 '20 at 14:13
  • Understood. You cannot do this (without using super weird hacks that you really don't want to hear about). – FFF Feb 6 '20 at 15:11
  • Haha ok, I resolved it differently. – Daly Feb 6 '20 at 15:51

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.