Deploy smart contracts with hardhat deploy and hardhat
tasks
or scripts
. However, due to the Hardhat architecture that enables its extension by creating plugins, you can rely on existing solutions developed by the community.
Hardhat deploy is a community-developed plugin that enables the deployment of your smart contracts in a simple way.
npm install -D hardhat-deploy
. Then, import hardhat-deploy in hardhat.config.ts
:001_deploy_lock.ts
.
tsconfig.json
file to look like:hardhat.config.ts
file. Hardhat deployment includes a way to name accounts in the config file.
001_deploy_lock.ts
file:Lock.ts
and include in the imports the following:
deployments
will allow you to execute the deployment files from your test.
Change the before
function to look like the following:
deployments.fixture
and pass a tag that matches the one you specified in the deployment file (001_deploy_lock.ts
).
The deployment file is then executed and you can then reuse that functionality and simply consume the address of the newly-deployed contract by using:
Lock__factory
but use the connect function and pass the address of the newly-created contract plus a signer. Then, run npx hardhat test
and you should get the same result:
hardhat.config.ts
file:
.env
file with the following variables:
dotenv
:
hardhat.config.ts
file:
base_sepolia
:
ALCHEMY_SEPOLIA_KEY
.