Ethereum: How to set syncnode of a peer to true?

Setting a colleague’s synchronization on True

As a developer’s network or administrator, ensuring that your Ethererem testnet connection is correctly configured for synchronization with other knots can be crucial for maintaining consistency of data and to prevent orphans from orphan. In this article, we will go through the process of installing a node to synchronize a colleague on TRUE on a test relationship.

What is a synchronized knot?

In Ethereum, the synchronization node
node that acts as an intermediary among other knots on the network, transmits the data and ensures that all nodes are synchronized. When the buyer connects to the synchronization node, he may request information about other clients associated with the same knot, including addresses, services and last time.

Why do you place a synchronization node to the truth?

Setting a synchronization node of colleagues is true that:

  • All knots online are aware of the presence and connection of the other.

  • Each customer’s data is propagated by the network and available for synchronization by other customers.

  • Orphans blocks, which may occur when the knot switches off or re -connected, are removed from the net.

Step by Step

To place a synchronization node of colleagues on TRUE on Testnet test, follow these steps:

1.
Get information from equal

First of all, you need to regain information about your colleague you want to sync. You can do this with the “Getpeerinfo control with the Ethereum console or by calling the API.

`Bash

ETH console -Q Getpeerinfo

Replacewith a test address.

2

ExitingGetpeerinfocommand will contain a JSON object containing different information about a colleague, including its addresses and services.

Json

{

"ADDR": "172.20.61.111:63379",

"Services": "00000001",

"Lasts": ...

Iche

In this example:

  • ADDRis an address.

  • Services’ indicates that this colleague uses 0x services (for example, eth, ether).

  • Lastsend 'provides information about the last moment when this customer sent a message.

3.
Creating a Synchronization Node

To set a colleague's synchronization knot in True, you need to create an instance of "Syncnode" class that connects to the test connection. You can use the following code as a starting point:

Javascript

Const net = requires (‘ethers’);

Const {Sincnode} = requires (‘./ Sync-Dode.js’);

Async function main () {{

Const NetworkConfig = New Network.web3.Providers.httpprovider (‘

const client = new network.Client (NetworkConfig);

// Create an instance of a node synchronization

Const Sincnode = New Sincnode (client, ‘0x00000001’, 1); // Replace -in your services.

// Set the synchronization node to TRUE

Sincnode.setsynnode (truth);

Iche

Main (). Catch ((Error) => Console.error (Error));

`

Be sure to replaceyour_Project_idwith the ETTRETNET project ID.

4.
Update information from equal

Finally, you need to update the data from the JSON object obtained by the pre -installation of its services to 1 (or other valid service code). You can do this using a small javascript function:

Javascript

Function Setservice (Peerinfo) {{

If (! Peerinfo.Service

// Set the services of ETH -u if they are not already present

Peerinfo.ervicees = [‘et’];

Iche

Returns Peerinfo;

Iche

// Update data from equal services set to 1

Const Updateeerinfo = Setservicees ({… Peerinfo});

Console.log (updatedpeerinfo);

`

Conclusion

Looking at these steps and usingsyncnode`, you can easily set a node to synchronize the right colleague to your Ethereum Teston connection.