본문으로 건너뛰기

로컬 네트워크 연결

Sui CLI는 Sui 네트워크의 로컬 인스턴스를 만들고 시작하는 sui start 명령을 제공한다. 인덱서, faucet, GraphQL 서비스의 로컬 인스턴스(웹 기반 GraphiQL IDE 포함) 같은 서비스를 시작할 수 있다. sui start에는 생성한 로컬 네트워크에서 사용할 테스트 SUI를 받기 위한 local faucet도 포함된다.

로컬 네트워크 시작

로컬 네트워크를 시작하려면 다음 명령을 실행한다:

$ RUST_LOG="off,sui_node=info" sui start --with-faucet --force-regenesis

이 명령은 다음을 수행한다:

  • 두 개의 플래그와 함께 Sui CLI 바이너리를 호출한다:

    • --with-faucet: faucet 서비스를 시작한다.

    • --force-regenesis: 새 genesis를 생성하고 로컬 네트워크 상태를 유지하지 않는다.

  • RUST_LOG=off,sui_node=info 플래그로 Rust에 특정 로깅을 설정하도록 지시한다. 이 설정은 sui-node를 제외한 모든 구성 요소의 로깅을 끈다. 더 자세한 로그를 보고 싶다면 명령에서 RUST_LOG를 제거할 수 있다.

주의

--force-regenesis를 전달해 네트워크를 시작할 때마다 로컬 네트워크는 이전 데이터가 없는 무작위 genesis에서 시작하며 로컬 네트워크 상태를 유지하지 않는다. 데이터를 유지하려면 --force-regenesis 플래그를 전달하지 않는다.

Sui는 /tmp에 임시 디렉터리를 생성하며, /tmp 폴더가 /tmpfs에 마운트되어 있으면 동작하지 않을 수 있다. 이 경우 TMPDIR=./some_folder를 설정한다.

사용자 지정

다른 서비스를 시작하거나 기본 포트와 호스트를 변경하는 것과 같이 로컬 Sui 네트워크를 커스터마이즈하려면 sui start 명령에 추가 플래그 또는 옵션을 포함한다.

with-indexer, with-graphql 같은 옵션과 플래그를 사용하려면 PostgreSQL/libpq가 설치되어 있어야 한다. 아래의 가능한 옵션 목록에서 기본 데이터베이스가 무엇인지, 다른 데이터베이스를 전달하는 방법을 확인한다.

다음은 sui start에 전달할 수 있는 가능한 옵션과 플래그 목록이다. 콘솔에서 sui start --help를 실행해 이 옵션을 볼 수 있다.

--network.config <CONFIG_DIR>
Config directory that will be used to store network config, node db,
keystore. sui genesis -f --with-faucet generates a genesis config that
can be used to start this process. Use with caution as the `-f` flag
will overwrite the existing config directory. We can use any config
dir that is generated by the `sui genesis`

--force-regenesis
A new genesis is created each time this flag is set, and state is not
persisted between runs. Only use this flag when you want to start the
network from scratch every time you run this command.

To run with persisted state, do not pass this flag and use the `sui
genesis` command to generate a genesis that can be used to start the
network with.

--with-faucet[=<FAUCET_HOST_PORT>]
Start a faucet with default host and port: 0.0.0.0:9123. This flag
accepts also a port, a host, or both (e.g., 0.0.0.0:9123). When
providing a specific value, please use the = sign between the flag and
value: `--with-faucet=6124` or `--with-faucet=0.0.0.0`, or
`--with-faucet=0.0.0.0:9123`

--with-indexer[=<DATABASE_URL>]
Start an indexer with a PostgreSQL database.

Three modes of operation: - Not specified: No indexer is started
(unless --with-graphql is set) - `--with-indexer`: Create/use a
temporary database in the network's configuration directory -
`--with-indexer=<URL>`: Use the provided PostgreSQL database URL

When providing a database URL, use the = sign:
`--with-indexer=postgres://user:pass@host:5432/db`

--with-consistent-store[=<CONSISTENT_STORE_HOST_PORT>]
Start a Consistent Store with default host and port: 0.0.0.0:9124.
This flag accepts also a port, a host, or both (e.g., 0.0.0.0:9124).

When providing a specific value, please use the = sign between the
flag and value: `--with-consistent-store=9124` or
`--with-consistent-store=0.0.0.0`, or
`--with-consistent-store=0.0.0.0:9124` The Consistent Store will be
automatically enabled when `--with-graphql` is set.

--with-graphql[=<GRAPHQL_HOST_PORT>]
Start a GraphQL server with default host and port: 0.0.0.0:9125. This
flag accepts also a port, a host, or both (e.g., 0.0.0.0:9125).

When providing a specific value, please use the = sign between the
flag and value: `--with-graphql=9125` or `--with-graphql=0.0.0.0`, or
`--with-graphql=0.0.0.0:9125`

Note that GraphQL requires a running indexer and consistent store,
which will be enabled by default even if those flags are not set.

--fullnode-rpc-port <FULLNODE_RPC_PORT>
Port to start the Fullnode RPC server on. Default port is 9000

[default: 9000]

--epoch-duration-ms <EPOCH_DURATION_MS>
Set the epoch duration. Can only be used when `--force-regenesis` flag
is passed or if there's no genesis config and one will be
auto-generated. When this flag is not set but `--force-regenesis` is
set, the epoch duration will be set to 60 seconds

--data-ingestion-dir <DATA_INGESTION_DIR>
Make the fullnode dump executed checkpoints as files to this
directory. This is incompatible with --no-full-node.

If --with-indexer is set, this defaults to a temporary directory.

--no-full-node
Start the network without a fullnode

--committee-size <COMMITTEE_SIZE>
Set the number of validators in the network. If a genesis was already
generated with a specific number of validators, this will not override
it; the user should recreate the genesis with the desired number of
validators

로컬 네트워크 상태 유지

--force-regenesis 플래그를 전달하지 않고 네트워크를 중지했다가 다시 시작하면 모든 히스토리가 보존되며 계속 접근할 수 있다.

기본적으로 sui start를 사용할 때 ~/.sui/sui_config 폴더가 존재하고 genesis.blob 파일을 포함하면 이 명령은 기존 genesis와 네트워크 구성을 사용한다. 폴더가 존재하지 않으면 폴더를 만들고 새 genesis 구성을 생성한다. --network.config를 전달하면 이 명령은 네트워크 구성 파일을 확인하고 네트워크 구성 파일에 따라 genesis blob을 로드하려고 시도한다.

커스텀 genesis를 생성하려면 sui genesis 명령을 사용하고 원하는 커스텀 값을 전달한다. 가능한 플래그와 옵션에 관한 자세한 정보는 sui genesis --help를 실행하여 확인한다.

로컬 네트워크의 트랜잭션 히스토리를 보려면 다음 명령으로 로컬 총 트랜잭션 수를 조회한다:

$ curl --location --request POST 'http://127.0.0.1:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"id": 1,
"method": "sui_getTotalTransactionBlocks",
"params": []
}'

성공하면 응답은 다음과 유사하다:

{
"jsonrpc": "2.0",
"result": 168,
"id": 1
}

Sui CLI를 로컬 네트워크에 연결

Sui CLI는 모든 Sui 네트워크에서 사용할 수 있다. 로컬 네트워크에 연결하려면 CLI의 RPC URL 구성을 로컬 네트워크 URL로 설정하는 local이라는 새 환경 별칭을 생성한다.

$ sui client new-env --alias local --rpc http://127.0.0.1:9000

다음으로, 생성한 새 local 환경을 활성 환경으로 설정한다.

sui client switch --env local

명령은 Active environment switched to [local]을 반환한다.

다음 명령으로 현재 활성 환경을 확인할 수 있다:

$ sui client active-env

명령은 local을 반환한다.

현재 활성 주소 표시

Sui CLI는 명령에서 플래그로 주소를 명시적으로 지정하지 않으면 각 명령에 활성 주소를 사용한다. 로컬 네트워크에서 현재 활성 주소를 보려면 다음 명령을 사용한다:

sui client active-address

명령은 예를 들어 다음과 같은 주소를 반환한다:

0xbc33e6e4818f9f2ef77d020b35c24be738213e64d9e58839ee7b4222029610de

local faucet 사용

로컬 네트워크의 트랜잭션도 Mainnet, Testnet, Devnet과 마찬가지로 가스 수수료를 지불하기 위해 SUI 코인이 필요하다. Sui CLI는 local faucet에서 SUI를 받기 위한 sui client faucet 명령을 제공한다. faucet 명령은 기본적으로 활성 주소와 활성 네트워크 환경을 사용한다.

sui client faucet을 실행하고 코인이 주소에 도달할 때까지 약 60초 기다린다.

faucet에서 코인을 받은 후 다음 명령으로 해당 주소의 coin 객체를 확인한다:

$ sui client gas

응답은 다음과 유사하다:

╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0x1d790713c1c3441a307782597c088f11230c47e609af2cec97f393123ea4de45 │ 200000000 │
│ 0x20c1d5ad2e8693953fca09fd2fec0fbc52a787e0a0f77725220d36a09a5b312d │ 200000000 │
│ 0x236714566110f5624516faa0da215ad29f8daa611e8b651d1e972168207567b2 │ 200000000 │
│ 0xc81f30256bb04ad84bc4a92017cffd7c1f98286e028fa504d8515ad72ddd1088 │ 200000000 │
│ 0xf61c8b21b305cc8e062b3a37de8c3a37583e17f437a449a2ab42321d019aeeb4 │ 200000000 │
╰────────────────────────────────────────────────────────────────────┴────────────╯

예시 데이터 생성

네트워크에 예시 데이터를 추가하려면 TypeScript SDK를 사용한다. 이를 위해 인덱서와 GraphQL을 포함하여 로컬 네트워크를 시작해야 한다. 다음 명령을 사용한다:

sui start --force-regenesis --with-faucet --with-indexer --with-graphql

그런 다음 sui 루트 폴더에서 다음 명령을 실행한다:

$ pnpm --filter @mysten/sui test:e2e

테스트용 예시 데이터에 관한 추가 정보는 GitHub의 TypeScript 예시를 참조한다.

활동 모니터링

Sui 네트워크 익스플로러를 사용하여 로컬 네트워크의 활동을 모니터링할 수 있다. 로컬에서 익스플로러를 빌드하고 실행할 수 있으며 많은 온라인 익스플로러에서 제공되는 Custom RPC URL 설정을 사용해 로컬 네트워크의 RPC URL(기본값은 http://127.0.0.1:9000이다)을 제공할 수도 있다.

Sui TypeScript SDK로 테스트

게시된 Sui TypeScript SDK 버전은 로컬 네트워크에 설치한 Sui 버전보다 이전 버전일 수 있다. SDK의 최신 버전을 사용하려면 Sui NPM 레지스트리의 Current Tags 섹션에서 experimental 태그가 붙은 버전(예: 0.0.0-experimental-20230317184920)을 사용한다.

문제 해결

Node.js 18을 사용하지 않으면 다음 메시지가 표시될 수 있다:

Retrying requesting from faucet: Retry failed: fetch is not defined

이를 해결하려면 Node.js 18로 전환하거나 업데이트한 다음 다시 시도한다.