At the same time, using the Invoke function requires the built-in state function helper to encapsulate the parameters, as follows:
- The Internet of Things and the blockchain are a panoramic fusion. Wang Yongjuan, a strategic support force letter, talks about “blockchain + internet of things”
- BTC search volume has climbed to a record high, and the mysterious netizen 4Chan's currency price forecast has to be realized?
- Coinbase is increasingly unfriendly to retail investors? After the transaction rate adjustment, it ushered in a 233% rise
- A solution to realize small and micro payments of digital currency
- Fed report: digital currency, stable currency and growing payment patterns
- Zuckerberg is still difficult to eliminate regulatory concerns, can Libra kill a bloody road?
02 Native API Usage
from ontology.interop.Ontology.Native import Invoke
from ontology.builtins import state/pre>
2.1 Ontology native contract list
2.2 Transfer Contract Code
contract_address_ONT = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01') param = state(from_acct, to_acct, ont_amount) # 参数为转出地址，转入地址， 转账金额res = Invoke(1, contract_address_ONT, 'transfer', [param])
2.2 Transfer Contract Code
from ontology.interop.System.Runtime import Notify, CheckWitness from ontology.interop.Ontology.Runtime import Base58ToAddress from ontology.interop.Ontology.Native import Invoke from ontology.builtins import state
# contract address contract_address_ONT = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01' Contract_address_ONG = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\)
Def Main(operation, args): if operation == 'transfer': from_acct = args to_acct = args ont_amount = args ong_amount = args return transfer(from_acct,to_acct,ont_amount,ong_amount )
Def transfer(from_acct, to_acct, ont_amount, ong_amount): # Convert base58 address to bytearray format address from_acct=Base58ToAddress(from_acct) to_acct=Base58ToAddress(to_acct) # Check, the caller must have the same address as the roll-out address if CheckWitness( From_acct): # ONT Transfer if ont_amount > 0: param = state(from_acct, to_acct, ont_amount) # state function is used to encapsulate the transfer related parameters res = Invoke(1, contract_address_ONT, 'transfer', [param]) # invoke call ONT Token native contract transfer if res and res == b'\x01': Notify('transfer succeeded') else: Notify('transfer failed') # ONG transfer, flow as above if ong_amount > 0: param = state(from_acct, to_acct , ong_amount) res = Invoke(1, contract_address_ONG, 'transfer', [param]) if res and res == b'\x01': Notify('transfer succeeded') else: Notify('transfer failed') else: Notify ('CheckWitness failed')
03 SmartX Practice
2. Deployment contract . If you need to apply for test coins during the deployment process, the application address is https://developer.ont.io/applyOng. The deployment results are as follows:
3. Perform a transfer . The relevant parameter settings are required before the transfer function is executed for transfer. In this example, you need to fill in the send address, receive address, number of ONTs for the transfer, and the number of ONGs:
4. The transfer was successful . When the transfer parameters are set correctly, the transfer function is executed and the transfer is successful. The token received will be displayed in the receiving address filled in:
- In this technical point of view, we introduced the Native API of the ontology blockchain. Developers can use the Native API to make native ontology contract calls. The most typical function of a native contract call is contract transfer, which is the core part of the entire smart contract. In the next technical point of view, we will introduce the Upgrade API to explore how to upgrade contracts in ontology smart contracts . In all the grammar parts of this issue, we provide Chinese videos, and the friends can watch the lessons.
Welcome more blockchain technicians to add the Ontology Institute small secretary micro-signal ontresearch as a friend to discuss technology together!