Skip to content

Latest commit

 

History

History
108 lines (82 loc) · 8.08 KB

4. Publish the web3 site and view it.md

File metadata and controls

108 lines (82 loc) · 8.08 KB

Publish a static website

With the above features can we build a traditional web site further? Of course we can upload file by file, but this would be very cumbersome. In order to solve this problem, CYFS provides another basic Named Object: DirObject, which is equivalent to FileObject, to upload a directory as a whole. The construction method is as follows.

Use the upload command to publish a static website

Prepare a static website, saved in the local directory www, we publish all the files in the www directory to ood and construct a DirObject using the command cyfs upload www.

PS E:\> cyfs upload www
[info],[2022-06-14 23:19:23.831],<>,cyfs-sdk version 1.0-nightly (2022-06-13), index.js:49298
[info],[2022-06-14 23:19:24.496],<>,[cyfs], Tools directory: C:\Users\Bucky\AppData\Roaming\npm\node_modules\cyfs-tool-nightly, cyfs.js:2538
...
[info],[2022-06-14 23:19:54.137],<>,will get trans task state: http://127.0.0.1:1322/trans/task/state [object Object], index.js:71829

When the command is executed, the local www directory has been uploaded to OOD and a unique connection to Web 3.0 has been generated. You can open cyfs://o/5r4MYfFDmENKMkjtaZztmnpSNTDSoRd6kCWuLSo4ftMS/95RvaS5azgt176LqHAEMEmkr9ieW2DTL7yosXv2fUES8/{directory internal path} to access the corresponding file

Open this static website with cyfs browser

Using the url from the previous step, plus the index.html website entry file placed under www, the final URL is cyfs://o/5r4MYfFDmENKMkjtaZztmnpSNTDSoRd6kCWuLSo4ftMS/ 95RvaS5azgt176LqHAEMEmkr9ieW2DTL7yosXv2fUES8/index.html Copy and paste it into the CYFS browser address bar, and the result is as follows: image

*** Note that typing cyfs://o/5r4MYfFDmENKMkjtaZztmnpSNTDSoRd6kCWuLSo4ftMS/95RvaS5azgt176LqHAEMEmkr9ieW2DTL7yosXv2fUES8/ in the address bar does not automatically complete the index.html. This sometimes causes some inconvenience, and we will try to solve this problem in subsequent releases of CYFS.

In index.html, we can use tags like <img src="image/img.png" /> to refer to resources in a folder via relative paths, and the CYFS browser will automatically fill in the address as cyfs://o/ 5r4MYfFDmENKMkjtaZztmnpSNTDSoRd6kCWuLSo4ftMS/95RvaS5azgt176LqHAEMEmkr9ieW2DTL7yosXv2fUES8/image/img.png, so that the resource is loaded correctly.

Note: It is not possible to use absolute paths, like <img src="/image/img.png" /> to load resources. This is due to the fact that cyfs links add some additional information that is not the same as the traditional URI standard

CYFS semantic links

As we have fully understood from the previous study, CYFS Object URLs are pointers to immutable trusted content. These URLs contain cryptographic information and are definitely not suitable to be entered in the browser address bar. There are times when we still need URLs that point to the most recent content (such as someone's avatar), or there are URLs that we want the user to enter manually into the browser.CYFS provides semantic URLs to address this need.

cyfs://$name/$path

The above design is similar to HTTP URLs, but there are a few core differences

  1. the name system implemented by CYFS based on MetaChain is decentralized and you can actually own a name. the DNS system used by the HTTP protocol is inherently centralized and any domain name held by anyone can in principle be stripped by the governing body (registry). Therefore CYFS names have no suffixes. 2.
  2. CYFS uses smart contracts to implement common transaction scenarios for names
  3. a name on CYFS can only be configured to a specific NamedObjectId, a design that makes the content pointed to by CYFS semantic URLs trustworthy and mutable.

As an example, when entering cyfs://cyfs/index in the CYFS browser, it will parse according to the following logic

  1. the MetaChain is read and the status of the cyfs name is obtained
  2. It is a valid name and points to a DirObject,Id is 95RvaS5azgt176LqHAEMEmkr9ieW2DTL7yosXv2fUES8,Owner is 5r4MYfFDmENKMkjtaZztmnpSNTDSoRd6kCWuLSo4ftMS
  3. CYFS browser, based on the above information, speaks the semantic link cyfs://cyfs/index successfully converted to cyfs://o/5r4MYfFDmENKMkjtaZztmnpSNTDSoRd6kCWuLSo4ftMS/ 95RvaS5azgt176LqHAEMEmkr9ieW2DTL7yosXv2fUES8/index and continue processing as Object Link opens.

Tips

  • The CYFS protocol specifies the URL conversion specification when a Name is configured as a different type of Object
  • The support for subnames like subname.name is not yet finalized
  • The names obtained in the CYFS Beta Network are for testing purposes only and may not be taken directly to the official network, which will better support the migration of legacy domain name owners to the CYFS name system for ecological health reasons.

Purchase and Configuration of Real Names

To explain the DMC, some basic business logic for purchasing names

Buying names

Using meta's bidname command, try to buy a name on the chain

cyfs meta bidname <name> -c <caller_file> -o [name_owner] [bid_price] [rent_price]

If name_owner is not specified, it defaults to the caller's id

The unit of bid_price and rent_price is Qiu, 1 Qiu = 10^-6 DMC

Example, buy a name sixsixsixsix

cyfs meta bidname sixsixsix -c C:\Users\Bucky\.cyfs_profile\People 500000 500000

After the command is executed, a TxId is returned. you can use the receive command to view the results of the transaction.

cyfs meta getreceipt 8YCfQUGm7Aiz2dM3BFKdU1q8fbX6moo4GG6LGzYA8Row

If the name has already been bought, the purchase will naturally fail, and you can replace sixsixsixsix with a unique name that you think of

Wait for the purchase to complete

Because CYFS name purchase is based on auction logic, when bidname is successful, you have to wait for a while before the name will really belong to you and can be bound.

You can use cyfs meta getname <name> to check the purchase status of the name, when the state changes to 0, it means the purchase is complete and you can continue to bind the name

Binding names

After the name is purchased successfully, it is bound to the id of the caller by default. here we have to use the namelink command to bind the name to the Id of the DirObject, so that you can open the page you just opened via cyfs://{name|/index.html

cyfs meta namelink <name> -c <caller> -t <type> <objid>
  • name: the name to bind
  • caller: the identity file of the name purchaser
  • type: we want to bind the name to an id, here we put "obj"
  • objid: the objid to bind to Example: bind ssixsixsix to Id 95RvaS5azgt176LqHAEMEmkr9ieW2DTL7yosXv2fUES8
cyfs meta namelink sixsixsix -c C:\Users\Bucky\.cyfs_profile\People -t obj 95RvaS5azgt176LqHAEMEmkr9ieW2DTL7yosXv2fUES8 

Confirm that the name binding was successful

Wait a while for the transaction to be uploaded, then you can check the name binding status and confirm that the name binding was successful

cyfs meta getname sixsixsix

Open the semantic link in the browser

Visit cyfs://sixsixsix/index.html and it will look like this: image image

Conclusion

With the help of the name concept, we have implemented dynamic cyfs:// through semantic linking, but unlike the HTTP protocol, all valid records must be generated by the domain owner, whose modification records are fully queryable based on blocks. This idea of first getting ObjectId through a path, and getting trusted objects with Object Link is simple and straightforward, but has deep connotations. A little expansion, is better than smart contracts, to achieve a trusted computing infrastructure. Here the content of "Hello, CYFS" is all over, you have understood the most important basic concepts in CYFS, and have experienced how Web3's Ownership is achieved from a technical point of view, and how Web3 "guarantees that everyone has the right to save content and publish content, and to earn revenue directly from the content This will be a major advancement of the Internet itself. In the next phase, you will continue to learn how to use CYFS to build a truly decentralized service: the DEC App, and gain a deep understanding of data property rights and consensus.