originally derived from hammertoe's fdt-deal-monitor
This is an example daemon that listens to events emitted from a smart contract and Filecoin and passes them to Edge-UR for aggregation and storage on Filecoin.
This is intended as an example flow and for use in demos and hackathons, this is not intended for use in production and entirely use at your own risk.
There is an example contract in contracts
that has the event and a method you can call to initiate the storage.
- Clone this repository locally:
git clone https://github.com/application-research/fevm-data-segment
cd fevm-data-segment
- Install dependancies:
yarn install
- Set you PRIVATE_KEY:
export PRIVATE_KEY=xxxx
yarn hardhat deploy
You need to specify the RPC endpoint of a Filecoin node, the Edge-UR API address, and the contract address, in the .env
file, then start the daemon with:
node fdt-deal-monitor-ethers.js
You can call the contract to get it to pass an existing CID to the Edge-UR instance to store:
npx hardhat store-data --contract 0x3f6748D2e66b4634Cc9b570f0Ac8b89AED963b21 --uri https://bafybeie4og2w7u6c5sq5sfeajrnohqvs6i4fjjqruayopr2xbmapahrn5i.ipfs.dweb.link/dataverse_logo.png
To deploy to Calibration Network
run npx hardhat deploy --network calibration
-
Cid
deployed to:0x57AdD0E4ACa42C8C31531672B9B9E11B37076a99
-
Proof
deployed to:0xa6E03821BF7c7e6A86F521C360CedB7Cf461122d
-
EdgeAggregatorOracle
deployed to:0x13653C684011CF94843636C490025489A6397673
npx hardhat node
npx hardhat deploy --network calibration
Open up your terminal (or command prompt) and navigate to a directory you would like to store this code on. Once there type in the following command:
git clone --recurse-submodules https://github.com/filecoin-project/fevm-hardhat-kit.git
cd fevm-hardhat-kit
yarn install
This will clone the hardhat kit onto your computer, switch directories into the newly installed kit, and install the dependencies the kit needs to work.
You can get a private key from a wallet provider such as Metamask.
Add your private key as an environment variable by running this command:
export PRIVATE_KEY='abcdef'
If you use a .env file, don't commit and push any changes to .env files that may contain sensitive information, such as a private key! If this information reaches a public GitHub repository, someone can use it to check if you have any Mainnet funds in that wallet address, and steal them!
Run this command:
yarn hardhat get-address
This will show you the ethereum-style address associated with that private key and the filecoin-style f4 address (also known as t4 address on testnets)! The Ethereum address can now be exclusively used for almost all FEVM tools, including the faucet.
Go to the Hyperspace testnet faucet, and paste in the Ethereum address from the previous step. This will send some hyperspace testnet FIL to the account.
Currently there are 2 main types of contracts:
-
Basic Solidity Examples: Simple contracts to show off basic solidity
-
Filecoin API Examples: Contracts that demo how to use the Filecoin APIs in Solidity to access storage deals and other Filecoin specific functions.
-
Basic Deal Client: A contract that demos how to create Filecoin storage deals within Solidity smart contracts. See below to learn more.
Type in the following command in the terminal to deploy all contracts:
yarn hardhat deploy
This will compile all the contracts in the contracts folder and deploy them to the Hyperspace test network automatically!
Keep note of the deployed contract addresses for the next step.
You can interact with contracts via hardhat tasks, found in the 'tasks' folder. For example, to interact with the SimpleCoin contract:
Type in the following command in the terminal:
yarn hardhat get-balance --contract 'THE DEPLOYED CONTRACT ADDRESS HERE' --account 'YOUR ETHEREUM ADDRESS HERE'
The console should read that your account has 12000 SimpleCoin!
The primary advantage of the FEVM over other EVM based chains is the ability to access and program around Filecoin storage deals. This can be done in the FEVM via the Filecoin.sol library maintained by Zondax. Note this library is currently in BETA. It is unaudited, and the APIs will likely be changing with time. This repo will be updated as soon as possible when a breaking change occurs.
The library is included in this kit as an NPM package and will automatically be downloaded when you perform the yarn
command (don't confuse these with the included mocks)!
Currently you will find a getter contract that calls the getter methods on the MarketAPI to get storage deal data and store that data. To do this you will need dealIDs which you can find here on FilFox.
As an example to store most of the data available for a deal run the store-all command with a specified dealID. Below is an example of using this command below with a deal on Hyperspace testnet with a dealID of 707.
yarn hardhat store-all --contract "DEPLOYED FILECOIN_MARKET_CONSUMER CONTRACT ADDRESS HERE" --dealid "707"
Under contracts, within the basic-deal-client
sub-directory, you will find a file called DealClient.sol
. This is an example contract that uses the Filecoin.sol API's to create storage deals via Solidity smart contracts on Filecoin. This works by emitting a Solidity event that Boost storage providers can listen to. To learn more about this contract feel free to checkout the original Foundry project which includes a detailed readme.
Under contracts, within the filecoin-api-examples
sub-directory, you will find a file called deal-rewarder.sol
. This is a basic example contract that uses the Filecoin.sol API's to create bounties for specific data to be stored on the Filecoin blockchain. To learn more about this contract feel free to checkout the original Foundry project which includes a detailed readme.