Build a smart contract wallet factory that deploys smart contract accounts with an EOA (Externally Owned Account) set as the signer for each smart contract account on Abstract.
This example consists of two components:
- contracts - Solidity smart contracts in a Hardhat environment that define the smart contract account and factory.
- frontend - A simple frontend using Next.js and Viem to interact with the contracts.
-
Get a copy of the
smart-contract-account-factoryexample directory from the Abstract Examples repository:mkdir -p smart-contract-account-factory && curl -L https://codeload.github.com/Abstract-Foundation/examples/tar.gz/main | tar -xz --strip=2 -C smart-contract-account-factory examples-main/smart-contract-account-factory && cd smart-contract-account-factory
-
Change directory to the
contractsfolder.cd contracts -
Install dependencies
npm install-
Compiling the contracts.
npx hardhat compile
-
Create a new Hardhat configuration variable for your wallet private key.
When prompted, enter the private key of the wallet you want to use to deploy the contract. It is strongly recommended to use a new wallet for this purpose.
npx hardhat vars set WALLET_PRIVATE_KEY -
Run the deploy script to deploy the smart contract account factory and create a smart account via the factory.
Note: The
defaultNetworkinside hardhat.config.ts is set toabstractTestnet. You will need testnet ETH from a faucet in your wallet to deploy the contract to Abstract.npx hardhat deploy-zksync --script deploy.ts
-
Change directory to the
frontendfolder.# if you are in the contracts folder cd ../frontend # Or, if you are in the root folder cd frontend
-
Install the dependencies.
npm install
-
Start the frontend.
npm run dev
-
Open http://localhost:3000 in your browser.
To deploy onto a local node (instead of the Abstract testnet), follow the instructions below.
-
Install the ZKsync CLI
npm install -g zksync-cli
-
For local development, ensure Docker is installed and running.
docker --version docker info
-
For local development, run an "In Memory node".
zksync-cli dev start
-
Set the hardhat default network to
inMemoryNodein hardhat.config.ts.defaultNetwork: "inMemoryNode",
-
Use the rich wallets to access accounts loaded with funds on the local node.