본문으로 건너뛰기

로컬 네트워크 연결

Sui 로컬 네트워크를 사용하여 최신 Sui 변경 사항에 대해 dApp을 테스트하고 Devnet 또는 Testnet 네트워크에 대한 다음 Sui 릴리스에 대비하라. Sui CLI는 로컬 네트워크를 시작하기 위한 sui start 명령을 제공한다. sui start를 사용할 때는 인덱서, faucet, 또는 GraphQL 서비스의 로컬 인스턴스(웹 기반 GraphiQL IDE 포함)와 같이 여러 서비스를 시작할 수 있다. 포함된 faucet을 사용하여 로컬 네트워크에서 사용할 테스트 SUI를 받을 수 있다.

아직 설치하지 않았다면 시스템에 Sui 설치를 해야 한다.

Start the local network

로컬 네트워크를 시작하려면 Sui CLI를 설치한 후 다음 명령을 실행하라.

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

이 명령은:

  • 두 개의 플래그와 함께 Sui CLI 바이너리를 호출한다:
  • --with-faucet faucet 서비스를 시작하기 위한 플래그이다.
  • --force-regenesis는 새로운 제네시스를 생성하고 로컬 네트워크 상태를 유지하지 않기 위한 플래그이다.
  • 이는 RUST_LOG=off,sui_node=info 플래그를 통해 Rust가 특정 로깅을 설정하도록 지시하며 sui-node를 제외한 모든 구성 요소에 대한 로깅을 끈다. 더 자세한 로그를 보고 싶다면 명령에서 RUST_LOG를 제거할 수 있다.
정보

--force-regenesis를 전달하여 네트워크를 시작할 때마다 로컬 네트워크는 이전 데이터가 없는 랜덤 제네시스에서 시작하며 로컬 네트워크는 유지되지 않는다. 데이터를 유지하려면 --force-regenesis 플래그를 전달하지 않는다. 자세한 내용은 Persist local network state 섹션을 참조하라. 또한 /tmp에 임시 디렉터리가 생성되는데 /tmp 폴더가 /tmpfs에 마운트되어 있으면 동작하지 않을 수 있으므로 이 경우 TMPDIR=./some_folder를 설정하라.

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

정보

with-indexer, with-graphql 및 관련 옵션과 플래그를 사용하려면 PostgreSQL/libpq가 설치되어 있어야 한다. 아래의 가능한 옵션 목록에서 기본적으로 요구되는 DB와 다른 DB를 전달하는 방법을 확인하라.

다음은 sui start에 전달할 수 있는 가능한 옵션과 플래그의 목록이다.

    --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
--with-graphql[=<WITH_GRAPHQL>] Start a GraphQL server on localhost and port: 127.0.0.1:9125, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-graphql=6125`. Note that
GraphQL requires a running indexer
--with-faucet[=<WITH_FAUCET>] Start a faucet with default host and port: 127.0.0.1:9123, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-faucet=6123`
--with-indexer[=<WITH_INDEXER>] Start an indexer with default host and port: 0.0.0.0:9124, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-indexer=6124`. The indexer be started in writer mode and reader mode
--fullnode-rpc-port <FULLNODE_RPC_PORT> Port to start the Fullnode RPC server on. Default port is 9000 [default: 9000]
--pg-port <PG_PORT> Port for the Indexer Postgres DB. Default port is 5432 [default: 5432]
--pg-host <PG_HOST> Hostname for the Indexer Postgres DB. Default host is localhost [default: localhost]
--pg-db-name <PG_DB_NAME> DB name for the Indexer Postgres DB. Default DB name is sui_indexer [default: sui_indexer]
--pg-user <PG_USER> DB username for the Indexer Postgres DB. Default username is postgres [default: postgres]
--pg-password <PG_PASSWORD> DB password for the Indexer Postgres DB. Default password is postgrespw [default: postgrespw]
--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
--no-full-node Start the network without a fullnode
-h, --help Print help (see more with '--help')

콘솔에서 sui start --help를 사용하여 위 옵션들을 확인할 수 있다.

Persist local network state

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

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

정보

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

Access your local full node

로컬 네트워크에서 총 transaction 수를 가져오려면 다음 명령을 사용하라:

$ 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
}

Connect the Sui CLI to your local network

Sui CLI는 어떤 Sui 네트워크에서도 사용할 수 있다. 기본적으로는 Sui Devnet에 연결된다. 로컬 네트워크에 연결하려면 클라이언트가 사용하는 RPC URL을 로컬 네트워크로 설정하는 local이라는 새 environment alias를 생성해야한다.

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

다음으로, 생성한 새 local environment로 활성 environment를 설정하려면 다음 명령을 사용하라.

sui client switch --env local

이 명령은 다음을 반환한다:

Active environment switched to [local]

다음 명령으로 현재 활성 environment를 확인할 수 있다:

$ sui client active-env

이 명령은 다음을 반환한다:

local

Show the current active address

Sui Client CLI는 주소를 지정하지 않으면 명령에 활성 주소를 사용한다. 로컬 네트워크에서 활성 주소를 표시하려면 다음 명령을 사용하라.

sui client active-address

이 명령은 다음 예시와 같은 주소를 반환한다:

0xbc33e6e4818f9f2ef77d020b35c24be738213e64d9e58839ee7b4222029610de

로컬 네트워크에서 사용할 테스트 SUI를 받기 위해 활성 주소를 사용하라. 로컬 네트워크의 모든 주소를 보려면 sui client addresses 명령을 사용하라.

정보

이 명령을 실행할 때 반환되는 주소는 고유하며 이 예시에서 사용된 주소와 일치하지 않는다.

Use the local faucet

로컬 네트워크의 transaction은 다른 네트워크와 마찬가지로 가스 수수료를 지불하기 위해 SUI 코인이 필요하다. faucet에서 활성 주소를 사용할 수 있다.

Sui CLI는 faucet에서 코인을 받기 위한 sui client faucet 명령을 제공한다. 가장 기본적인 경우 sui client faucet를 실행하고 코인이 주소에 도달할 때까지 최대 60초 동안 기다려야 한다. 새 코인을 확인하려면 sui client gas를 사용하라.

정보

faucet 명령은 기본적으로 활성 주소와 활성 네트워크 environment를 사용한다. 다른 주소나 faucet 서버 URL을 전달해야 한다면 help 메뉴를 확인하라. 로컬 네트워크나 공개 네트워크(fullnode.network.sui.io)가 아닌 다른 네트워크를 사용한다면 faucet 서버의 URL을 전달해야 한다.

Check the gas coin objects for the active address

faucet에서 코인을 받은 후 다음 명령을 사용하여 해당 주소의 코인 object를 확인하라:

$ sui client gas

응답은 다음과 유사하지만 ID는 다르게 표시될 것이다:

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

Generate example data

네트워크에 예시 데이터를 추가하려면 TypeScript SDK를 사용한다. 이를 위해 인덱서와 GraphQL을 포함하여 로컬 네트워크를 시작해야 하며 sui start --force-regenesis --with-faucet --with-indexer --with-graphql를 사용하라. 그런 다음 sui 루트 폴더에서 다음 명령을 실행하라:

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

테스트를 위한 예시 데이터에 대한 추가 정보는 https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript#testing를 참조하라.

Monitor activity

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

Troubleshooting

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

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

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

Test with the Sui TypeScript SDK

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