How to deploy smart contracts on Scroll Alpha Testnet with Hardhat

Han Pham
2 min readMar 31, 2023

--

Photo of Scroll Logo
Photo of Scroll Logo

Scroll makes it easy to start building on their zkEVM Layer-2 network. You can start deploying your existing Solidity smart contracts to their Alpha Testnet.

This post provides guidance and steps in deploying your smart contracts on Scroll Alpha Testnet.

Create a .env file in your root folder and configure your .env file as follows:

// file: .env
SCROLL_TESTNET_URL = "https://alpha-rpc.scroll.io/l2"
PRIVATE_KEY = "YOUR-PRIVATE-KEY"

If you use Metamask, you can find your wallet key within your Metamask interface. To find your wallet private key, log into your MetaMask account, click the Details button on your Main Ethereum Network page, and then click the Export Private Key button.

More information about their Alpha Testnet and RPC URL info can be found here

Next, configure your hardhat.config.ts file:

(Make sure to install the import dependencies before you deploy)

// file: hardhat.config.ts
import * as dotenv from "dotenv";
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

dotenv.config();

const config: HardhatUserConfig = {
solidity: "0.8.18", // here I use solidity version 0.8.^, but you can change to your current solidity version
networks: {
scrollTestnet: {
url: process.env.SCROLL_TESTNET_URL || "",
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY]: [],
}
}
};

export default config;

Before deployment, you should load your test tokens on Alpha Testnet so you can execute the transactions. You can transfer your test tokens from Goerli Testnet to Scroll Alpha using Scroll Bridge

Make sure your smart contracts are compiled. Here are the command lines to deploy with npm:

npx hardhat compile
npx hardhat run --network scrollTestnet

If you use yarn, you can configure your package.json file as follows for a faster development process:

// file: package.json
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile": "npx hardhat compile",
"test": "npx hardhat test",
"deploy:scrollTestnet": "npx hardhat run --network scrollTestnet"
},
...
}

You can then deploy with yarn with these command lines:

yarn compile
yarn deploy:scrollTestnet

If your deployment has been successful, you will see something like this in your console:

deployd to 0xEeD1...
✨ Done in 7.86s.

Additionally, you can find your deployed smart contracts on their block explorer here:

I’m an undergrad student developer at the University of Washington, Bothell. You can find me at hanspham.com

Thanks for reading. Hope this guide was useful. Subscribe for more future updates!

--

--