Deploy your contracts to chain using hardhat
At 0xsaturn have a repository called Protocols that holds our Solidity contracts, and Typescript
typings for integrating in the SDK. We have customized the hardhat contract along with several scripts to
enable anyone to deploy contracts through the repository easily.
Let's get started on how we can do that!
Clone the repository.
To clone the repository, ensure that you have git installed.
git clone https://github.com/0xsaturn/saturn-protocolsOnce done, move into the directory.
cd saturn-protocolsFinally, install all the dependencies for the project.
npm install -D
# OR
yarnSetup the environmental variables.
The environmental variables need to be setup to deploy the contracts.
We need the following variables here:
- Wallet private key: To deploy contracts to the chain with the wallet owner as the contract owner.
- Alchemy API key: To interact with the Ethereum nodes or nodes of different chains.
A .env.example file is provided in the repository for configuring the variables. Rename it to .env
and fill in the credentials.
Build the contracts.
Now, the contracts need to be compiled and built. To do so, run the following command:
yarn run buildThis compiles the contracts, Generates the Typescript typings, waffle build files, ABI files generated.
Deploy the contract to the chain.
Once we have compiled the contracts, we are ready to deploy them to the chain.
Scripts for deploying contracts to the chain has been provided inside the scripts directory. We will be
deploying the ERC20 token contract here.
To deploy a contract to chain, you need the file to deploy and the network to deploy to. Currently we support,
- Ethereum
- Polygon
- Avalanche
- Fantom
- Harmony
- Aurora
- Or, literally any EVM chain. 🤯
And their testnets!
To deploy the ERC20 contract, Here's the command to deploy it (to polygon mainnet):
npx hardhat run scripts/deploy-token.ts --network polygonThis should give you the contract address once deployed! Keep a track of it, and use it to interact with the contract using our SDK too 😉.
Before deploying contracts, ensure that the contract deploy scripts have the
correct constructor arguments as you like. For example,
scripts/deploy-token.ts for the ERC20 contracts.