Metadata in SmartPy

Creation of metadata files

init_metadata

class MyContract(sp.Contract):
def __init__(self, ...):
self.init_metadata("meta_0", {"foo": "bar"})
self.init_metadata("meta_1", {"a" : 12, "c" : True)
...

Off-chain views

    @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)

Meta-programming, typing and metadata

self.init_metadata("a_name", expr)

A rather complete example

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

--

--

--

An intuitive and effective smart contracts language and development platform for Tezos. In Python.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Inspirational Women in STEM and Tech: “Don’t be paralyzed with analysis” with Payal Chakravarty…

Install Wine 7.1 on Ubuntu 20.04 / 21.10 & Linux Mint

Kubermetrics — Cluster Visualization Made Simple

4/8 Pixel Racers Weekly Update

This Is The Best C++ Cheat Sheet!

Hydro Development Updates 24 February 2022

Basic And Second Generation Inheritance In Python With super().__init__()

MATLAB code for Voltage Regulation and Efficiency Of transmission line with Sending end parameters…

Matlab code for Transmission Line

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
SmartPy.io

SmartPy.io

An intuitive and effective smart contracts language and development platform for Tezos. In Python.

More from Medium

Parallel vs Distributed Computing

Debugging Failing Golang Tests

A Quick Look at Blockchain Scaling via Rollups

An Incomplete Guide to scaling.