Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions docs/build/massa-web3/deweb/deweb-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
id: deweb-link
sidebar_label: deweb link
---

# Deweb Linking

## The Problem
In web2, you can link site A to another site B by displaying the URL of site B in site A.
In web3, displaying a link to a decentralized website is not so straightforward.
A deweb website is identified by one (or several) MNS (Massa Name System) domain but you can't just display it inside a `<a>` tag because most browsers don't handle MNS.
To access a deweb site, you have to incorporate its MNS as a subdomain of the URL of a [deweb provider](../../../deweb/provider/setup-public-instance.mdx). But which provider should you choose when you want to create a link to a deweb site ?
The usual way is to hardcode the provider into a URL like this: `<mns>.<provider domain name>`
The drawback of this approach is that you force the user to use a specific provider. This causes the following issues:
- Add centralization
- If the provider is down, the link is dead
- If the user is running his own provider (see [here](../../../learn/decentralized-web.mdx) and [here](../../../deweb/local-server-config/setup-local-server.mdx)) they can't use it to access the linked site.


## Solution
### resolveDeweb function
Massa-web3 provides a function that abstracts provider selection logic:

```typescript
async function resolveDeweb(uri: string, chainId = CHAIN_ID.Mainnet): Promise<string>
```

- uri: The mns domain of the deweb site. Must be suffixed by ".massa" e.g., "dws.massa", "mip.massa"...
- chainId: Optional parameter to specify the network (mainnet, buildnet) on which the website is stored. Default: mainnet.
- Returns: A promise that resolves to an operational URL containing a provider and the mns URI as subdomain. If no providers have been found, return a fallback URL that redirects to a page allowing the user to choose a public provider.

:::info
This function only works in a browser
:::

For example, if you want to put a link to [Syntra](https://syntra.massa.network/) (onchain token scheduling Dapp powered by [autonomous smart contracts](../../../learn/asc/intro.mdx)) decentralized website in your website, you can do something like that:
```html
<a href={resolveDeweb("syntra.massa")}>syntra.massa</a>
```

Under the hood, `resolveDeweb` function does the following:
- Checks if the current browser natively supports Massa name system. If so, it just returns the URI as passed in parameter:
"`http://<mns domain>.massa/<path and query params>`".
For now, the only browser that supports MNS is [Decentr](https://decentr.net), on Windows OS only.
- If no native support, checks if the [deweb provider plugin](../../../learn/decentralized-web.mdx) of [Massa Station](../../../massaStation/home.mdx) is running. If so, it will return
"`http://<mns domain>.localhost:<deweb plugin port>/<path and query params>`".
e.g. *"massexplo.massa/blocks"* -> *"http://massexplo.localhost:4242/blocks"* (the port is random)
- If no station deweb plugin is available, check if the user is running a [local deweb server](../../../deweb/local-server-config/setup-local-server.mdx). If so, return
"`http://<mns domain>.localhost:8080/<path and query params`".
e.g. *"adm.massa/options/nodes"* -> *"http://adm.localhost:8080/options/nodes"*
- If no local deweb server is running, check if the current website, the one displaying the link, is served to the user by a deweb provider. If the website the user is currently visiting is a decentralized one, it means that it is served to him via a deweb provider. So we can use the same provider the user is currently using to serve the deweb website in the link. The function will thus return
"`http://<mns domain>.<current provider domain>/<path and query params>`".
e.g. *"compound.massa/lend"* -> *"http://compound.massa.network/lend"*
- If none of the previous providers are available, return a fallback URL :
```
https://deweb.massa.network/deweb_redirect?chain_id=<chain id>&deweb_url=<mns domain>
```

This fallback URL has two query parameters:
- *chain_id*: the chain id used in the `resolveDeweb` function
- *deweb_url*: the URI passed as parameter to `resolveDeweb`


### redirection page
The redirection page targeted by the fallback URL is hosted on `deweb.massa` decentralized website.
The page helps the user to get a provider in two means:

- It allows the user to choose a public deweb provider among a community-maintained list. When the user clicks on the button, the deweb website required by the user is automatically opened in a new tab with the URL of the selected provider.
- The page also suggests the user to access the deweb site by using their own deweb provider. The user is invited to download one of the following tools :
- massa station deweb plugin
- decentr browser if the current OS is Windows
- run the provider server binary localy on the computer.

![redirection page](./images/deweb_redirect_page.png)
Comment thread
fleandrei marked this conversation as resolved.

:::caution
Public providers proposed on the page are not checked. Ensure you trust the provider's admin.
:::

### useResolveDeweb
`useResolveDeweb` is a react hook available in Massalabs [react ui kit](https://github.com/massalabs/ui-kit) react tool kit. It's a wrapper around `resolveDeweb` function.

```ts
function useResolveDeweb(Url: string, chainId?: bigint): {resolvedUrl: string, isLoading: boolean, error: string | null}
```

Parameters:
- Url: the URL of the deweb site. The URL can be a mns domain with a deweb provider domain. The ".massa" suffix after the mns domain is not required, but the protocol prefix ("http://") does.
- chainId: Same as for `resolveDeweb`

Result:
- resolvedUrl: the result returned by `resolveDeweb`
- isLoading: Whether the URL creation process is pending or not
- error: eventual error of the process.
10 changes: 10 additions & 0 deletions docs/build/massa-web3/deweb/deweb-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
id: massa-web3-deweb-overview
sidebar_label: Overview
sidebar_position: 1
---

# Overview

**Massa-web3** provides utility code to help builders integrate the decentralized web paradigm into their products easily.
For more info on Deweb, have a look at [Decentralized Web](./../../../learn/decentralized-web.mdx).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions docs/deweb/upload/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ title: Overview

# Overview

To deploy a website on the Massa blockchain, you can use the DeWeb CLI by following the [Uploading a Website](../cli/upload) guide.
This guide provides an overview of the process and the steps to upload your website.
There are two ways to easily deploy and manage your websites on the Massa blockchain:

We are working on additional user-friendly tools to make website deployment accessible to all users, regardless of technical experience.
These upcoming solutions will simplify the upload process, providing an intuitive interface for deploying websites on the Massa blockchain.
- **easy uploader**: It's an online user-friendly tool that makes website deployment and management accessible to all users, regardless of technical experience.
You can use it right now [here](https://dws.massa.network).
- **Deweb CLI**: This is a command-line tool that allows you to upload and manage your sites with more fine-grained control.
To use it, you can follow the [Uploading a Website](../cli/upload) guide that provides an overview of the process and the steps to upload your website.

Stay tuned for more updates!
2 changes: 1 addition & 1 deletion docs/node/all-configs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ instability and/or a complete desynchronization from Massa blockchain.
## Node configuration

You can override the default configuration via
the `massa-node/config/config.toml` file.
the `massa-node/base_config/config.toml` file.

<!-- The content will be added at build time via ./scripts/download-configs.sh -->
<Tabs>
Expand Down
17 changes: 17 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,23 @@ const sidebars = {
},
],
},
{
type: "category",
collapsible: false,
label: "Deweb",
items: [
{
type: "doc",
id: "build/massa-web3/deweb/massa-web3-deweb-overview",
label: "Overview",
},
{
type: "doc",
id: "build/massa-web3/deweb/deweb-link",
label: "Deweb Link",
},
],
},
],
},
{
Expand Down