In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to create a NEO light client". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this "how to create a NEO light client" article can help you solve the problem.
Why?
For any project, the first question is always what the purpose of the project is, and the neo-swift project is created for four main reasons.
Developers want to develop distributed iOS applications, and the scope of application is getting wider and wider.
One way to build a developer-friendly community is to create a SDK that is convenient for non-blockchain developers to use.
Some developers like Swift very much.
The development and deployment of mobile devices is becoming increasingly important.
The following is its substance
Read operation
First of all, we need to implement the read operation of the block chain. Blockchain is an open and distributed ledger, and users can read information freely without any form of authentication. One way to achieve this kind of read operation is to run the full node on the machine, which can hold a fully synchronized block chain backup, but there is obviously not enough space on the mobile device to store all the information backup of the block chain. In this case, the way to read the data is to communicate with the person running the full node through RPC.
Public func getBlockBy (index: Int64, completion: @ escaping (NeoClientResult)-> ()) {sendRequest (.getBlock, params: [index, 1]) {result in switch result {case. Failure (let error): completion (. Failure (error)) case. Success (let response): let decoder = JSONDecoder () guard let data = try? JSONSerialization.data (withJSONObject: (response ["result"] as! JSONDictionary), options: .prettyPrinted), let block = try? Decoder.decode (Block.self, from: data) else {completion (.failure (.progresidData)) return} let result = NeoClientResult.success (block) completion (result)}
This set of code can obtain a block from a specific height on the chain. The height of the block at the time of writing this article is 1pm 348je 910, and any block below that height can be retrieved and viewed. If you are interested, you can search the chain for information such as transactions, blocks, and addresses, so as to gain a deeper understanding of how the data structure works. Https://neotracker.io/
Create a wallet
Although reading data from a blockchain makes it easier to collect data, it is more interesting to write the data to the blockchain. This article will explore the two main write operations currently in use in the NEO blockchain, namely, sending assets and claiming GAS. I hope you can have a clear understanding of the most frequently used block chain operations after reading through this article. To write information to the NEO block chain, you first need to obtain a pair of valid public and private keys to authorize your write operation.
"the wallet does not actually store any assets, its function is to use the private key to send write requirements to the block chain."
This is where wallet software users are most likely to have misunderstandings. In fact, NEO assets are stored on the blockchain; the wallet is just an interactive interface through which users can enter their private keys and move the assets, that is, to write information to distributed books.
So how to generate this pair of public and private keys? First, you have to generate a private key, which is a 64-character hexadecimal string that can be any number between 0 and 2 ^ 256 (1.15792089e+65 trillion). The rest of the account information is derived from this number, and the account information includes the private key, WIF (wallet import format), public key and address.
WIF
This is a private key.
0C28FCA386C7A227600B2FE50B7CAEEC86D3BF1FBE471BE89827E19D72AA1D
Because it is too complex, convert the private key to WIF (wallet import format).
5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ
Although it is not yet fully readable, it is certainly easier to read than the original string. WIF also has basic error checking capabilities, so if you send an asset to an address in WIF format, you are more likely to check for errors.
Public key
After successfully obtaining the private key and WIF, the operation begins to become complicated. It is difficult to build the whole client on Swift. Swift does not have a library of encryption methods to achieve elliptic curve encryption, while NEO needs to use secp256r1 elliptic curves to derive public keys.
You can learn more about it through the link below:
Ellipticcurves-Is secp256r1 more secure than secp256k1?-Cryptography Stack Exchange
Https://github.com/neo-project/neo/blob/master/neo/Cryptography/Crypto.cs
With btckeygenie, modifications can be imported into the golang wallet generator and compiled using gomobile. It may be possible to write a mature ECDSA (Elliptic Curve Digital signature algorithm) library in Swift language in the future, but it cannot be achieved at this stage.
Address
After obtaining the public key, you can have a "full account" as long as you get the address. At this stage, put the hexadecimal or WIF private key into the go language package to generate a complete account.
Public init? (wif: String) {var error: NSError? Guard let wallet = GoNeowalletGenerateFromWIF (wif, error) else {return nil} self.wif = wif self.publicKey = wallet.publicKey () self.privateKey = wallet.privateKey () self.address = wallet.address () self.hashedSignature = wallet.hashedSignature () / / We'll discuss thislater}
Completing the above steps actually completes the first and important step in SDK development.
Send assets and claim GAS
Once the wallet is generated, the asset can be transferred to the wallet address, but applications such as Neon Wallet are also needed to send assets or claim GAS, and of course we want to create a SDK that can be embedded in any iOS mobile app.
This requires the implementation of the sendrawtransaction RPC method, with reference to the documentation.
The load of the RPC method is as follows:
"params": ["80000001195876cb34364dc38b730077156c6bc3a7fc570044a66fbfeeea56f71327e8ab0000029b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500c65eaf440000000f9a23e06f74cf86b8827a9108ec2e0f89ad956c9b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50092e14b5e00000030aab52ad93f6ce17ca07fa88fc191828c58cb71014140915467ecd359684b2dc358024ca750609591aa731a0b309c7fb3cab5cd0836ad3992aa0a24da431f43b68883ea5651d548feb6bd3c8e16376e6e426f91f84c58232103322f35c7819267e721335948d385fae5be66e7ba8c748ac15467dcca0693692dac"]
Provenance:
Official documents-> NetworkProtocol neo-project/neo Wiki GitHub
If the result is "true", it means that the current transaction has been successfully broadcast to the whole network, and it is done!
If the result is "false", it means that the current transaction has not been successfully broadcast, which can be caused by many reasons, such as double payment, incomplete signature and so on. In this example, the transaction was successfully broadcast after confirmation, but the second broadcast could not be made because of double payments.
In the end, the hexadecimal string output by javascript sdk will finally match its own string.
After following the javascript, you can draw a clear schematic diagram of the complete memory configuration for sending asset transactions, as follows:
If you go through each section in detail, you will see that the transaction starts from the lowest memory address (0x00) to the highest memory address (0xXX), where XX is the transaction length in hexadecimal.
The first metadata: includes the type, version, and attributes of the transaction. The transaction type is transfer / 80max, and the version is / 00 / (may need to be upgraded? ) the transaction mentioned here does not contain specific attributes. Input:Input is the really interesting part. The balance of the NEO or any blockchain system is different from any number of the database in the traditional server client model. In practice, the balance is presented in the following form.
"GAS": {"balance": 29.02751232, "unspent": [{"index": 1, "txid": "74cc80ffb1588a964fc6a656302bfe5c3465d2214c64211d8fe2f322cb342a29", "value": 28.0}, {"index": 0, "txid": "819e00aeca6be42a436b9535b2c165670be9011bbd41afe5d475b0c858a7f6c5", "value": 29.02751232}, {"index": 1, "txid": "3d96fb31185394147b237a987730fa2e4c1848744530842e468a6d9bdeec4069", "value": 0.02751232}]}
The total balance is the sum of all the objects in the unconsumed series under the ID of a transaction. When we send assets such as GAS, we need to use these unconsumed Input to generate a result. For example, if you need to send 28 GAS, you need an Input of 28, but if you need to send 29 GAS, you need two Input, one with a value of 28 and the other with a value of 1. You see, all transactions are summed up to an arbitrary number. The biggest transaction that can be done so far is to send 30 GAS, which requires 3 Input.
The second metadata: represents the number of times Output. For example, if we want to send 28 GAS, only one Output will be generated, because we will consume all the Output, leaving only one Output, which is the new transaction information sent to the recipient. But if you want to send 27 GAS, the situation will be more complicated, because there will be two Output, one Output is sent to the recipient's 27 GAS, the other is sent back to the sender's change. So one or two Output are generated for each transaction. Each asset in the asset ID:NEO network has its own unique identifier. There are currently two identifiers, but there may be countless identifiers in the future. Send asset amount: this is self-evident, need to be multiplied by 100000000 to verify the floating point precision receiver address hash value: this is also self-evident, on behalf of the recipient address hash value Total-Send total: this is sent back to the wallet address change, if the change is 0, you do not need to fill in this field or the following sender address hash value sender address hash value: receive change address hash value
Signature: continue to use the same p256 elliptic curve to sign the payload, which is everything before the third metadata block.
NEO public key: that is, an ordinary public key, but including prefix and suffix bytes, I do not know the use of prefix and suffix, may have the function of checking errors.
This is the end of the introduction to "how to create a NEO light client". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.