Set up a Project

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,

mkdir mvc-test-project
cd mvc-test-project
npm init -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.

npm install typescript ts-node @types/node fs-extra --save-dev

Initialize the TypeScript configuration file

npx tsc --init

Install Meta-Contract

npm install meta-contract --save

Start Writing the Program

Create an index.ts file to execute the logic.

Write the following code in the src/index.ts file:

Functionality of This Code:

  1. 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.

  2. Read the mnemonic from the file if it exists.

  3. 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.