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 is about how to use ENS custom ethernet address management to share with you. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Our goal is to support ethernet wallets and credit card payments to reduce the dependence of skilled customers. If the customer decides to pay by credit card, we must use our wallet and pay on his behalf.
To this end, we decided to build the back end in Ruby and use two decentralized front-end clients (dApp) in React. We also take advantage of web3, the most mature library that allows you to connect to Ethernet Fong nodes. Since it is written in JavaScript, we decided to implement the AWS Lambda functions in Node.js and call them through our back end.
Address problem
Once we want to keep addresses synchronized in all environments (development, testing, login, production), there will be problems. Each deployment of a new version of any contract requires us to set a new address in the FE client and the AWS Lambda function, and to inform all developers that they should update the version on the local computer. In the long run, this is very annoying and time-consuming. We decided to take some time to solve the problem.
Service under the name of Tai Tai Square
The first solution we came up with was to use the public ENS (Ethernet Square name Service), which is the "DNS" of the smart contract. Similar to DNS, this service points unique domain names to complex, lengthy and hard-to-remember addresses. Everything is stored in the same block chain as our smart contract. In addition, you can change the address at any time, so we don't have to do this in many configurations of the application, just do it in ENS. Very good!
However, domain name registration in ENS takes some time, and you need to lock Ethernet to own it, or register a .test domain name that expires in 28 days. In addition, your domain name does not point directly to your address; it points to the parser contract that you must deploy (to manage all subdomains yourself). In the rapid development phase, we want to bypass this process and do some kind of tagging and versioning.
Our parser
We decided to prepare a simplified version of the parser contract and a set of helpers to simplify the minimum of managing addresses without having to rely on ENS. We also put forward the possibility of tagging addresses, such as v1MagneV2Testgrad late defaultPowerproduction and so on.
We also have a script that you can load in the geth console and use convenient functions to configure the name that points to the address. These helpers can also be imported in JS code. You can find open source code, complete documentation and examples here.
The contract is compatible with the official ENS standard, so you can eventually register your real domain and point to this parser.
Usage example
Suppose we want to write a simple Web server in Express.js that will have two endpoints for setting and obtaining addresses.
In our example, we use Ganache, which allows us to deploy smart contracts and test our network in a local environment. The installation on Mac boils down to downloading the application and opening it-we don't need to configure anything.
Once we run Ganache, we can deploy our parser contract. First, we must clone the repository.
Git clone https://github.com/tooploox/ens-tagged-resolver
Next we install some dependencies:
Cd ens-tagged-resolvernpm install
One of our dependencies is truffle, the development framework, which will help us easily deploy our contracts. We have configured truffle for you to support the Ganache network (in the truffle.js file), so we can deploy it with one command:
. / node_modules/.bin/truffle migrate-- network ganache
We should see the contract address:
PublicResolver: 0x58552b526049049430c070fcd2148c806deb5b6c
We'll need this address later.
Now we can start the Express application. Let's create a directory for it and initialize a new node project:
Mkdir resolvercd resolvernode init-y
Then we can install Express using body-parser and Web3:
Npm install express body-parser web3@0.20-save
We can also download the utility script from our repo:
Curl-O https://raw.githubusercontent.com/tooploox/ens-tagged-resolver/master/tagged-resolver-utils.js
After all, we can create our server in the server.js file.
First, we must import the express and Web3 libraries.
Const express = require ("express"); const bodyParser = require ("body-parser"); const Web3 = require ("web3")
Second, we need our utils module:
Const {taggedResolverUtils} = require (". / tagged-resolver-utils")
Third, we will create an instance of Web3:
Web3 = new Web3 (new Web3.providers.HttpProvider ("http://localhost:7545"));
Port 7545 is the default port used by Ganache, and you can change it in the settings as needed.
Next, we will create a utils instance and pass an Web3 instance as a dependency:
Const resolver = taggedResolverUtils (web3)
Now we can build two endpoints:
Const RESOLVER = "0x58552b526049049430c070fcd2148c806deb5b6c"; / / The address of the deployed contract const app = express (); app.use (bodyParser.urlencoded ({extended: false})); app.use (bodyParser.json ()); app.get ("/ addresses/:domain/:tag", (req, res) = > {const addr = resolver.getAddrForTag (RESOLVER, req.params.domain, req.params.tag); res.send ({addr});}) App.post ("/ addresses", (req, res) = > {const txhash = resolver.setAddrForTag (RESOLVER, req.body.domain, req.body.address, req.body.tag); res.send ({txhash});}); app.listen (3000)
The entire list is available here:
Const express = require ("express"); const bodyParser = require ("body-parser"); const Web3 = require ("web3"); const {taggedResolverUtils} = require (". / tagged-resolver-utils"); web3 = new Web3 (new Web3.providers.HttpProvider ("http://localhost:7545"));const resolver = taggedResolverUtils (web3); const RESOLVER =" 0x43c26d5a8ac0b72f4688648f979c8d4ef27d782d "; / / Address of the resolver contractconst app = express (); app.use (bodyParser.urlencoded ({extended: false})); app.use (bodyParser.json ()) App.get ("/ addresses/:domain/:tag", (req, res) = > {const addr = resolver.getAddrForTag (RESOLVER, req.params.domain, req.params.tag); res.send ({addr);}) / / An example request to the end-point://// curl-X POST\ / / http://localhost:3000/addresses\ /-H 'content-type: application/json'\ /-d'{/ / "domain": "libellum.eth", / / "address": "0xF56547A13c8d62bCE5359C20f33bA570D864f01B" / / "tag": "default" / /} 'app.post ("/ addresses", (req, res) = > {const txhash = resolver.setAddrForTag (RESOLVER, req.body.domain, req.body.address, req.body.tag) Res.send ({txhash});}); app.listen (3000)
Let's save the file and run the server:
Node server.js
We have two endpoints:
[GET] http://localhost:3000/addresses/:domain/:tag[POST] http://localhost:3000/addresses (params: domain, address, tag)
First, we can check whether the address of the libellum.e domain has a default tag:
Http://localhost:3000/addresses/libellum.eth/default
We can see that the address is 0x00000000000000000000000000000000000000000000. This means that it is undefined.
We can simply set it through a POST request:
Curl-X POST\ http://localhost:3000/addresses\-H 'content-type: application/json'\-d'{"domain": "libellum.eth", "address": "0xF56547A13c8d62bCE5359C20f33bA570D864f01B", "tag": "default"}'
Now you can refresh your browser. Look at that! The address has changed.
Thank you for reading! On "how to use ENS custom Ethernet Square address management" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
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.