A guide to the local test network development process

This guide describes the end-to-end development process for the local test network.

CLI FROM SOURCE, NOT FROM GITHUB
This guide is not correct if you use the aptos CLI from the release on GitHub or from cargo install, only if you build it yourself from aptos-core as described below.

Please read this manual carefully. This manual covers the local testnet development method. This method will not work if you create in devnet.

Start the local testnet from aptos-core.

Select and enter aptos-core:

git clone git@github.com:aptos-labs/aptos-core.git ~/aptos-core && cd ~/aptos-core
Enter fullscreen mode Exit fullscreen mode

Start test local network:

cargo run -p aptos -- node run-local-testnet --with-faucet --faucet-port 8081 --force-restart --assume-yes
Enter fullscreen mode Exit fullscreen mode

You can add the --release parameter after cargo run if you want to build the release version of the CLI to run the local testbed.

You now run the local testnet built from aptos-corebase.

Typescript: Using the SDK from aptos-core

Important: In this development method, it is important not to use the SDK from npmjs. Instead you should use the same SDK that the aptos CLI is built from, which we will describe below.

This tutorial assumes that you have completed the previous step on local testing. We also assume that you have yarn installed.

First go to aptos-core and build the SDK:

cd ~/aptos-core/ecosystem/typescript/sdk
yarn install
yarn build
Enter fullscreen mode Exit fullscreen mode

Create a new project if you don't have one already:

mkdir ~/project && cd ~/project
yarn init
Enter fullscreen mode Exit fullscreen mode

Make your project a target for the SDK from the local aptos-core:

yarn add ../aptos-core/ecosystem/typescript/sdk
Enter fullscreen mode Exit fullscreen mode

You can also use the full path, e.g. /home/daniel/aptos-core/ecosystem/typescript/sdk.

Set it all up:

yarn install
Enter fullscreen mode Exit fullscreen mode

You are all set! You should see in package.json that your project is targeting local aptos-core:

{
  "name": "project",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "aptos": "../a/core/ecosystem/typescript/sdk/"
  }
}
Enter fullscreen mode Exit fullscreen mode

This way your local test network and the SDK you're using match, which means you won't see any compatibility issues.

You can now use the aptos module in your code as follows:

import { AptosClient, AptosAccount, FaucetClient } from "aptos";

const NODE_URL = "https://127.0.0.1:8080/v1";
const FAUCET_URL = "https://127.0.0.1:8081";

(async () => {
  const client = new AptosClient(NODE_URL);
  const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL);
})();
Enter fullscreen mode Exit fullscreen mode

Note: Note that this code creates clients that communicate with your local testnet, not devnet.

Оцените статью
devanswers.ru
Добавить комментарий