Technical Guide | Python Smart Contract Development? It’s enough to read this one.
01 Foreword
In the previous technical point of view article, we introduced the intelligent contract system supported by the current main network and the corresponding smart contract development tool SmartX. Many small partners want to get started. In this issue's technical point of view, we will officially begin to talk about the smart contract grammar part.
02 Blockchain API How to use
From ontology.interop.System.Blockchain import GetHeight, GetHeader
From ontology.interop.System.Runtime import Notify From ontology.interop.System.Blockchain import GetHeight Def Main(operation): If operation == 'demo': Return demo() Return False
- 5G Chain Network – New Era Spark Program (Funding) Rural Revitalization Closed Meeting is about to be held
- Data observation: Ethereum DApp ecology begins to recover
- Bitcoin rose $1,000 in two days, which may be the three reasons
Def demo(): height=GetHeight() Notify(height) # print height return height #returns height after the function finishes running
2.2 GetHeader
From ontology.interop.System.Runtime import Notify From ontology.interop.System.Blockchain import GetHeader Def demo(): Block_height=10 Header=GetHeader(block_height) Notify(header) Return header
2.3 GetTransactionByHash
First, the transaction hash is reversed: An example of the GetTransactionByHash function that gets a transaction through a transaction hash is as follows: 9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1
C1890c4d730626dfaa9449419d662505eab3bda2e1f01f89463cc1a4a30a279
{0xc1,0x89,0x0c,0x4d,0x73,0x06,0x26,0xdf,0xaa,0x94,0x49,0x41,0x9d,0x66,0x25,0x05,0xea,0xb3,0xbd,0xa2,0xe1,0xf0,0x1f,0x89,0x46 , 0x3c, 0xc1, 0xa4, 0xa3, 0x0a, 0x27, 0x9f}
\xc1\x89\x0c\x4d\x73\x06\x26\xdf\xaa\x94\x49\x41\x9d\x66\x25\x05\xea\xb3\xbd\xa2\xe1\xa2\xe1\xf0\x1f \x89\x46\x3c\xc1\xa4\xa3\x0a\x27\x9f
From ontology.interop.System.Blockchain import GetTransactionByHash
Def demo():
# tx_hash="9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1"
Tx_hash=bytearray(b"\xc1\x89\x0c\x4d\x73\x06\x26\xdf\xaa\x94\x49\x41\x9d\x66\x25\x05\xea\xb3\xbd\xa2\xe1\xf0 \x1f\x89\x46\x3c\xc1\xa4\xa3\x0a\x27\x9f")
Tx=GetTransactionByHash(tx_hash)
Return tx
From ontology.interop.System.Blockchain import GetTransactionHeight
Def demo():
# tx_hash="9f270aa3a4c13c46891ff0e1a2bdb3ea0525669d414994aadf2606734d0c89c1"
Tx_hash=bytearray(b"\xc1\x89\x0c\x4d\x73\x06\x26\xdf\xaa\x94\x49\x41\x9d\x66\x25\x05\xea\xb3\xbd\xa2\xe1\xf0 \x1f\x89\x46\x3c\xc1\xa4\xa3\x0a\x27\x9f")
Height=GetTransactionHeight(tx_hash)
Return height
2.5 GetContract
From ontology.interop.System.Blockchain import GetContract Def demo(): # contract_hash="d81a75a5ff9b95effa91239ff0bb3232219698fa" Contract_hash=bytearray(b"\xfa\x98\x96\x21\x32\x32\xbb\xf0\x9f\x23\x91\xfa\xef\x95\x9b\xff\xa5\x75\x1a\xd8") Contract=GetContract(contract_hash) Return contract
2.6 GetBlock
2. Get the block by block hash: 3.1 GetTransactionCount From ontology.interop.System.Blockchain import GetBlock
Def demo():
Block=GetBlock(1408)
Return block
From ontology.interop.System.Blockchain import GetBlock
Def demo():
Block_hash=bytearray(b'\x16\xe0\xc5\x40\x82\x79\x77\x30\x44\xea\x66\xc8\xc4\x5d\x17\xf7\x17\x73\x92\x33\x6d\x54 \xe3\x48\x46\x0b\xc3\x2f\xe2\x15\x03\xe4')
Block=GetBlock(block_hash)
03 Block API How to use
There are three functions available for reference in the Block API, which are GetTransactions, GetTransactionCount, and GetTransactionByIndex. We will introduce these three functions in turn.
From ontology.interop.System.Blockchain import GetBlock
From ontology.interop.System.Block import GetTransactionCount
Def demo():
Block=GetBlock(1408)
Count=GetTransactionCount(block)
Return count
From ontology.interop.System.Blockchain import GetBlock
From ontology.interop.System.Block import GetTransactions
Def demo():
Block=GetBlock(1408)
Txs=GetTransactions(block)
Return txs
3 .3 GetTransactionByIndex
Developers can use the GetTransactionByIndex function to get the specified transaction for the specified block.
From ontology.interop.System.Blockchain import GetBlock
From ontology.interop.System.Block import GetTransactionByIndex
Def demo():
Block=GetBlock(1408)
Tx=GetTransactionByIndex(block,0) # index starts from 0.
Return tx
04 Postscript
The Blockchain & Block API serves as the most indispensable part of smart contracts by querying blockchain data and block data in smart contracts. In a later technical perspective, we will discuss how to use other APIs to explore their interaction with the ontology blockchain. In all the grammar parts of this issue, we provide Chinese videos, which can be viewed and learned by friends.
We will continue to update Blocking; if you have any questions or suggestions, please contact us!
Was this article helpful?
93 out of 132 found this helpful
Related articles
- A-share blockchain concept stocks "interim examination" handed over: some profits of several hundred million yuan, and some received a million subsidies
- The volume of trading has not been significantly enlarged, and the rebound is suspected to be more attractive.
- After the Bell chain crashes, it is suspected that the new disk will be restarted.
- Legal Daily Report: How to Inherit Digital Assets (I)
- Market Analysis: BTC receives Yang again, short-term cautiously
- Supervising bitcoin miners? Some experts have made a bad idea to the US Congress.
- Regulations | Dutch central bank urges cryptocurrency-related companies to complete registration by 2020