In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the method of etherfang prophecy machine and intelligent contract development". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "what is the method of etherfang prophecy machine and intelligent contract development"!
The Tinypay.co DNS Oracle
Tinypay's oracle does three simple things:
Extract the 'ClientCreated' event from the contract
Validate DNS records with data from events
After the domain name is confirmed, send 'ConfirmClient' transaction' to the contract
I have gone through several iterations and finally achieved them, and I hope to guide you through them to understand the development of Etay Fong.
You can also use RPC directly, but it seems you shouldn't do it.
The first time I wrote a prophecy machine, I used Go-Ethereum. I want to use RPC API directly for all communication with the Ethereum node.
This is interesting because I can learn a lot about the lower levels of ethernet protocol storage and data coding. I had to manually recreate the ABI (application binary interface) in the code and use it to send and decrypt messages. ABI is necessary to define how contracts interact and how to extract data from the original bytes online.
The actual extraction of data from the event proved to be much more complicated than I thought. The processing of the event for Go-Ethereum was not completed. I was forced to manually poll the RPC endpoint and figure out how to decode the binary data from the original event. Of course, Go-Ethereum seems to be the focus of the ethernet team, who should be well aware of Go-Ethereum 's problems in watching and decoding events. I hope they will improve soon, which will make Go-Ethereum a better choice for writing prophecy machines and other ethersquare client applications.
Low-level RPC API and decoding API prove to be very inefficient, and they are iterating faster, so.
Web3 is a good abstraction.
For the second iteration, I switch to node.js and use the web3 library to communicate with the geth node. This gives me built-in abstracted event queries, data extraction and formatting, and obviously makes development easier.
I started using Alex Beregszaszi's very useful tinyoracle' guide, which allowed me to get good results in the second edition.
The following code has been selected and edited, and the complete code can be found in the github repository (this iteration is labeled v0.0.2)
Var Web3 = require ('web3'); var web3 = new Web3 (); var contracts = require (path.join (_ _ dirname,' gen_contracts.json')); / / First we instruct web3 to use the RPC provider// first we specify that web3 uses RPC interface web3.setProvider (new web3.providers.HttpProvider ('http://' + opts.rpc_host +':'+ opts.rpc_port)) / / This isn't strictly necessary here, but goes to show the step / / required to "unlock" the account before sending transactions.// this is not strictly required, but it shows the steps required to "unlock" the account before sending the transaction. If (! web3.personal.unlockAccount (web3.eth.coinbase, opts.wallet_password)) {console.error ('Could not unlock'); process.exit ();} / Here we register the filter with the ethereum node, / / and then begin polling for updates.// here, we use the Taifang node to register the filter, and then start polling for updates function runLoop (o) {var filter = web3.eth.filter ({address: o.contract_address}) Filter.watch (function (err, results) {if (err) {console.log ('WATCH ERROR:', err); process.exit ();} console.debug (results);});} / If the contract isn't deployed yet, if we deploy it here// does not already have a deployment contract, we will deploy it here. If (! opts.contract_address) {/ / This block of code loads the ABI for interpreting contract data.// this code block loads ABI to interpret contract data. Var dmC = web3.eth.contract (JSON.parse (contracts.DomainMicropay.abi)); var x = {from: web3.eth.coinbase, data: contracts.DomainMicropay.bin, gas: 1000000}; / / send the transaction for installing the contract.// sends the transaction for the deployment contract. DmC.new (x, function (err, resp) {if (err) {console.error ('Loading contract', err); process.exit ();} var addr = resp.address; if (! addr) {console.log (' Pending tx:', resp.transactionHash);} else {console.log ('Deployed Address:', addr); opts.contract_address = addr; runLoop (opts) }});} else {runLoop (opts); / / in either case, start the polling event loop. / / in either case, start the polling event loop} Truffle should be the framework you most want to use
Finally, in the third iteration, I gave up what I had done. We have used ConsenSys's excellent tool Truffle at the front end of our network. I just copied the generated artifacts into my node.js project, included them directly, and got to work.
With Truffle, we were able to compile our Solidity contract into a JavaScript library that validates important details such as the contract's deployment address and completely replaces low-level RPC communication. Viewing events, sending transactions and querying data becomes a simple API call generated directly from our contract.
/ / This code extract shows the whole event loop abstracted behind the actual event name: ClientConfirmed and ClientCreated.// this code shows the actual abstracted events throughout the event loop: ClientConfirmed and ClientCreated. StartWatcher: function (rpcUrl, unlockPass) {password = unlockPass | | password;web3.setProvider (new web3.providers.HttpProvider (rpcUrl)); DomainMicropay.setProvider (web3.currentProvider); contract.ClientConfirmed ({}, eventOpts (), function (err, data) {if (err) {console.log ('Error ClientConfirmed:', err); return } console.log ('Event ClientConfirmed:', data.args.domain);}); contract.ClientCreated ({}, eventOpts (), function (err, data) {if (err) {console.log ('Error ClientCreated:', err); return;} console.log ('Event ClientCreated:', data.args.domain) Contract.getPaymentContractForDomain .call (data.args.domain) .then (beginDomainVerification (data)) .catch (errFn ('Unhandled Error:'));});}
As you can see, Truffle provides some very good abstractions for using and interacting with smart contracts.
Thank you for your reading, the above is the content of "what is the method of etherfang prophecy machine and intelligent contract development". After the study of this article, I believe you have a deeper understanding of what the etheric square prophecy machine and intelligent contract development method is, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.