Upload your file/folder with ethfs-cli

Introduction

In this tutorial, we will demonstrate how to use the ethfs-cli tool to upload files or folders to EVM-compatible chains such as Sepolia or QuarkChain L2 testnet.

You can find the full list of currently supported chains here.

For the content to be uploaded, let's assume that

  • there is a folder to be uploaded; (e.g., dist)

  • there are two files in the folder. (e.g., hello.txt and img/1.jpeg)

Step 1: Install ethfs-cli

If you have not already done so, you can install ethfs-cli using the following command:

npm i -g ethfs-cli

If you installed it a long time ago, please run the same command to update to the latest version.

Step 2: Create a FlatDirectory Contract

A FlatDirectory contract serves as a container that needs to be created before uploading files.

Command Syntax

ethfs-cli create -p <private-key> -c <chain-id>

This command creates a FlatDirectory on a specified blockchain. You need to provide a private key and the chain ID.

If the part -c <chain-id> is omitted, Ethereum Mainnet will be specified by default.

Example: Sepolia

You will get a FlatDirectory address after the transaction is confirmed on Sepolia:

Example: QuarkChain L2

You will get a FlatDirectory address after the transaction is confirmed on QuarkChain L2 testnet:

Step 3: Upload Files

In this section, you will upload the files/folder into the FlatDirectory that you just created.

Command Syntax

You need to provide the contract address (-a <address>), chain ID (-c <chain-id>), private key (-p <private-key>), and the type of upload (-t <upload-type>).

Notice that you have 2 options to specify the file upload type: calldata, blob. The default type is blob which requires network support for EIP-4844.

If the part -c <chain-id> is omitted, Ethereum Mainnet will be specified by default.

Example: Sepolia

Example log:

Example: QuarkChain L2

Example log:

Step 4: Download Your File!

Now you should be able to download the file you just uploaded.

Command Syntax

Example: Sepolia

Example: QuarkChain L2

Now, your file has been saved locally.

Step 5: Access Your File via web3://

Of course, you can also easily access the file you just uploaded using the web3:// protocol.

Example: Sepolia

text: web3://0x8FE13f6697B1A8c34460D0E1375bbD205834D208:3333/hello.txt

image: web3://0x8FE13f6697B1A8c34460D0E1375bbD205834D208:3333/img/1.jpeg

Example: QuarkChain L2

text: web3://0xbaD27E1893B5E096c8e638a781eC93d7413d10F3:110011/hello.txt

image: web3://0xbaD27E1893B5E096c8e638a781eC93d7413d10F3:110011/img/1.jpeg

Note: In the above URLs, you may need to specify a different chain ID than the one used in the ethfs-cli commands. This distinct chain ID is necessary for identifying the EthStorage network responsible for storing the files.

To gain further insights into web3:// protocol, you can visit web3url.io.

Optional: Using Your Own RPC Endpoint

You can also specify your own RPC for better performance by -r flag in the above steps.

For example when create FlatDirectory contract:

When uploading files:

Last updated