hardhat-boilerplate v1.0.1
Installation
At first install all project dependencies
npm i
Then you need to set ENVIRONMENT_TO_DEPLOY and NETWORK variables in .env.local. For example;
ENVIRONMENT_TO_DEPLOY:<environment>
can be:
- giveaway
- presale
- opensale
- test
- production
How to restart a moralis environment
To do this, we need to follow the next steps:
- set an environment in .env.local
- run :
npm run restart
- Log in into Moralis account and delete the syncs (listener)
- Delete classes associated to the deleted syncs
- Update Cloud functions with
scripts/moralis/index.js
file
Running scripts
If you want set to deploy contracts, run:
npm run deploy
Then, you need to set listeners on moralis server:
npm run watch-events
Then, you need to request random number seed to chainlink VRF, for that you need to register LilVillainsMinter address like a consumer (https://vrf.chain.link/) and then run using the owner account:
npm run request-random
Now we can set a giveaway stage:
npm run set-giveaway
then:
Now we can set a presale stage:
npm run set-presale
Now we can set a opensale stage:
npm run set-opensale
Cloud functions (Moralis)
There are many cloud functions that are hosted in Moralis server. The code is available in /scripts/moralis/cloudFunctions folder
Develop and deploy
To develop cloud functions first we need to configure the following environment variables in .env.local
file:
- MORALIS_CLI_API_KEY
- MORALIS_CLI_API_SECRET
You can get these values from Moralis -> Account Settings -> Keys (Both values applies to all servers)
After that you should start listening the cloud functions directory to automatically deploy the changes, to do that you should run
npm run deploy:moralis
and choose the server you want to deploy/watch.
Test
One of many ways to test Cloud function is doing a simple get request to it, for example:
//https://<SERVER_URL>/functions/<CLOUD_FUNCTION_NAME>?_ApplicationId=<APP_ID>&<PARAM_NAME1>=<PARAM_VALUE1>&<PARAM_NAME2>=<PARAM_VALUE2>
//https://p6hzp6z7.usemoralis.com:2058/server/functions/getNFTs?_ApplicationId=8fv7oJnfTjwa26gi0EqJ1EHbtJt&address=0x202f4d5cce054f715444b292d0ce76acb38c2767&amount=10
Develop
If you want run all in a local node, you can start up it with the next command:
npm run local-node
Then you can deploy your contracts in that node with the next command:
npm run deploy localhost
Some cases you need to know contract size because you can't exceed 24KB. For to known all contract sizes, run the next code:
npm run contract:size
To run test:
npm run test
To get coverage, run:
npm run test:coverage
Optional
if you want a great experience in solidity language install the next vs code extension
Troubleshooting
If you are running tests and get a timeout error, may be you need to set the next object in hardhat.config.js file:
mocha: {
timeout: 100000, //40000ms is the default value
}