> For the complete documentation index, see [llms.txt](https://services.stakeangle.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://services.stakeangle.com/mainnets/chain4energy/state-sync.md).

# State Sync

{% hint style="info" %}
State Sync allows to sync a new node by fetching a snapshot of the network state at a recent height, instead of fetching and replaying all historical blocks.
{% endhint %}

{% hint style="info" %}
Some networks which use `wasm` may not yet support `wasm` folder transfers with State Sync. In this case you may need to download `wasm` folder separately.
{% endhint %}

{% hint style="info" %}
Depending on network, State Sync may need different amount of RAM to successfully fish sync process. It is recommended to have at least 8GB RAM.
{% endhint %}

1. **Stop existing service and reset database.**

```
sudo systemctl stop c4ed
c4ed unsafe-reset-all --home $HOME/.c4e-chain
```

2. **Add peers.**

```
PEER="1b802d4616c1de3fa687ad0d671b1b9d64754a44@88.198.49.217:26156,3d75b4da612395d69ef58a0f6dbb851bd98c1962@185.144.99.246:26656,a9bdcae2527c4a27a6f4882e852329241a945699@46.4.81.204:30656,2f6141859c28c088514b46f7783509aeeb87553f@141.94.193.12:11656,bf78d9bd64cf7e83357966aa3b4ca19d996ef1ef@51.75.55.49:26656,e84d7bff6960e7b50ee8eba09ef6f25b0b0b30cc@95.214.53.105:56656,717c041cf112f778508033e99a16288ec9d034c8@95.217.35.186:60756,cff10605b619e5119a1c9d53397a798de8fbf83b@64.227.136.63:26656,770fc199534d3126ff336b93aaf643a80e12761a@185.169.252.22:26656,c37c30000caf21391e77a457f7721685e41bea42@195.3.223.221:26656,d4c6f17b49af7f96c587613cbdb6e41b179079c2@185.208.206.217:26656"
sed -i.bak -e "s/^persistent_peers *=.*/persistent_peers = \"$PEER\"/" $HOME/.c4e-chain/config/config.toml
```

3. **Fill variables with data for State Sync.**

```
RPC="https://chain4energy-rpc.stakeangle.com:443"
RECENT_HEIGHT=$(curl -s $RPC/block | jq -r .result.block.header.height)
TRUST_HEIGHT=$((RECENT_HEIGHT - 1000))
TRUST_HASH=$(curl -s "$RPC/block?height=$TRUST_HEIGHT" | jq -r .result.block_id.hash)

echo $RECENT_HEIGHT $TRUST_HEIGHT $TRUST_HASH
```

4. **Add variable values to config.toml.**

```
sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$RPC,$RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$TRUST_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" $HOME/.c4e-chain/config/config.toml
```

5. **Start service and check journal.**

```
sudo systemctl restart c4ed
sudo journalctl -u c4ed -f -o cat
```

{% hint style="info" %}
State Sync typically takes up to 10 minutes.&#x20;
{% endhint %}
