> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plasma.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 빠른 시작

> 환경을 설정하고 Hardhat 또는 Foundry를 사용해 Plasma Testnet에 계약을 배포합니다.

이 가이드는 Hardhat을 사용하여 Plasma의 EVM 호환 테스트넷에서 환경 설정, 계약 배포 및 상호 작용을 다룹니다. Ethereum 도구와 스마트 계약 개발에 대한 기본 지식이 있다고 가정합니다.

## 사전 요구 사항

* Node.js 20+
* Ethereum 개발에 대한 기본 지식
* 브라우저 지갑

## 환경 설정

Hardhat을 사용하여 계약을 빌드하고 배포합니다.

### Hardhat 설정

1. 새 프로젝트 디렉터리를 만들고 초기화합니다:

   ```shell theme={null}
   mkdir my-plasma-project
   cd my-plasma-project
   npm init -y
   npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
   npm install dotenv
   npx hardhat init
   ```
2. 단계를 따라 JavaScript 프로젝트를 만듭니다. 프로젝트를 원하는 곳에 저장합니다. 이 빠른 시작에서는 `.gitignore` 파일이 필요하지 않을 가능성이 큽니다.
3. Plasma 테스트넷을 위해 `hardhat.config.js`를 구성합니다:

   ```javascript theme={null}
   require("@nomicfoundation/hardhat-toolbox");
   require("dotenv").config();

   /** @type import('hardhat/config').HardhatUserConfig */
   module.exports = {
     solidity: "0.8.28",
     networks: {
       plasmaTestnet: {
         url: process.env.RPC_ENDPOINT,
         chainId: 9746,
         accounts: [process.env.PRIVATE_KEY] // We'll set this up next.
       }
     }
   };
   ```

## 지갑 및 테스트넷 설정

### 브라우저 지갑에 Plasma Testnet 추가

1. 브라우저 지갑(MetaMask, Trust Wallet 또는 Rabby)을 열고 네트워크 선택기를 클릭합니다.
2. 사용자 정의 네트워크를 추가하는 옵션을 선택합니다(예: **네트워크 추가**, **수동으로 추가** 또는 **사용자 정의 네트워크 추가**).
3. 다음 세부 정보를 입력합니다:
   * **네트워크 이름**: Plasma Testnet
   * **새 RPC URL**: `https://testnet-rpc.plasma.to`
   * **체인 ID**: `9746`
   * **통화 기호**: `XPL`
   * **블록 익스플로러 URL**: `https://testnet.plasmascan.to`
4. 네트워크를 저장하고 지갑에서 Plasma Testnet으로 전환합니다.

### 테스트넷 토큰 받기

1. 브라우저 지갑에서 지갑 주소를 복사합니다.
2. [openfaucet.org](https://openfaucet.org/)를 방문합니다.
3. 주소를 입력하고 테스트넷 토큰을 요청합니다.
4. 트랜잭션이 완료될 때까지 기다립니다(몇 초 내에 지갑에 표시됩니다).

### 환경 변수 설정

1. 브라우저 지갑의 계정 설정을 사용해 계정의 개인 키를 내보냅니다.
2. 프로젝트 루트에 `.env` 파일을 만듭니다:

   ```shell theme={null}
   PRIVATE_KEY=your_private_key_here
   RPC_ENDPOINT=https://testnet-rpc.plasma.to
   ```

<Warning>
  개인 키나 니모닉을 버전 관리에 커밋하지 마십시오. `.env`를 `.gitignore` 파일에 추가하십시오.
</Warning>

## 간단한 스마트 계약 작성

1. 기본 저장 계약 `contracts/SimpleStorage.sol`을 만듭니다:

   ```solidity theme={null}
   // SPDX-License-Identifier: MIT
   pragma solidity ^0.8.28;

   contract SimpleStorage {
       string private storedData;
       
       event DataStored(string data);
       
       constructor() {
           storedData = "Hello, Plasma!";
       }
       
       function setData(string memory data) public {
           storedData = data;
           emit DataStored(data);
       }
       
       function getData() public view returns (string memory) {
           return storedData;
       }
   }
   ```
2. 계약을 컴파일합니다:

   ```shell theme={null}
   npx hardhat compile
   ```

   다음과 같은 출력이 표시되어야 합니다:

   ```plaintext theme={null}
   Downloading compiler 0.8.28
   Downloading compiler 0.8.28
   Compiled 2 Solidity files successfully (evm target: paris).
   ```

## 테스팅

1. 테스트 스크립트 `test/SimpleStorage.js`를 만듭니다:

   ```javascript theme={null}
   const { expect } = require("chai");

   describe("SimpleStorage", function () {
     let simpleStorage;

     beforeEach(async function () {
       const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
       simpleStorage = await SimpleStorage.deploy();
       await simpleStorage.waitForDeployment();
     });

     it("Should return the initial greeting", async function () {
       expect(await simpleStorage.getData()).to.equal("Hello, Plasma!");
     });

     it("Should update the stored data", async function () {
       await simpleStorage.setData("Updated data");
       expect(await simpleStorage.getData()).to.equal("Updated data");
     });
   });
   ```
2. 테스트를 실행합니다:

   ```shell theme={null}
   npx hardhat test
   ```

   다음과 같은 출력이 표시되어야 합니다:

   ```plaintext theme={null}
   Lock
     Deployment
       ✔ Should set the right unlockTime (454ms)
       ✔ Should set the right owner
       ✔ Should receive and store the funds to lock
       ✔ Should fail if the unlockTime is not in the future
     Withdrawals
       Validations
         ✔ Should revert with the right error if called too soon
         ✔ Should revert with the right error if called from another account
         ✔ Shouldn't fail if the unlockTime has arrived and the owner calls it
       Events
         ✔ Should emit an event on withdrawals
       Transfers
         ✔ Should transfer the funds to the owner

   SimpleStorage
     ✔ Should return the initial greeting
     ✔ Should update the stored data


   11 passing (541ms)
   ```

### Plasma Testnet에 배포

1. 먼저, `scripts` 디렉터리를 만듭니다:

   ```shell theme={null}
   mkdir scripts
   ```
2. 다음으로, 계약을 배포할 스크립트 `scripts/deploy.js`를 만듭니다:

   ```javascript theme={null}
   async function main() {
     const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
     
     console.log("Deploying SimpleStorage...");
     const simpleStorage = await SimpleStorage.deploy();
     await simpleStorage.waitForDeployment();
     
     const address = await simpleStorage.getAddress();
     console.log("SimpleStorage deployed to:", address);
   }

   main()
     .then(() => process.exit(0))
     .catch((error) => {
       console.error(error);
       process.exit(1);
     });
   ```
3. 계약을 배포합니다:

   ```shell theme={null}
   npx hardhat run scripts/deploy.js --network plasmaTestnet
   ```

   다음과 같은 출력이 표시되어야 합니다:

   ```plaintext theme={null}
   Deploying SimpleStorage...
   SimpleStorage deployed to: 0xaa4FB2A8eD6953A4e57b8097BAf048d7919e6262
   ```
4. `deployed to:` 주소를 기록해 두십시오. 이는 Plasma 테스트넷에서 계약의 주소입니다.

## 배포 확인

1. 계약 주소를 복사합니다.
2. [Plasma 테스트넷 익스플로러](https://testnet.plasmascan.to/)를 방문합니다.
3. 계약 주소를 검색하여 배포 트랜잭션을 확인합니다.

## 문제 해결

| 문제         | 해결 방법                                          |
| :--------- | :--------------------------------------------- |
| 가스 추정 오류   | 지갑에 충분한 XPL이 있는지 확인하십시오                        |
| 네트워크 연결 오류 | RPC URL과 테스트넷 가용성을 확인하십시오                      |
| 개인 키 오류    | `.env`가 올바르게 구성되었는지 확인하십시오(필요한 경우 `0x` 접두사 없음) |
| 익스플로러 지연   | 몇 분 기다리십시오. 익스플로러가 동기화 중일 수 있습니다               |
