Comment on page
Direct deal-making with Client contract
This page covers the client contract, and includes a tutorial on how developers can use the client contract to create storage deals programmatically.
Before continuing, make sure you have the following software installed and prerequisites ready:
- Yarn or NPM (Yarn is used in this tutorial)
- A code editor such as VS Code
- A wallet with Calibration testnet FIL
Let’s run through how to create storage deals using smart contracts.
First, let’s grab the kit and set up the development environment.
- 1.Clone the Filecoin virtual machine deal-making kit, including all submodules:git clone --recurse-submodules https://github.com/filecoin-project/fvm-starter-kit-deal-making.gitThis will copy the FVM deal-making kit into your current directory and initiate the
- 2.Move into the
fvm-starter-kit-deal-makingdirectory and grab all the dependencies using
- 3.Now that all the packages are downloaded, you need to create a
.envfile with your private key. This is so the Hardhat kit knows what wallet to use for transactions. Open up the repo in your code editor of choice and find the file titled
.env.example. Rename the file to
.env. You can do this in your terminal by running:mv .env.example .env
Take precautions and never share your private key with anyone! Also make sure to not check your private key into Git. The
.gitignoreof the Hardhat kit is already set to ignore
- 5.Deploy the contracts with
hardhat:yarn hardhat deployThis should compile and deploy all the contracts, including the client contract, which is the one we will be interacting with. Take note of the address of the deployed contract; we'll be using this later.
Before storing a file with a storage provider it needs to be prepared by turning it into a
.carfile. The metadata also needs to be recorded. The Hardhat kit has a tool which can do this for you. However, to keep things nice and simple, we’re going to use the FVM Data Depot website. This website will automatically convert files to the
.carformat, output all the necessary metadata, and act as an HTTP retrieval point for the storage providers.
- 2.Click Upload File and select a file you wish to upload.
- 3.Select the File ID of the file to read all the relevant metadata. Make a note of the:
We’ll use this information in the next step when invoking the
- Piece CID
- Payload CID
- Car size
- Piece size
Now that we have the
.carfile prepared in the data depot, we can invoke the MakeDealProposal method on the smart contract we deployed earlier. To do this, we will run the
make-deal-proposaltask in Hardhat. There are quite a few parameters to include in this call:
contract: the address of your deployed
- `piece-cid: gathered from the previous step.
piece-size: gathered from the previous step.
car-size: gathered from the previous step.
location-ref: The location of where the storage provider can find the .car file. This is the
URLfrom the previous step.
When calling the
make-deal-proposaltask in Hardhat, your command will look something like this:
yarn hardhat make-deal-proposal \
--contract 0x0219eB1740C315fe5e20612D7E13AE2A883dB3f4 \
--piece-cid baga6ea4seaqn4eomxfk3ttog7lnvlvedu7nia377w4gotw2pm746k6kq7gwe6ga \
--piece-size 2097152 \
--verified-deal false \
--car-size 1439368 \
--label baga6ea4seaqn4eomxfk3ttog7lnvlvedu7nia377w4gotw2pm746k6kq7gwe6ga \
--start-epoch 180000 \
--end-epoch 700000 \
--storage-price-per-epoch 0 \
--provider-collateral 0 \
--client-collateral 0 \
--extra-params-version 1 \
--location-ref "https://bafybeidguwwno5ohjss7g4l6ygvyy3dzxxrkkgtxqkobnnxnu62aw4ipxa.ipfs.w3s.link/ipfs/bafybeidguwwno5ohjss7g4l6ygvyy3dzxxrkkgtxqkobnnxnu62aw4ipxa/baga6ea4seaqn4eomxfk3ttog7lnvlvedu7nia377w4gotw2pm746k6kq7gwe6ga.car \
--skip-ipni-announce true \
--remove-unsealed-copy true \
Parameters such as the
price-per-epochare set to
0. On mainnet, these would be determined by storage providers, but since this is on the Calibration testnet, the storage providers should pick up the jobs even with these parameters set to
Now if you’ve invoked the task with all the correct parameters, the method will execute on-chain and emit an event that Boost storage providers will be listening for. If the deal is well-formed and the parameters are acceptable, they will download the
.carfile, double-check to ensure the
piece-sizematch the deal, and publish your storage deal! This could take up to a day. Once the deal is published, you'll be able to find it on a Calibration testnet block explorer. The client in the deal should be the
t4address of the smart contract we called
After emitting an event and waiting for storage providers to accept your deal, you can monitor its status on a provided Boost logs dashboard. This feature is only available on the Calibration testnet. See this guide on GitHub for help diagnosing why deals might not be accepted and adjusting your proposal for re-submission.
During this tutorial, we have shown the significance of making deals using smart contracts and then walked through making a storage deal using the FVM deal-making kit and web3.storage. Developers can make use of this workflow to integrate decentralized storage on Filecoin with their smart contracts and decentralized applications.