Create a TypeScript project and introduce the meta-contract library.
Note: All tests below use Node.js version 18.20.1. The keys and addresses used in this tutorial are for testing purposes only and should not be used in a production environment. The author is not responsible for any losses due to key leakage.
Create a Node.js Project
First, initialize a Node.js project,
mkdirmvc-test-projectcdmvc-test-projectnpminit-y
Install TypeScript
This tutorial uses TypeScript to write the program, and it's recommended to use TypeScript to write contracts.
The following command installs the TypeScript dependencies.
Write the following code in the src/index.ts file:
Functionality of This Code:
Check if the mnemonic-seed.txt file exists in the project directory. If not, generate a new mnemonic and write it to the file. Note that this mnemonic is randomly generated and should not be used in a production environment. Also, keep this mnemonic safe as subsequent operations will use it.
Read the mnemonic from the file if it exists.
Generate a wallet using the mnemonic, and print the private key, address, and balance.
Run the Program
Execute the following commands to run the program:
If everything is correct, you will see an output similar to the following:
The wallet creation is complete. You can use this wallet address for subsequent operations.