0.6.0 • Published 20 days ago

web3protocol v0.6.0

Weekly downloads
-
License
MIT
Repository
-
Last release
20 days ago

web3protocol

npm version

Parse and execute ERC-6860 / ERC-4804 web3:// protocol URLs. Used by EVM Browser to browse web3:// on-chain websites.

Usage

import { Client } from 'web3protocol';
import { getDefaultChainList } from 'web3protocol/chains';

// Get a prepared chain list that you can optionally alter, or provide your own
let chainList = getDefaultChainList()

// Configure a client with these chains definitions
let web3Client = new Client(chainList)

let fetchedWeb3Url = await web3Client.fetchUrl("web3://0xA5aFC9fE76a28fB12C60954Ed6e2e5f8ceF64Ff2/resourceName")
// Returns:
// fetchedWeb3Url.httpCode == 200
// fetchedWeb3Url.httpHeaders == {}
// fetchedWeb3Url.output == ReadableStream returning bytes [ 63, 63, 63 ]

Fetch a web3:// URL, get an HTTP status code, HTTP response headers and a ReadableStream.

getDefaultChainList() is provided as a quick way to launch (mix of RPC URLs provided by the Viem.sh library and the chainid.network website), but be aware this could sometimes get out of date.

Apps using web3protocol : web3curl, a simple CURL-like app; EVM Browser, a web3:// electron-based web browser.

Supported standards

Implemented features

  • ERC-6860 (draft) : the base web3:// protocol with auto and manual mode, basic ENS support. This updates ERC-4804 (final) with clarifications, small fixes and changes.
  • ERC-6821 (draft) : ENS resolution : support for the contentcontract TXT field to point to a contract in another chain
  • ERC-6944 (draft) / ERC-5219 (final) : New mode offloading some parsing processing on the browser side
  • ERC-7617 (pending): Add chunk support in ERC-6944 resource request mode
  • ERC-7618 (pending): Add Content-encoding handling in ERC-6944 resource request mode
  • Not standard : Linagee .og domain names

Partially implemented features

  • ERC-7087 (draft) : Auto mode : Add MIME type support (dataURLs not supported yet)

Options

The client takes the following options:

let web3Client = new Client(chainList, {
  multipleRpcMode: "fallback",
  domainNameResolverCache: {
    maxEntries: 256,
    maxAgeSeconds: 30 * 60,
  },
  resolveModeDeterminatorCache: {
    maxEntries: 256,
    maxAgeSeconds: 30 * 60,
  },
})
  • multipleRpcMode (fallback or parallel) : If a chain have multiple RPC configured, by default the fallback mode is used (first one is used, then if failure, the second one, and so on). In the parallel mode, a call is sent simultaneously to all RPCs, and the first one answering is used.
  • domainNameResolverCache: An object of options for domain name resolution caching. May be null to use default options. Otherwise, the object may specify:
    • maxEntries: The maximum number of cached entries. After this, the least-recently-used entry is dropped. Use zero to disable caching.
    • maxAgeSeconds: The maximum number of seconds before a resolution result is no longer considered valid.
  • resolveModeDeterminatorCache: An object of options for resolve mode determination caching. May be null to use default options. Otherwise, the object may specify:
    • maxEntries: The maximum number of cached entries. After this, the least-recently-used entry is dropped. Use zero to disable caching.
    • maxAgeSeconds: The maximum number of seconds before a determination result is no longer considered valid.

If you want to edit the chain list from getDefaultChainList(), to, for example, edit the RPCs of a chain, edit the chain list before giving it to the client :

let chainList = getDefaultChainList()
chainList.find(chain => chain.id == <chainId>).rpcUrls = ['https://<yourRPC>', 'https://<yourSecondRPC>', ...];
let web3Client = new Client(chainList)

Testing

Web3:// test files are located in their own git repository and are imported as a git submodule. After cloning, please run git submodule init and then git submodule update.

Testing is then launched with yarn test

0.6.0

20 days ago

0.5.14

24 days ago

0.5.13

2 months ago

0.5.11

2 months ago

0.5.12

2 months ago

0.5.10

3 months ago

0.5.9

3 months ago

0.5.8

3 months ago

0.5.7

4 months ago

0.5.6

4 months ago

0.5.5

4 months ago

0.5.4

5 months ago

0.5.3

5 months ago

0.4.4

5 months ago

0.5.0

5 months ago

0.5.2

5 months ago

0.5.1

5 months ago

0.3.0

7 months ago

0.4.1

6 months ago

0.3.2

7 months ago

0.4.0

6 months ago

0.3.1

7 months ago

0.4.3

6 months ago

0.4.2

6 months ago

0.3.3

7 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.1.3

9 months ago

0.1.2

11 months ago

0.1.1

12 months ago

0.1.0

12 months ago