This is a simple EIP-7702 smart wallet designed for use with EOA that will temporarily hold ERC-20 tokens in escrow until spent by an agent EOA that has been added to the subaccount's approved signer list.
The approved signer can, for example, sign an EIP-3009 authorization to spend USDC being held in the upgraded subwallet address to spend on x402 resources. This approach removes the need to dump a complete budget up-front into an EOA controlled by an autonomous agent while still being compatible with paying for x402 resources.
This project showcases a Hardhat 3 Beta project using the native Node.js test runner (node:test) and the viem library for Ethereum interactions.
To learn more about the Hardhat 3 Beta, please visit the Getting Started guide. To share your feedback, join our Hardhat 3 Beta Telegram group or open an issue in our GitHub issue tracker.
This example project includes:
- A simple Hardhat configuration file.
- Foundry-compatible Solidity unit tests.
- TypeScript integration tests using
node:test, the new Node.js native test runner, andviem. - Examples demonstrating how to connect to different types of networks, including locally simulating OP mainnet.
To run all the tests in the project, execute the following command:
npx hardhat testYou can also selectively run the Solidity or node:test tests:
npx hardhat test solidity
npx hardhat test nodejsThis project includes Ignition modules to deploy contracts. You can deploy to a locally simulated chain, Sepolia, or Base.
To run the deployment to a local chain:
npx hardhat ignition deploy ignition/modules/SubWallet.ts| Variable | Used for | Where to get it |
|---|---|---|
BASE_RPC_URL |
Base deployment & scripts | Alchemy, Infura, QuickNode, or https://mainnet.base.org |
BASE_PRIVATE_KEY |
Deployer/signer for Base | Your EOA private key (without 0x) |
ETHERSCAN_API_KEY |
Contract verification on Basescan/Etherscan | Etherscan API |
SEPOLIA_RPC_URL |
Sepolia deployment | Same providers, Sepolia endpoint |
SEPOLIA_PRIVATE_KEY |
Deployer for Sepolia | Your EOA private key |
To deploy to Base mainnet, configure your private key and RPC provider:
-
Create a
.envfile in the project root (add.envto.gitignore):BASE_RPC_URL=https://mainnet.base.org BASE_PRIVATE_KEY=your_private_key_here ETHERSCAN_API_KEY=your_etherscan_api_keyOr use an RPC provider like Alchemy, Infura, or QuickNode for
BASE_RPC_URL. -
Set the config variables using
hardhat-keystore:npx hardhat keystore set BASE_RPC_URL npx hardhat keystore set BASE_PRIVATE_KEY npx hardhat keystore set ETHERSCAN_API_KEY
Or set them as environment variables before running Hardhat.
-
Deploy to Base:
npx hardhat ignition deploy ignition/modules/SubWallet.ts --network base
To deploy to Sepolia, set SEPOLIA_RPC_URL and SEPOLIA_PRIVATE_KEY:
npx hardhat keystore set SEPOLIA_PRIVATE_KEY
npx hardhat ignition deploy ignition/modules/SubWallet.ts --network sepolia-
Get an API key from Etherscan (works for Etherscan, Basescan, Sepolia, and other Etherscan-family explorers).
-
Set the config variable:
npx hardhat keystore set ETHERSCAN_API_KEY -
Verify a deployed contract (SubWallet has no constructor args):
npx hardhat verify --network base DEPLOYED_ADDRESS
For Sepolia:
npx hardhat verify --network sepolia DEPLOYED_ADDRESS
-
If you deployed with the production build profile (optimizer enabled), add
--build-profile production:npx hardhat verify --network base --build-profile production DEPLOYED_ADDRESS
To print the ETH balance of the configured deployer account:
npx hardhat run scripts/balance.ts --network base