Metadata in SmartPy

Creation of metadata files

class MyContract(sp.Contract):
def __init__(self, ...):
self.init_metadata("meta_0", {"foo": "bar"})
self.init_metadata("meta_1", {"a" : 12, "c" : True)
...
    @sp.offchain_view
def get_x(self, params):
"""blah blah ' fdsfds " """
sp.result(sp.record(a = self.data.x, b = 12 + params))
@sp.offchain_view
def get_storage(self):
sp.result(self.data.x)
@sp.offchain_view
def get_cst(self):
"""42"""
sp.result(42)
self.init_metadata("a_name", expr)
class MyContract(sp.Contract):
def __init__(self, **kargs):
self.init_metadata("meta_0", {"foo": "bar"})
meta_1 = {"some": "string",
"some_dict" : {1, 2, 3},
"a": sp.key("tz1..."),
"foo" : (),
"views" : [self.get_x,
self.get_cst,
self.get_storage],
"f": lambda x : x + 2
}
self.init_metadata("meta_1", meta_1)
self.init(**kargs)
@sp.entry_point
def incr(self):
self.data.x += 1
@sp.entry_point
def change_metadata(self, params):
self.data.metadata[""] = params
@sp.offchain_view
def get_x(self, params):
"""blah blah ' fdsfds " """
sp.result(sp.record(a = self.data.x, b = 12 + params))
@sp.offchain_view
def get_storage(self):
sp.result(self.data.x)
@sp.offchain_view
def get_cst(self):
"""42"""
sp.result(42)
...

Linking of metadata files

metadata = sp.metadata_of_url(
"ipfs://QmWDcp3BpBjvu8uJYxVqb7JLfr1pcyXsL97Cfkt3y1758o")

A Real Example

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store