Upload your file/folder with ethfs-cli
Last updated
Last updated
In this tutorial, we will demonstrate how to upload files or folders to an EVM compatiable chain using the ethfs-cli tool. Find the list of the 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
)
ethfs-cli
If you have not already done so, you can install ethfs-cli
using the following command:
FlatDirectory
ContractA FlatDirectory contract serves as a container that needs to be created before uploading files.
The following command creates a FlatDirectory
on the default chain (Ethereum Mainnet) using the private key 0x112233...
If you intend to create it on other chains that support EVM, you need to add the chain ID using the -c
flag, for example, 11155111
for Sepolia.
You will get a FlatDirectory
address after the transaction is confirmed:
In this section, you will upload the files/folder into the FlatDirectory
that you just created using the following command:
Notice that you have the option to specify the file upload type: calldata
, blob
. The default type is blob
which requires network support for EIP-4844.
For example:
Now you should be able to download the file you just uploaded.
Run the command to download the file.
Now, your file has been saved locally.
web3://
Of course, you can also easily access the file you just uploaded using the web3:// protocol. For example,
web3://0x2f7696D4284358A2E8fDb4DF772dAd60c2c8fbAd:3333/hello.txt
or,
web3://0x2f7696D4284358A2E8fDb4DF772dAd60c2c8fbAd:3333/img/1.jpeg
To gain further insights into web3://
protocol, you can visit web3url.io.
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: