Foundry
Foundry is a fast toolkit for application development written in Rust equipped with a testing framework, as well as utilities for interacting with smart contracts and getting chain data. We’re going to use the FEVM Foundry Kit repository to get started.
On this page
The template repository contains submodules and remappings for ds-test assertions for testing, solmate building blocks for contracts, and forge-std to layer on top of evm cheatcodes to improve UX.
Prerequisites
You must have the following installed:
You should also have an address on the Filecoin Hyperspace testnet. See the Add to MetaMask page for information on how to get an address. You also need test-FIL tFIL
in your wallet. See the Use a Faucet page for information on how to get test funds.
Steps
Clone the
xBalbinus/fevm-foundry-kit
repository and move into thefevm-foundry-kit
directory:git clone https://github.com/xBalbinus/fevm-foundry-kit/tree/main.git cd fevm-foundry-kit
Install the project dependencies with Yarn:
yarn install
Export your private key from MetaMask. See the MetaMask documentation to find out how to export your private key.
In your .env.example, create an environment variable called
PRIVATE_KEY
and paste in the private key from MetaMask. Also, do the same for theHYPERSPACE_RPC_URL
. Then rename the file to .env:PRIVATE_KEY=eed8e9d727a647f7302bab440d405ea87d36726e7d9f233ab3ff88036cfbce9c HYPERSPACE_RPC_URL=https://api.hyperspace.node.glif.io/rpc/v1
Inside the
src
folder in a contract calledSimpleCoin.sol
. Deploy this contract using Foundry:forge build forge script script/SimpleCoin.s.sol:MyScript --rpc-url https://api.hyperspace.node.glif.io/rpc/v1 --broadcast --verify -vvvv
... Script ran successfully. Gas used: 234642
Alternatively, you can do the same using the
forge create
command:forge build forge create --rpc-url https://api.hyperspace.node.glif.io/rpc/v1 --private-key $PRIVATE_KEY src/SimpleCoin.sol:SimpleCoin
The deployment process should be almost instantaneous. Once the contract has been successfully deployed, Foundry will give you a contract address you can use to interact with the contract.
You can now interact with your contract using the contract address given by Foundry.
Done! For more information, see the Foundry book.