Skip to content

Commit f36c6fa

Browse files
committed
translate quick start section
1 parent 8e0281f commit f36c6fa

File tree

9 files changed

+711
-2
lines changed

9 files changed

+711
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,51 @@
11
---
22
sidebar_position: 2
33
---
4+
45
# Claim Faucet
6+
7+
This guide explains how to request test tokens from a faucet.
8+
9+
## Prerequisites
10+
11+
First, ensure you have completed the environment setup and successfully printed your address. Refer
12+
to [Environment Setup](setup-project.md).
13+
14+
```text
15+
Mnemonic seed exists: <* * * * * * * * * * * *>, will use this one.
16+
Creating wallet with seed: <* * * * * * * * * * * *> and path <m/44'/10001'/0'/0/0>
17+
Your private key *
18+
Your address mi51xGS45itNchtDRdRP3Fbh3vjEQWxh38
19+
Your balance 0 satoshis
20+
```
21+
22+
Record your address to request test tokens.
23+
24+
## Request Test Tokens
25+
26+
Currently, the witnessonchain service provides a space testnet faucet.
27+
28+
You can visit: [Space Testnet Faucet](https://witnessonchain.com/faucet/tspace) to request test tokens.
29+
30+
Enter your address, click the `Shoot me the coin` button, and wait a few seconds. Your address will receive a certain
31+
amount of test tokens, as shown below:
32+
33+
![space-faucet](/img/witnessonchain-faucet.png)
34+
35+
You can check your address balance in a browser or run the environment setup code again to check the balance.
36+
37+
```bash
38+
node src/index.js
39+
```
40+
41+
At this point, you should see that your balance is no longer zero.
42+
43+
```text
44+
Your balance 10000000 satoshis
45+
```
46+
47+
## Request Mainnet Test Tokens
48+
49+
If you need to request mainnet test tokens, visit: [Space Mainnet Faucet](https://witnessonchain.com/faucet/space). Note
50+
that the format of mainnet addresses is different from testnet addresses; mainnet addresses start with `1`, while
51+
testnet addresses start with `m` or `n`.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,127 @@
11
---
22
sidebar_position: 1
33
---
4+
45
# Set up a Project
56

7+
Create a TypeScript project and introduce the `meta-contract` library.
8+
9+
> Note: All tests below use Node.js version 18.20.1. The keys and addresses used in this tutorial are for testing
10+
> purposes only and should not be used in a production environment. The author is not responsible for any losses due to
11+
> key leakage.
12+
13+
## Create a Node.js Project
14+
15+
First, initialize a Node.js project,
16+
17+
```bash
18+
mkdir mvc-test-project
19+
cd mvc-test-project
20+
npm init -y
21+
```
22+
23+
## Install TypeScript
24+
25+
This tutorial uses TypeScript to write the program, and it's recommended to use TypeScript to write contracts.
26+
27+
The following command installs the TypeScript dependencies.
28+
29+
```bash
30+
npm install typescript ts-node @types/node fs-extra --save-dev
31+
```
32+
33+
Initialize the TypeScript configuration file
34+
35+
```bash
36+
npx tsc --init
37+
```
38+
39+
## Install Meta-Contract
40+
41+
```bash
42+
npm install meta-contract --save
43+
```
44+
45+
## Start Writing the Program
46+
47+
Create an `index.ts` file to execute the logic.
48+
49+
```bash
50+
mkdir src
51+
touch src/index.ts
52+
```
53+
54+
Write the following code in the `src/index.ts` file:
55+
56+
```typescript
57+
import {Mnemonic} from "meta-contract/dist/mvc";
58+
import {promises as fs} from 'fs';
59+
import {API_NET, Wallet} from "meta-contract";
60+
61+
const FILE_PATH = 'mnemonic-seed.txt'
62+
const WALLET_PATH = "m/44'/10001'/0'/0/0"
63+
let seed = '';
64+
const generateMnemonic = async (): Promise<string> => {
65+
console.log("Generating random mnemonic seed: <%s>, use your own if you already have it", Mnemonic.fromRandom().toString())
66+
const mnemonic = Mnemonic.fromRandom().toString();
67+
await fs.writeFile(FILE_PATH, mnemonic, 'utf8');
68+
return mnemonic;
69+
};
70+
71+
const readMnemonic = async (): Promise<string> => {
72+
return await fs.readFile(FILE_PATH, 'utf8');
73+
};
74+
75+
// Detect if the mnemonic seed file exists, if not, generate a new one
76+
// Then create a wallet with the seed with path WALLET_PATH
77+
const setupMyWallet = async (): Promise<void> => {
78+
try {
79+
await fs.access(FILE_PATH);
80+
const mnemonic = await readMnemonic();
81+
console.log('Mnemonic seed exists: <%s>, will use this one.', mnemonic);
82+
seed = mnemonic;
83+
} catch (error) {
84+
const mnemonic = await generateMnemonic();
85+
console.log('Mnemonic seed not detected, generating new one. <%s> , please keep it safe for future use.', mnemonic);
86+
seed = mnemonic;
87+
}
88+
console.log('Creating wallet with seed: <%s> and path <%s>', seed, WALLET_PATH);
89+
let mnemonicParsed = Mnemonic.fromString(seed);
90+
let privateKey = mnemonicParsed.toHDPrivateKey("", API_NET.TEST).deriveChild(WALLET_PATH);
91+
let wallet = new Wallet(privateKey.privateKey.toWIF(), API_NET.TEST, 1);
92+
console.log("Your private key %s", privateKey.privateKey.toWIF());
93+
console.log("Your address %s", privateKey.privateKey.toAddress(API_NET.TEST).toString());
94+
console.log("Your balance %s satoshis", await wallet.getBalance());
95+
};
96+
97+
setupMyWallet().catch(console.error);
98+
```
99+
100+
### Functionality of This Code:
101+
102+
1. Check if the `mnemonic-seed.txt` file exists in the project directory. If not, generate a new mnemonic and write it
103+
to the file. Note that this mnemonic is randomly generated and should not be used in a production environment. Also,
104+
keep this mnemonic safe as subsequent operations will use it.
105+
2. Read the mnemonic from the file if it exists.
106+
3. Generate a wallet using the mnemonic, and print the private key, address, and balance.
107+
108+
## Run the Program
109+
110+
Execute the following commands to run the program:
111+
112+
```bash
113+
npx tsc
114+
node src/index.js
115+
```
116+
117+
If everything is correct, you will see an output similar to the following:
118+
119+
```text
120+
Mnemonic seed exists: <* * * * * * * * * * * *>, will use this one.
121+
Creating wallet with seed: <* * * * * * * * * * * *> and path <m/44'/10001'/0'/0/0>
122+
Your private key *
123+
Your address mi51xGS45itNchtDRdRP3Fbh3vjEQWxh38
124+
Your balance 0 satoshis
125+
```
126+
127+
The wallet creation is complete. You can use this wallet address for subsequent operations.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
11
# MVCScan
2+
3+
Introduction to using the MVCScan browser to view transactions.
4+
5+
## Introduction to MVCScan
6+
7+
[MVCScan](https://www.mvcscan.com/) is a blockchain browser for MVC, allowing users to view information on blocks, transactions, and addresses. It provides rich data display and query functions, making it convenient for users to view blockchain data. It supports both the mainnet and the testnet, and allows for balance inquiries of spaces and tokens.
8+
9+
![MVCScan Home](/img/mvcscan-home.png)
10+
11+
## Network Selection
12+
13+
MVCScan supports both the mainnet and the testnet. Users can choose different networks to view different data.
14+
15+
[MVCScan Mainnet](https://www.mvcscan.com/): View mainnet data.
16+
17+
[MVCScan Testnet](https://test.mvcscan.com/): View testnet data.
18+
19+
## Transaction Query
20+
21+
Enter the transaction ID in the input box and click the search button to view transaction details.
22+
23+
![Transaction Query](/img/mvcscan-transaction.png)
24+
25+
## Address Query
26+
27+
Enter the address in the input box and click the search button to view address details. Address details include space balance, transaction history, and token balances held.
28+
29+
![Address Query](/img/mvcscan-address.png)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,65 @@
11
# MVCApi
2+
3+
Introduction to MVCAPI Standardized Interface Definition and How to Use MVCApi to View Transactions
4+
5+
## MVCApi Protocol
6+
7+
MVCApi is a set of OpenAPI service protocols that define a standardized interface for accessing transaction data using
8+
Restful APIs. The goal of the MVCApi protocol is to provide an easy way to access transaction data, making it simpler
9+
for developers to utilize this data.
10+
11+
Compared to traditional node RPC interfaces, MVCApi defines more comprehensive interfaces and functionalities, adding
12+
many convenient interaction logics for clients and web pages, making integration and debugging easier.
13+
14+
The interface definition of the MVCApi protocol is based on the OpenAPI specification. Developers can use any tools that
15+
support the OpenAPI specification to generate client code, greatly simplifying the integration process.
16+
17+
Additionally, due to the openness of the MVCApi protocol, any service implementing the MVCApi protocol can be accessed
18+
by clients. This means developers can use the MVCApi protocol to access different services without worrying about the
19+
specific implementation of the service and without being tied to a particular service provider, allowing for flexible
20+
switching between providers.
21+
22+
To view the MVCApi definition,
23+
visit [openapi.yaml](https://github.com/mvc-labs/mvcapi-definition/blob/master/openapi.yaml).
24+
25+
## MVCApi Service
26+
27+
[MVCApi Service](https://mvcapi.com/) is a Restful API service implementation based on the MVCApi protocol, maintained
28+
by members of MVCLabs. Developers can write code to interact with the MVCApi service or use the Swagger UI provided by
29+
MVCApi to view interface definitions and test the interfaces.
30+
31+
Swagger UI can simulate client requests and return interface data, mainly for developers to debug and test the
32+
interfaces.
33+
34+
MVCApi debugging interface address: [https://mvcapi.com/](https://mvcapi.com/)
35+
36+
![MVCApi Home](/img/mvcapi-home.png)
37+
38+
## Network Selection
39+
40+
MVCApi supports both the mainnet and the testnet. Users can choose different networks to view different data.
41+
42+
In Swagger UI, by selecting different Servers, you can switch to different network API entries, such as mainnet and
43+
testnet.
44+
45+
![Network Selection](/img/mvcapi-network.png)
46+
47+
## Transaction Query
48+
49+
MVCApi provides two types of transaction query interfaces: querying transaction details by transaction ID and querying
50+
raw transactions by transaction ID. If raw transaction data is needed, the raw transaction query interface can be used.
51+
52+
Here, we take querying transaction details /tx/\{txid} as an example. Enter the transaction ID, click the `Try it out`
53+
button, and you can view the transaction details in JSON format.
54+
55+
![Transaction Query](/img/mvcapi-transaction.png)
56+
57+
## Address Query
58+
59+
Since MVCApi is developer-oriented, the address query interface functionalities are specialized. Querying space balance,
60+
querying SpaceUtxo, querying transaction history, querying FT, and querying NFT balances and transaction history
61+
correspond to different interfaces.
62+
63+
For specific functionalities, please refer to the MVCApi interface definition.
64+
65+
![Address Query](/img/mvcapi-address.png)

0 commit comments

Comments
 (0)