bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 8쪽 중 3쪽
bally distributed RPC infra for dApps. Built with a smart routing engine and 40+ global node providers, it delivers fast, reliable, and scalable access to blockchain networks, ensuring your dApps perform smoothly on both mainnet and testnet. Free accounts available, and paid “lightning-performance” plans start at $10 — full speed. No limits.
**Supported Networks**
* Merlin Mainnet
Access URL: <https://drpc.org/chainlist/merlin-mainnet-rpc>
# Oracle
An Oracle is a tool that brings external data into the blockchain, allowing smart contracts to access real-world information such as prices, weather, and transportation data. This provides critical reference points for the execution of smart contracts. In the Web3 ecosystem, Oracles act as a bridge between the blockchain and the real world. They enable smart contracts to achieve a greater variety of functionalities, thereby advancing the application of blockchain technology across various fields.
Merlin Chain has successfully integrated several Oracle projects. Developers can visit the website and documentation to choose the Oracle that best fits their project development needs and expectations for deployment.
* [Pyth Network](https://pyth.network/)
* [RedStone](https://redstone.finance/)
* [API3](https://api3.org/)
* [APRO Oracle](https://www.apro.com/)
# On-Chain Data
Merlin Chain has integrated with a comprehensive suite of tools and services designed to provide developers with seamless access to on-chain data and analytics.
**Data Platforms for Developer Integration**
* [Chainbase](https://chainbase.com/)
* [Subsquid](https://subsquid.io/)
* [Footprint Analytics](https://www.footprint.network/)
Platforms for On-chain Data Reference
* [GeniiData](https://geniidata.com/ordinals/home)
* [DefiLlama](https://defillama.com/)
* [BTCEden](https://www.btceden.org/)
* [Ave.ai](https://ave.ai/)
# Junior Builder Guides
This section is designed to help new developers get started with Merlin by providing step-by-step instructions on writing and deploying smart contracts. Here, you'll learn how to:
* [**Write a Contract**](/merlin-docs/developers/junior-builder-guides/write-a-contract)**:** Understand the basics of smart contract development and create your first contract.
* [**Deploy a Contract with Hardhat**](/merlin-docs/developers/junior-builder-guides/deploy-a-contract-with-hardhat)**:** Use Hardhat, a development environment for EVM, to compile, test, and deploy your smart contracts on the Merlin Chain.
# Write a Contract
Merlin is EVM compatible. So the smart contracts you wrote for EVM ecosystems also work well for Merlin.
This document explains how to automatically write a smart contract using the OpenZeppelin Wizard. The resulting smart contract code can either be integrated with Remix by Clicking the **Open in Remix** button, or copied to a clipboard and pasted in the user’s intended IDE.
### Getting started <a href="#getting-started" id="getting-started"></a>
Navigate to the [OpenZeppelin Wizard](https://wizard.openzeppelin.com/) in your browser. First thing to notice is the **Solidity Wizard** and **Cairo Wizard** buttons.
One can choose any of the following tabs to begin creating an out-of-box smart contract code in either Solidity (for EVM chains) or Cairo (useful for Starknet). These are:
* **ERC20** for writing an ERC-20 token smart contract.
* **ERC721** for writing an NFT token smart contract.
* **ERC1155** for writing an ERC-1155 token smart contract.
* **Governor** for creating a DAO.
* **Custom** for writing a customized smart contract.
### Writing an NFT contract <a href="#writing-an-nft-contract" id="writing-an-nft-contract"></a>
For illustration purposes, we will be creating a NFT smart contract.
Suppose you wanted to create a `Mintable`, `Burnable` ERC721 token and specify an appropriate license for it.
1. Select the **ERC721** tab.
2. Give your NFT a name and a symbol by filling the `Name` and `Symbol` fields.
3. Use the check-boxes on the left to select features of your token.
4. Put a tick on the `Mintable` check-box.
5. Put a tick on the `Auto Increment Ids` check-box, this ensures uniqueness of each minted NFT.
6. Put a tick on the `Burnable` check-box.
7. Either leave the **default MIT license** or type the license of your choice.
Notice that new lines of code are automatically written each time a feature is selected.
### Voila! Contract is ready <a href="#voila-contract-is-ready" id="voila-contract-is-ready"></a>
With the resulting lines of code, you now have the NFT token contract written in Solidity. As mentioned above, this source code can now be ported to an IDE of your choice or opened directly in Remix.
The below figure depicts the auto-written NFT smart contract code.

# Deploy a Contract with Hardhat
### Overview
Hardhat is one of the popular smart contract development frameworks. Refer to [Hardhat's tutorials](https://hardhat.org/tutorial) for more information.
### Prerequisites
Before you begin, you will need to prepare the following:
* Prepare one EVM account。
* Send some BTC to the account as gas fee 。 You can first bridge some BTC via Merlin Bridge (<https://merlinchain.io/bridge>) and send the BTC to your EVM account used to deploy contracts.
# Run a Merlin Node
# Overview
# Node types
* Json-rpc Node
* Validator Node
# Deployment and Configuration
# Deploy a rpc only node
### Deployment Overview
* Current Testnet and Mainnet version: fork9.
* Recommended configuration for mainnet, can appropriately downgrade for testnet.
* For mainnet: Ensure Docker's home directory is set to the maximum available disk space and configure disk usage alerts.
* For mainnet: Choose the Singapore region as the deployment location for your synchronization nodes.
* Please ensure that time synchronization is enabled and set to UTC+0 on all deployment-related servers.
<table data-full-width="false"><thead><tr><th>Server</th><th>Components</th><th>Recommended hardware</th><th>Comments</th></tr></thead><tbody><tr><td><ul><li>Database</li><li>Sync Server</li></ul></td><td><ul><li>state-db, prover-db</li><li>sync, prover</li></ul></td><td><ul><li><strong>CPU</strong>: 64VCORE, <mark style="color:red;">>= 3050MHZ</mark> </li><li><strong>RAM</strong>: 128G</li><li><strong>DISK</strong>: 2000GB, NVMe SSD</li></ul></td><td>Synchronize the L2 state from master node and L1, only one can run at a time.</td></tr><tr><td><ul><li>RPC Server(s)</li></ul></td><td><ul><li>json-rpc, prover</li></ul></td><td><ul><li><strong>CPU</strong>: 64VCORE, <mark style="color:red;">>= 3050MHZ</mark> </li><li><strong>RAM</strong>: 128G </li><li><strong>DISK</strong>: 2000GB, NVMe SSD</li></ul></td><td>Provide access entry for external requests, can run multiple instances.</td></tr></tbody></table>
## Deployment Steps
### Prepare configuration files
#### docker-compose.yml
If you have modified the default configuration of the database container \[merlin-state-db], please synchronize this configuration with **\[StateDB]** in [node.config.toml](#node.config.toml) and **databaseURL** in [prover.config.json](#prover.config.json).
{% code overflow="wrap" %}
```yaml
version: "3.5"
networks:
default:
name: merlin-rpc-network
services:
cdk-validium-state-db:
container_name: merlin-state-db
restart: unless-stopped
image: postgres:15
cpu_shares: 4096
ports:
- 5432:5432
environment:
- POSTGRES_USER=state_user
- POSTGRES_PASSWORD=state_password
- POSTGRES_DB=state_db
volumes:
- ./init_prover_db.sql:/docker-entrypoint-initdb.d/init.sql
- /data/merlin/data/statedb:/var/lib/postgresql/data
command:
- "postgres"
- "-N"
- "500"
- "-c"
- "max_connections=20000"
- "-c"
- "shared_buffers=16GB"
- "-c"
- "work_mem=32MB"
- "-c"
- "wal_buffers=8MB"
- "-c"
- "effective_cache_size=16GB"
- "-c"
- "maintenance_work_mem=128MB"
- "-c"
- "checkpoint_completion_target=0.7"
- "-c"
- "max_wal_size=4GB"
- "-c"
- "min_wal_size=200MB"
- "-c"
- "max_worker_processes=16"
cdk-validium-pool-db:
container_name: merlin-pool-db
restart: unless-stopped
image: postgres:15
cpu_shares: 4096
ports:
- 5433:5432
environment:
- POSTGRES_USER=pool_user
- POSTGRES_PASSWORD=pool_password
- POSTGRES_DB=pool_db
volumes:
- /data/merlin/data/pooldb:/var/lib/postgresql/data
command:
- "postgres"
- "-N"
- "500"
- "-c"
- "max_connections=10000"
cdk-validium-prover:
container_name: merlin-prover
image: hermeznetwork/zkevm-prover:v6.0.2
restart: unless-stopped
logging:
options:
max-size: '500m'
max-file: '3'
ports:
- 50061:50061 # MT
- 50071:50071 # Executor
volumes:
- ./prover.config.json:/usr/src/app/config.json
command: >
zkProver -c /usr/src/app/config.json
cdk-validium-sync:
container_name: merlin-sync
image: merlinadmin/zkevm-node:v3.1.0
restart: unless-stopped
logging:
options:
max-size: '500m'
max-file: '3'
ports:
- 9091:9091
volumes:
- ./node.config.toml:/app/config.toml
- ./genesis.json:/app/genesis.json
command:
- "/bin/sh"
- "-c"
- "/app/zkevm-node run --network custom --custom-network-file /app/genesis.json --cfg /app/config.toml --components synchronizer"
cdk-validium-json-rpc:
container_name: merlin-rpc
image: merlinadmin/zkevm-node:v3.1.0
restart: unless-stopped
logging:
options:
max-size: '500m'
max-file: '5'
ports:
- 8123:8123
- 8133:8133 # needed if WebSockets enabled
- 9092:9091 # needed if metrics enabled
volumes:
- ./node.config.toml:/app/config.toml
- ./genesis.json:/app/genesis.json
command:
- "/bin/sh"
- "-c"
- "/app/zkevm-node run --network custom --custom-network-file /app/genesis.json --cfg /app/config.toml --components rpc --http.api eth,net,debug,zkevm,txpool,web3" #with debug mode. delete "--http.api eth,net,debug,zkevm,txpool,web3" will remove debug endpoint.
```
{% endcode %}
#### init\_prover\_db.sql
```sql
CREATE DATABASE prover_db;
\connect prover_db;
CREATE SCHEMA state;
CREATE TABLE state.nodes (hash BYTEA PRIMARY KEY, data BYTEA NOT NULL);
CREATE TABLE state.program (hash BYTEA PRIMARY KEY, data BYTEA NOT NULL);
CREATE USER prover_user with password 'prover_password';
ALTER DATABASE prover_db OWNER TO prover_user;
ALTER SCHEMA state OWNER TO prover_user;
ALTER SCHEMA public OWNER TO prover_user;
ALTER TABLE state.nodes OWNER TO prover_user;
ALTER TABLE state.program OWNER TO prover_user;
ALTER USER prover_user SET SEARCH_PATH=state;
```
#### node.config.toml
Update **\[StateDB]** if you use a customized database configuration.
{% code overflow="wrap" %}
```toml
IsTrustedSequencer = false
[Log]
Environment = "production" # "production" or "development"
Level = "info"
Outputs = ["stderr"]
[Synchronizer]
SyncInterval = "1s"
SyncChunkSize = 300
SyncOnlyTrusted = true
TrustedSequencerURL = "https://rpc.merlinchain.io" # for testnet: https://testnet-rpc.merlinchain.io
L1SynchronizationMode = "parallel"
UpgradeEtrogBatchNumber = 1642245
[Synchronizer.L1ParallelSynchronization]
MaxClients = 10
MaxPendingNoProcessedBlocks = 25
RequestLastBlockPeriod = "5s"
RequestLastBlockTimeout = "5s"
RequestLastBlockMaxRetries = 3
StatisticsPeriod = "5m"
TimeoutMainLoop = "5m"
RollupInfoRetriesSpacing = "5s"
FallbackToSequentialModeOnSynchronized = false
[Synchronizer.L1ParallelSynchronization.PerformanceWarning]
AceptableInacctivityTime = "5s"
ApplyAfterNumRollupReceived = 10
[Etherman]
URL = "https://mainnet-l1.merlinchain.io" # for testnet: https://testnet-l1.merlinchain.io
ForkIDChunkSize = 20000
MultiGasProvider = false
[RPC]
Host = "0.0.0.0"
Port = 8123
ReadTimeout = "360s"
WriteTimeout = "360s"
MaxRequestsPerIPAndSecond = 10000
SequencerNodeURI = "https://rpc.merlinchain.io" # for testnet: https://testnet-rpc.merlinchain.io
EnableL2SuggestedGasPricePolling = false
TraceBatchUseHTTPS = true
BatchRequestsEnabled = true
BatchRequestsLimit = 10000
[RPC.WebSockets]
Enabled = true
Host = "0.0.0.0"
Port = 8133
[State]
[State.DB]
User = "state_user"
Password = "state_password"
Name = "state_db"
Host = "merlin-state-db"
Port = "5432"
EnableLog = false
MaxConns = 800
[State.Batch]
[State.Batch.Constraints]
MaxTxsPerBatch = 300
MaxBatchBytesSize = 120000
MaxCumulativeGasUsed = 1125899906842624
MaxKeccakHashes = 2145
MaxPoseidonHashes = 252357
MaxPoseidonPaddings = 135191
MaxMemAligns = 236585
MaxArithmetics = 236585
MaxBinaries = 473170
MaxSteps = 7570538
MaxSHA256Hashes = 1596
[Pool]
FreeClaimGasLimit = 1500000
IntervalToRefreshBlockedAddresses = "5m"
IntervalToRefreshGasPrices = "5s"
MaxTxBytesSize = 100132
MaxTxDataBytesSize = 100000
DefaultMinGasPriceAllowed = 6000000
MinAllowedGasPriceInterval = "5m"
PollMinAllowedGasPriceInterval = "15s"
AccountQueue = 100
GlobalQueue = 10240
[Pool.EffectiveGasPrice]
Enabled = false
L1GasPriceFactor = 0.25
ByteGasCost = 16
ZeroByteGasCost = 4
NetProfit = 1
BreakEvenFactor = 1.1
FinalDeviationPct = 10
EthTransferGasPrice = 0
EthTransferL1GasPriceFactor = 0
L2GasPriceSuggesterFactor = 0.5
[Pool.DB]
User = "pool_user"
Password = "pool_password"
Name = "pool_db"
Host = "merlin-pool-db"
Port = "5432"
EnableLog = false
MaxConns = 800
[Metrics]
Host = "0.0.0.0"
Port = 9091
Enabled = true
ProfilingHost = "0.0.0.0"
ProfilingPort = 6060
ProfilingEnabled = true
[MTClient]
URI = "cdk-validium-prover:50061"
[Executor]
URI = "cdk-validium-prover:50071"
MaxResourceExhaustedAttempts = 5
WaitOnResourceExhaustion = "1s"
MaxGRPCMessageSize = 300000000
```
{% endcode %}
#### prover.config.json
Update **databaseURL** if you use a customized database configuration.
```json
{
"configPath": "/usr/src/app/config",
"runExecutorServer": true,
"runExecutorClient": false,
"runExecutorClientMultithread": false,
"runHashDBServer": true,
"runHashDBTest": false,
"runAggregatorServer": false,
"runAggregatorClient": false,
"runFileGenBatchProof": false,
"runFileGenAggregatedProof": false,
"runFileGenFinalProof": false,
"runFileProcessBatch": false,
"runFileProcessBatchMultithread": false,
"runKeccakScriptGenerator": false,
"runKeccakTest": false,
"runStorageSMTest": false,
"runBinarySMTest": false,
"runMemAlignSMTest": false,
"runSHA256Test": false,
"runBlakeTest": false,
"executeInParallel": true,
"useMainExecGenerated": true,
"saveRequestToFile": false,
"saveInputToFile": false,
"saveDbReadsToFile": false,
"saveDbReadsToFileOnChange": false,
"saveOutputToFile": true,
"saveProofToFile": true,
"saveResponseToFile": false,
"loadDBToMemCache": true,
"opcodeTracer": false,
"logRemoteDbReads": false,
"logExecutorServerResponses": false,
"proverServerPort": 50051,
"proverServerMockPort": 50052,
"proverServerMockTimeout": 10000000,
"proverClientPort": 50051,
"proverClientHost": "127.0.0.1",
"executorServerPort": 50071,
"executorROMLineTraces": false,
"executorClientPort": 50071,
"executorClientHost": "127.0.0.1",
"hashDBServerPort": 50061,
"hashDBURL": "local",
"aggregatorServerPort": 50081,
"aggregatorClientPort": 50081,
"aggregatorClientHost": "zkevm-node",
"mapConstPolsFile": false,
"mapConstantsTreeFile": false,
"inputFile": "input_executor_0.json",
"inputFile2": "input_executor_1.json",
"keccakScriptFile": "config/scripts/keccak_script.json",
"storageRomFile": "config/scripts/storage_sm_rom.json",
"outputPath": "output",
"databaseURL": "postgresql://prover_user:prover_password@merlin-state-db:5432/prover_db",
"dbNodesTableName": "state.nodes",
"dbProgramTableName": "state.program",
"dbMultiWrite": true,
"dbFlushInParallel": false,
"dbMTCacheSize": 1024,
"dbProgramCacheSize": 512,
"dbNumberOfPoolConnections": 2000,
"dbGetTree": true,
"cleanerPollingPeriod": 600,
"requestsPersistence": 3600,
"maxExecutorThreads": 500,
"maxProverThreads": 20,
"maxHashDBThreads": 300,
"ECRecoverPrecalc": false,
"ECRecoverPrecalcNThreads": 4,
"stateManager": true,
"useAssociativeCache": false
}
```
#### genesis.json 
* testnet
```url
https://download.merlinchain.io/merlin/testnet/genesis.json
```
* mainnet
```url
https://download.merlinchain.io/merlin/mainnet/genesis.json
```
### Launch database
#### **Database Server**
```shell
docker compose up -d cdk-validium-state-db
```
### Snapshot Recovery
* Install postgresql-client-15
```shell
# Install dependency
sudo apt install gnupg2 wget vim -y
# Enable official package repo
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Import GPG signing key
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
# Update system packages
sudo apt update -y
# Install postgres client
sudo apt install postgresql-client-15 -y
```
* Download recovery database snapshot
```shell
# Confirm the creation date of below downloaded files; they must be on the same day.
# Testnet
wget https://rpc-snapshot.merlinchain.io/testnet_state_db.sql.tar.gz
wget https://rpc-snapshot.merlinchain.io/testnet_prover_db.sql.tar.gz
# Mainnet
wget https://rpc-snapshot.merlinchain.io/state_db.sql.tar.gz
wget https://rpc-snapshot.merlinchain.io/prover_db.sql.tar.gz
```
* Prepare recovery script
```shell
git clone https://github.com/0xPolygon/cdk-validium-node.git
cd cdk-validium-node
# Recommend using Go 1.21 or a later version
go build -o ./build ./cmd
```
* Prepare recovery configuration
```shell
# touch a config file named "snapshot_restore.toml"
vim snapshot_restore.toml
```
```ini
# update the database connection info based on your "docker-compose.yml"
[Log]
Environment = "production" # "production" or "development"
Level = "debug" # "info"
Outputs = ["stderr"]
[State]
[State.DB]
User = "state_user"
Password = "state_password"
Name = "state_db"
Host = "127.0.0.1"
Port = "5432"
EnableLog = false
MaxConns = 200
[HashDB]
User = "prover_user"
Password = "prover_password"
Name = "prover_db"
Host = "127.0.0.1"
Port = "5432"
EnableLog = false
MaxConns = 200
```
* Execute recovery
```shell
# Assuming you are currently under previous Git directory, and the snapshot recovery file you downloaded is also in the current directory (or you can manually specify the location), execute the following command for recovery:
./build restore --cfg ./snapshot_restore.toml -is ./state_db.sql.tar.gz -ih ./prover_db.sql.tar.gz
```
* Add extra index for state db
```sql
CREATE INDEX IF NOT EXISTS l2block_block_hash_idx ON state.l2block (block_hash);
CREATE INDEX IF NOT EXISTS l2block_created_at_idx ON state.l2block (created_at);
CREATE INDEX IF NOT EXISTS log_log_index_idx ON state.log (log_index);
CREATE INDEX IF NOT EXISTS log_topic0_idx ON state.log (topic0);
CREATE INDEX IF NOT EXISTS log_topic1_idx ON state.log (topic1);
CREATE INDEX IF NOT EXISTS log_topic2_idx ON state.log (topic2);
CREATE INDEX IF NOT EXISTS log_topic3_idx ON state.log (topic3);
CREATE INDEX IF NOT EXISTS idx_receipt_tx_index ON state.receipt (block_num, tx_index);
CREATE INDEX IF NOT EXISTS receipt_block_num_idx ON state.receipt USING btree (block_num);
```
### **Launch other containers**
#### **Sync Server**
```shell
docker compose up -d cdk-validium-prover
docker compose up -d cdk-validium-pool-db
sleep 5
docker compose up -d cdk-validium-sync
```
#### **RPC Server**
```shell
docker compose up -d cdk-validium-prover
docker compose up -d cdk-validium-pool-db
sleep 5
docker compose up -d cdk-validium-json-rpc
```
## Installation Verification
On the RPC host, execute the following command:
```shell
curl --location 'http://localhost:8123' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}'
```
The expected result should be a valid block number:
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x2855"
}
```
## Troubleshooting
* Please note that there should be no indication of port occupation when checking the port mappings for Docker.
* Ensure that in all your configuration 프로젝트로 돌아가기