This is a simple mini wallet contract. With this contract, you can implement functions such as deposit, withdrawal, remittance, and obtaining USD value.
- First, you need to install npm, please refer to the npm official documentation for installation.
- Clone the repository to your local, navigate to the project directory, and run
npm install
to install the dependencies.
- Run the
npx hardhat compile
command to compile the contracts. - Run
npx hardhat test
to execute all unit test cases and check the results.
- First, you need to prepare a wallet address for deploying the contracts, then replace the value of
PRIVATE_KEY_MANAGER
in the hardhat.config.js file. - Navigate to the deploy.js file, where methods for deploying each contract in the project are prepared. We need to deploy each contract individually in sequence (by commenting out other deployment methods and leaving only the method to be deployed, because the deployment has to wait for some time before the transaction is confirmed and the next transaction can be executed).
- Comment out other methods, leaving only
await deployMiniWalletImplementation();
. Then run thenpx hardhat run scripts/deploy.js --network sepolia
command to deploy the MiniWalletImplementation contract. When you see the deployed contract address in the logs, take note of the MiniWalletImplementation contract address and assign it tominiWalletImplementationAddress
. - Similarly, comment out other methods and leave
await deployMiniWallet(miniWalletImplementationAddress);
. Then run thenpx hardhat run scripts/deploy.js --network sepolia
command to deploy the MiniWallet contract, and take note of the contract address. - Deploy the MockUSDT contract using a similar method, and take note of the contract address.
- Note that don't deploy and update the miniWalletImplementationV2 contract at this stage.
- To test the deployed contracts by sending transactions, you need to prepare two additional wallet addresses. Replace the values of
PRIVATE_KEY_USER
andPRIVATE_KEY_USER2
in the hardhat.config.js file with these addresses. - Replace the address values of
miniWalletAddress
andusdtAddress
in the transactions.js file with miniWalletAddress and usdtAddress deployed. - Similar to the deployment script, comment out other methods and keep the methods you want to test. Then, execute the test methods one by one in the transactions.js script. Note that you need to wait for a period of time after calling a contract method for the transaction to confirm before executing the next transaction.
- Using an example to explain: Comment out other methods and keep
await mintERC20Tokens(user, mintAmount);
, then run the commandnpx hardhat run scripts/transactions.js --network sepolia
. After obtaining the transactionId, navigate to the Sepolia Explorer (URL: https://sepolia.etherscan.io), paste the transactionId and search. Wait for the transaction status to change to Success on the page. Then, executeawait approveERC20TokenAllowance(user, mintAmount);
andawait depositERC20Tokens(user, usdt.address, depositAmount);
using the similar method. Afterwards, executeawait getAccountBalance(user, usdt.address);
, and you should see the balance as 100. - If you want to test the
getAllTokenBalances
method, first go to the deploy.js file and sequentially callawait deployMiniWalletImplementationV2();
andawait updateMiniWalletImplementation(miniWalletAddress, miniWalletImplementationV2Address);
methods to update the contract implementation. Then, in the transactions.js file, use miniWalletImplementationV2 to executeawait getAllTokenBalances(user2);
method.
MiniWalletImplementation and MiniWallet contracts have been deployed (MiniWalletImplementationV2 is not deployed yet). Anyone can use the following addresses for testing.
MiniWallet contract address: 0xf14d9896ED99896ffc1d342592DC48a25c308d50
MiniWallet contract link: https://sepolia.etherscan.io/address/0xf14d9896ED99896ffc1d342592DC48a25c308d50