Skip to content

Commit 7e70336

Browse files
Merge pull request #2209 from filecoin-project/update/add-dot-env-client-contract-tut
Adds `.env` process to Client Contract Tutorial.
2 parents 710789a + dcebd37 commit 7e70336

File tree

2 files changed

+48
-55
lines changed

2 files changed

+48
-55
lines changed
Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,70 @@
11
---
22
description: >-
3-
The Client Contract allows developers to create storage deals programmatically
4-
via smart contracts.
3+
This page covers the client contract, and includes a tutorial on how developers can use the client contract to create storage deals programmatically.
54
---
65

76
# Client contract tutorial
87

9-
In this tutorial, we will cover the background of creating storage deals via smart contracts and how to create storage deals with smart contracts on the FEVM (Ethereum Virtual Machine on top of the Filecoin blockchain). Before continuing, you will need the following software preinstalled on your computer:
8+
In this tutorial we will cover the background of creating storage deals using smart contracts, and how to create storage deals with smart contracts on the [Filecoin virtual machine](../../reference/general/glossary.md#filecoin-virtual-machine).
9+
10+
You can find a video form of this walkthrough on [ETHGlobal’s YouTube Channel](https://www.youtube.com/watch?v=27EV3gQGY9k).
11+
12+
## Prerequisites
13+
14+
Before continuing, make sure you have the following software installed and prerequisities ready:
1015

1116
* Git
1217
* NodeJS
1318
* Yarn or NPM (Yarn is used in this tutorial)
1419
* A code editor such as VS Code
1520
* A wallet with Calibration testnet FIL
1621

17-
You can find a video form of this walkthrough on [ETHGlobal’s YouTube Channel](https://www.youtube.com/watch?v=27EV3gQGY9k).
18-
19-
### Dealmaking workflows <a href="#dealmaking-workflows" id="dealmaking-workflows"></a>
20-
21-
Before we get started, we recommend reading about programmatic storage with Filecoin here. There are two methods to programmtic storage, which are direct dealmaking and aggregated dealmaking. We will cover direct dealmaking with the client contract tutorial.
22-
23-
### Steps <a href="#steps" id="steps"></a>
22+
## Steps
2423

25-
Let’s now run through how to create storage deals via smart contracts.
24+
Let’s run through how to create storage deals using smart contracts.
2625

27-
#### Setup <a href="#setup" id="setup"></a>
26+
### Setup
2827

2928
First, let’s grab the kit and set up the development environment.
3029

31-
1. Clone the Filecoin virtual machine deal-making kit, including all submodules:\
30+
1. Clone the Filecoin virtual machine deal-making kit, including all submodules:
3231

33-
34-
```
32+
```shell
3533
git clone --recurse-submodules https://github.com/filecoin-project/fvm-starter-kit-deal-making.git
3634
```
3735

38-
\
39-
This will copy the fvm deal-making kit into your current directory and initiate the `go-generate-car` submodule.
40-
2. Moving into the `fvm-starter-kit-deal-making` directory and grab all the dependencies using `yarn`:\
36+
This will copy the FVM deal-making kit into your current directory and initiate the `go-generate-car` submodule.
4137

38+
2. Move into the `fvm-starter-kit-deal-making` directory and grab all the dependencies using `yarn`:
4239

43-
```
40+
```shell
4441
cd fvm-starter-kit-deal-making
4542
yarn
4643
```
4744

45+
3. Now that all the packages are downloaded, you need to create a `.env` file 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:
4846

49-
3. Now that all the packages are downloaded, we will need to create a `.env` file 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`:\
50-
51-
52-
```
47+
```shell
5348
mv .env.example .env
5449
```
5550

51+
4. Within the `.env` file, replace the example private key with your actual private key. If you are using Metamask, follow [this tutorial to get your private key](https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key).
5652

57-
4. Replace the example private key with your actual private key. If you are using Metamask, follow [this tutorial to get your private key](https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key).\
58-
53+
{% hint style="info" %}
54+
Take precautions and never share your private key with anyone! Also make sure to not check your private key into Git. The `.gitignore` of the Hardhat kit is already set to ignore `.env` files.
55+
{% endhint %}
5956

60-
Remember to take precautions to never share your private key with anyone or check it into Git! The `.gitignore` of the hardhat kit is already set to ignore `.env` files.\
57+
5. Deploy the contracts with `hardhat`:
6158

62-
5. Deploy the contracts with `hardhat`:\
63-
64-
65-
```
59+
```shell
6660
yarn hardhat deploy
6761
```
6862

69-
\
70-
This should compile and deploy all the contracts, including the client contract, which is the one we will be interacting with. Copy and take note of the address of the deployed contract for later.
63+
This 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.
7164
72-
### Preparing a file for storage <a href="#preparing-a-file-for-storage" id="preparing-a-file-for-storage"></a>
65+
### Preparing a file for storage
7366
74-
Before storing a file with a storage provider, it needs to be prepared by turning it into a `.car` file, and the metadata must be recorded. To do this the Hardhat kit has a tool [which can do this for you](https://github.com/filecoin-project/fevm-hardhat-kit/tree/main/tools). However, to keep things nice and simple, we’re going to use the [FVM Data Depot website](https://data.lighthouse.storage/). This website will automatically convert files to the `.car` format, output all the necessary metadata, and act as an HTTP retrieval point for the storage providers.
67+
Before storing a file with a storage provider it needs to be prepared by turning it into a `.car` file. The metadata also needs to be recorded. The Hardhat kit has a tool [which can do this for you](https://github.com/filecoin-project/fevm-hardhat-kit/tree/main/tools). However, to keep things nice and simple, we’re going to use the [FVM Data Depot website](https://data.lighthouse.storage/). This website will automatically convert files to the `.car` format, output all the necessary metadata, and act as an HTTP retrieval point for the storage providers.
7568
7669
1. Go to the [FVM Data Depot website](https://data.lighthouse.storage/) and create an account.
7770
2. Click **Upload File** and select a file you wish to upload.
@@ -85,12 +78,12 @@ Before storing a file with a storage provider, it needs to be prepared by turnin
8578
8679
We’ll use this information in the next step when invoking the `MakeDealProposal` method.
8780
88-
### Invoke the MakeDealProposal method <a href="#invoke-the-makedealproposal-method" id="invoke-the-makedealproposal-method"></a>
81+
### Invoke the `MakeDealProposal` method
8982
9083
Now that we have the `.car` file 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-proposal` task in Hardhat. There are quite a few parameters to include in this call:
9184
92-
* `contract`: the address of your deployed `ClientContract.sol`
93-
* \`piece-cid: gathered from the previous step.
85+
* `contract`: the address of your deployed `ClientContract.sol`.
86+
* `piece-cid: gathered from the previous step.
9487
* `piece-size`: gathered from the previous step.
9588
* `car-size`: gathered from the previous step.
9689
* `start-epoch`: The block number you want the deal to begin on. It should be a block in the future. You can find the current block number on [FilFox Calibration](https://calibration.filfox.info/en).
@@ -99,7 +92,7 @@ Now that we have the `.car` file prepared in the data depot, we can invoke the M
9992
10093
When calling the `make-deal-proposal` task in Hardhat, your command will look something like this:
10194
102-
```
95+
```shell
10396
yarn hardhat make-deal-proposal \
10497
--contract 0x0219eB1740C315fe5e20612D7E13AE2A883dB3f4 \
10598
--piece-cid baga6ea4seaqn4eomxfk3ttog7lnvlvedu7nia377w4gotw2pm746k6kq7gwe6ga \
@@ -120,14 +113,14 @@ yarn hardhat make-deal-proposal \
120113
121114
Parameters such as the `collateral` and `price-per-epoch` are 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 `0`.
122115
123-
### Storage provider picks up the job <a href="#storage-provider-picks-up-the-job" id="storage-provider-picks-up-the-job"></a>
116+
### Storage provider picks up the job
124117
125-
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 to. If the deal is well-formed and the parameters are acceptable, they will download the .car file, double-check to ensure the `piece-cid` and `piece-size` match the deal and publish your storage deal! This could take up to a day. Once the deal is published, you can find it on a Calibration testnet block explorer. The client in the deal should be the `t4` address of the smart contract we called `MakeStorageDeal` on.
118+
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 `.car` file, double-check to ensure the `piece-cid` and `piece-size` match 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](../../networks/calibration/explorers.md). The client in the deal should be the `t4` address of the smart contract we called `MakeStorageDeal` on.
126119

127-
### Monitoring deal proposal acceptance <a href="#monitoring-deal-proposal-acceptance" id="monitoring-deal-proposal-acceptance"></a>
120+
### Monitoring deal proposal acceptance
128121

129122
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](https://github.com/filecoin-project/community/discussions/659) for help diagnosing why deals might not be accepted and adjusting your proposal for re-submission.
130123

131-
### Conclusion <a href="#conclusion" id="conclusion"></a>
124+
## Conclusion
132125

133126
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.

smart-contracts/developing-contracts/hardhat.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ First, we need to grab the starter kit and install the dependencies.
2626

2727
1. Clone the Hardhat starter kit and move into the new `fevm-hardhat-kit` directory:
2828

29-
```
29+
```shell
3030
git clone https://github.com/filecoin-project/fevm-hardhat-kit.git
3131
cd fevm-hardhat-kit
3232

@@ -39,7 +39,7 @@ cd fevm-hardhat-kit
3939

4040
2. Use Yarn to install the project’s dependencies:
4141

42-
```
42+
```shell
4343
yarn install
4444

4545
# [1/4] 🔍 Resolving packages...
@@ -51,19 +51,19 @@ yarn install
5151
# ✨ Done in 16.34s.
5252
```
5353

54-
3. Create an environment variable for your private key. Each wallet has a different process for exporting your private key - check your wallet’s official documentation.
54+
3. Add your private key to the `.env` file:
5555

56-
```sh
57-
export PRIVATE_KEY='<YOUR PRIVATE KEY>'
58-
59-
# For example
60-
# export PRIVATE_KEY='d52cd65a5746ae71cf3d07a8cf392ca29d7acb96deba7d94b19a9cf3c9f63022'
56+
```shell
57+
PRIVATE_KEY= <YOUR PRIVATE KEY>
6158
```
6259

63-
4. Always be careful when dealing with your private key. Double-check that you’re not hardcoding it anywhere or committing it to source control like GitHub. Anyone with access to your private key has complete control over your funds.
64-
5. Get the addresses associated with the private key from Hardhat:
60+
{% hint style="info" %}
61+
Always be careful when dealing with your private key. Double-check that you’re not hardcoding it anywhere or committing it to Git. Remember: anyone with access to your private key has complete control over your funds.
62+
{% endhint %}
63+
64+
4. Get the addresses associated with the private key from Hardhat:
6565

66-
```sh
66+
```shell
6767
yarn hardhat get-address
6868

6969
# Ethereum address (this addresss should work for most tools): 0x11Fc070e5c0D32024c9B63c136913405e07C8c48
@@ -84,7 +84,7 @@ Make sure that your account has funds. You won’t be able to deploy any contrac
8484

8585
1. Run `hardhat deploy` to deploy all the contracts. This can take a few minutes:
8686

87-
```sh
87+
```shell
8888
yarn hardhat deploy
8989

9090
# Compiled 18 Solidity files successfully
@@ -98,7 +98,7 @@ yarn hardhat deploy
9898

9999
2. Interact with the contracts using the available functions within the `tasks` folder. For example, you can get the balance of the `simple-coin` contract by calling the `get-balance` function:
100100

101-
```sh
101+
```shell
102102
yarn hardhat get-balance --contract '0xA855520fcCB6422976F7Ac78534edec2379Be5f6' --account '0x11Fc070e5c0D32024c9B63c136913405e07C8c48'
103103

104104
# Reading SimpleCoin owned by 0x11Fc070e5c0D32024c9B63c136913405e07C8c48 on network calibration

0 commit comments

Comments
 (0)