# Flashblocks

## Flashblocks란?

일반적으로 트랜잭션을 전송한 뒤에는 해당 트랜잭션이 블록에 포함될 때까지 기다려야해요. GIWA의 블록 생성주기에 따라 이 시간은 최대 1초가 될 수 있습니다. (단, 네트워크 혼잡 시 더 길어질 수 있어요.)

Flashblocks는 이 과정에서 블록이 완전히 생성될 때까지 기다리지 않고, preconfirmation 이라는 즉각적인 피드백 (최대 200ms)을 줌으로써 사용자가 트랜잭션을 보낸 직후 아주 짧은 시간 안에 결과를 확인할 수 있도록 도와줘요.

즉, 블록 자체를 더 빨리 만드는 기능이 아니라 블록 생성 전에 트랜잭션 상태를 더 빨리 알려주는 기능입니다.

이러한 특성 때문에 다음과 같은 앱에서 활용할 수 있어요.

* 트랜잭션 전송 및 반영을 즉각적으로 보여주고 싶은 지갑 및 웹서비스
* 빠른 결제 경험을 제공해주고 싶은 페이먼트 서비스
* 반응성이 중요한 게임 및 실시간 서비스

## Flashblocks 사용하기

Flashblocks RPC는 일반적인 Ethereum JSON-RPC 인터페이스와 동일하게 동작해요. Flashblocks RPC를 사용하기 위해서는 해당 RPC 노드가 Flashblocks mode를 지원해야하며, 이를 Flashblocks-aware RPC 라고 합니다.

### Flashblocks-aware RPC

GIWA에서는 개발 및 테스트 용도를 위해 무료로 제공하는 Flashblocks-aware RPC가 있어요.

<table><thead><tr><th width="240.471435546875">Network</th><th>Endpoint</th></tr></thead><tbody><tr><td>GIWA Testnet (Sepolia)</td><td><a href="https://sepolia-rpc-flashblocks.giwa.io/">https://sepolia-rpc-flashblocks.giwa.io</a></td></tr><tr><td>GIWA Mainnet</td><td>🚧 GIWA Mainnet 은 현재 준비 중이에요.</td></tr></tbody></table>

{% hint style="warning" %}
위에서 제공하는 RPC는 개발 및 테스트 목적으로 제공되며 rate limit이 걸려있습니다. 실서비스용 앱에는 외부 노드 서비스 사용을 권장합니다. 또는 여러분이 [직접 Flashblocks-aware RPC 노드](https://github.com/giwa-io/node#flashblocks-optional)를 운영할 수 있습니다.
{% endhint %}

### 지원하는 RPC Methods

#### `eth_call`

`pending` 태그를 통해, 최신 flashblock 상태를 기준으로 스마트 컨트랙트 호출을 실행해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_call",
    "params": [{"to": "0x...", "data": "0x..."}, "pending"],
    "id": 1
  }'
```

**Response**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x0000000000000000000000000000000000000000000000000000000000000001"
}
```

#### `eth_estimateGas`

`pending` 태그를 통해, 최신 flashblock 상태를 기준으로 가스 사용량을 추정해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_estimateGas",
    "params": [{"to": "0x...", "data": "0x..."},"pending"],
    "id": 1
  }'
```

**Response**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x9425"
}
```

#### `eth_getBalance`

`pending` 태그를 통해, 최신 flashblock 상태를 기준으로 잔고를 반환해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getBalance",
    "params": ["0x...", "pending"],
    "id": 1
  }'
```

**Response**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x1234"
}
```

#### `eth_getBlockByNumber`

`pending` 태그를 통해, 최신 flashblock 상태를 기준으로 블록 정보를 반환해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getBlockByNumber",
    "params": ["pending", true],
    "id": 1
  }'
```

**Response**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0x1234",
    "hash": "0x..",        // 같은 블록이어도 preconfirmed 트랜잭션 목록이 바뀌는 경우 매번 변경됨
    "transactions": [...], // 모든 preconfirmed 트랜잭션 목록
    "stateRoot": "0x...",
    "gasUsed": "0x...",
    "timestamp": "0x..."
  }
}
```

#### `eth_getLogs`

`pending` 태그를 통해, 최신 flashblock 상태를 기준으로 로그를 반환해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getLogs",
    "params": [{"fromBlock": "latest", "toBlock": "pending", "address": "0x...", "topics": ["0x..."]}],
    "id": 1
  }'
```

**Response**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "address": "0x...",
      "topics": ["0x..."],
      "data": "0x...",
      "blockNumber": "0x1234",
      "transactionHash": "0x...",
      "transactionIndex": "0x0",
      "blockHash": "0x...",
      "logIndex": "0x0",
      "removed": false
    }
  ]
}
```

#### `eth_getTransactionCount`

`pending` 태그를 통해, 최신 flashblock 상태를 기준으로 해당 주소의 nonce를 반환해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionCount",
    "params": ["0x...", "pending"],
    "id": 1
  }'
```

**Response**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x12"
}
```

#### `eth_getTransactionByHash`

Flashblock에 포함된 특정 해시의 트랜잭션 정보를 반환해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionByHash",
    "params": ["0x..."],
    "id": 1
  }'
```

**Response**

```json
{
	"jsonrpc": "2.0",
	"result": {
		"blockHash": "0x...",
		"blockNumber": "0x1234",
		"chainId": "0x164ce",
		"nonce": "0x23",
		"transactionIndex": "0x3",
		"type": "0x2",
	},
	"id": 1
}
```

#### `eth_getTransactionReceipt`

Flashblock에 포함된 트랜잭션 receipt 정보를 반환해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionReceipt",
    "params": ["0x..."],
    "id": 1
  }'
```

**Response**

```json
{
  "jsonrpc": "2.0",
  "result": {
    "transactionHash": "0x...",
    "blockNumber": "0x1234",
    "status": "0x1"
  },
  "id": 1
}
```

#### `eth_simulateV1`

최신 flashblock 상태를 기준으로 트랜잭션을 시뮬레이션해요.

**Request**

```bash
curl https://sepolia-rpc-flashblocks.giwa.io \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_simulateV1",
    "params": [{"blockStateCalls": [{"calls": [{"to": "0x...", "data": "0x..."}], "stateOverrides":{}}], "traceTransfers":true, "validation":true}, "pending"],
    "id": 1
  }'
```

**Response**

```json
{
  "jsonrpc": "2.0",
  "result": [
    {
      "calls": [
        {
          "status": "0x1",
          "gasUsed": "0x1234",
          "returnData": "0x"
        }
      ]
    }
  ],
  "id": 1
}
```

## 더 알아보기

[OP 스택 개발자 문서](https://docs.optimism.io/op-stack/features/flashblocks)를 확인해보세요.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.giwa.io/network-information/flashblocks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
