This article was first published on OntologyNetwork - Medium
How to Write a Smart Contract on Ontology with Python — (Part 2)
In the last article, we introduced the Blockchain & Block API of Ontology’s smart contract. Some of you might have already tried to write and run smart contracts on Ontology with Python. If you have any issues while using SmartX, feel free to contact us.
Today we will discuss how to use the second module: Storage API. The Storage API has five related APIs that enable addition, deletion, and changes to persistent storage in blockchain smart contracts. Here’s a brief description of the five APIs:
Let’s take a closer look at how to use these five APIs. First, create a new contract SmartX and then follow the steps below. Aa usual, at the end of the article, we will provide the GitHub link of the source code.
2 How to Use Storage API
2.1 GetContext & GetReadOnlyContext
GetContext & GetReadOnlyContext gets the context in which the current smart contract runs. The return value is the reverse of the current smart contract hash. As the name implies, GetReadOnlyContext gets the context of the read-only mode. In the example below, the return value is the reverse of the contract hash displayed in the upper right corner.
The Put function is responsible for storing the data on the blockchain in the form of a dictionary. As shown, Put accepts three parameters. GetContext gets the context of the current smart contract running, the key is the key value that needs to store data, and value is the value of the data that needs to be stored. Please note that if the key value is already in storage, the function will update its corresponding value.
The Get function is responsible for reading the data in the existing blockchain through the key value. ...
To keep reading, please go to the original article at:
OntologyNetwork - Medium