How To Deploy An Existing Smart Contract To Scroll.io Testnet

How To Deploy An Existing Smart Contract To Scroll.io Testnet

Table of contents

Scroll is an EVM-Equvalent zkEVM zkRollup. One of the many things this means is that developers can migrate currently existing dapps onto scroll with minimal tweaks to how their code is written. This is great news as there aren’t a lot of compatibility issues when deploying to scroll.

So I had to give this a try myself. I deployed an NFT minting dapp I had deployed much earlier to the Ethereum Rinkeby testnet (RIP), to scroll’s testnet, and it worked rather seamlessly. All that was needed were a couple of modifications to the hardhat.config.ts file, the installation of a few packages, and we were ready to go. In this article, we’ll be covering all of those.

Prerequisites:

  • Installing a few npm packages

  • new hardhat.config.ts code

  • retweaking deploy.ts script

  • tweaking tsconfig.json

  • Editing .env file.

packages to install:

npm i @nomicfoundation/hardhat-toolbox

npm i dotenv

npm i @nomiclabs/hardhat-ethers

Once you’re done installing all of these packages, the next step will be to configure some files. Let’s start by opening hardhat.config.ts and replace everything with this:

require('@nomiclabs/hardhat-waffle')
import * as dotenv from "dotenv";

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

dotenv.config();

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.9",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
  networks: {
    scrollTestnet: {
      url: process.env.SCROLL_TESTNET_URL || "",
      accounts:
        process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
    },
  },
};

export default config;

Save the file and then open up your deploy.ts script.

If you currently have this at the top of your deploy.ts file: const hre = require("hardhat");, comment it out, and replace it with this: import { ethers } from "hardhat"; .

Then proceed to search for ‘hre’ and get rid of it anywhere in your deploy.ts file. Save.

Opentsconfig.json, and add these:

{
"compilerOptions": {
...
    "target": "ES2017",
    "module": "commonjs",
},

"include": ["./test", "./src", "./scripts"],
 "files": ["./hardhat.config.ts"]
}

Save your tsconfig.json file.

The last thing we need to do will be to create or modify our .env file to look like this:

PRIVATE_KEY=WALLET_PRIVATE_KEY_GOES_HERE
SCROLL_TESTNET_URL=https://prealpha.scroll.io/l2

Open up your terminal and run yarn compile this will compile your contract.

Then run npx hardhat run --network scrollTestnet scripts/deploy.ts to deploy to Scroll’s testnet.

Copy your deployed contract address, head over to https://prealpha.scroll.io/l2scan, and paste the address into the search bar to the top right, and you should see it live!

Conclusion

It is important to note that these were the changes I had to make to get things working for me. You may not need to make this many modifications. Or you may need to make a whole lot more depending on what architecture you currently have going on. But whatever the case may be, feel free to shoot me a dm on Twitter, or join the Scroll discord and reach out to folks on there. The community is always ready to help!