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 Super World Computer beta testnet or Sepolia.
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
andimg/1.jpeg
)
Step 1: Install ethfs-cli
ethfs-cli
If you have not already done so, you can install ethfs-cli
using the following command:
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
FlatDirectory
ContractA FlatDirectory contract serves as a container that needs to be created before uploading files.
Command Syntax
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: SWC Beta
You will get a FlatDirectory
address after the transaction is confirmed on SWC beta testnet:
Example: Sepolia
You will get a FlatDirectory
address after the transaction is confirmed on Sepolia:
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: SWC Beta
Example log:
Example: Sepolia
Example log:
Step 4: Download Your File!
Now you should be able to download the file you just uploaded.
Command Syntax
Example: SWC Beta
Example: Sepolia
Now, your file has been saved locally.
Step 5: Access Your File via web3://
web3://
Of course, you can also easily access the file you just uploaded using the web3:// protocol.
Example: SWC Beta
text: web3://0xab351F35B82B20C1a253ae16523c5E2D60B56D6E:3337/hello.txt
image: web3://0xab351F35B82B20C1a253ae16523c5E2D60B56D6E:3337/img/1.jpeg
Example: Sepolia
text: web3://0x2f7696D4284358A2E8fDb4DF772dAd60c2c8fbAd:3333/hello.txt
image: web3://0x2f7696D4284358A2E8fDb4DF772dAd60c2c8fbAd:3333/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