Why PTP on Blockchain?
Traditional blockchain timestamps operate at second-level precision, limiting their utility for high-precision applications. By implementing PTP on peaq, we achieve:- Nanosecond-level precision timing
- Distributed time synchronization
- Blockchain-verified timestamps
- Trustless time coordination for machine networks
- Superior Network Time Accuracy: Unlike NTP, which allows for variable offset ranges, PTP provides deterministic and precise time synchronization
Architecture

Implementation Guide
peaq’s PTP implementation provides nanosecond-precise time synchronization with just a few lines of code.Usage
This can be run on any JavaScript-based project (server or client). You would need the peaq-sdk to run it, please refer here for more information.subscribeToPtp(masterUrl, interval)
Parameters:-
masterUrl REQUIRED
<string>
: The URL of the master clock server, which is used to send requests for synchronization. This is defined as a constant in the code, which is currently https://ptp.peaq.xyz. This server is a central time source that fetches the timestamp from the network at regular block intervals using real-time updates and is responsible for synchronizing the clocks of connected systems to ensure accurate and consistent timekeeping. -
interval OPTIONAL
<number>
: Periodically synchronizes the clock at a fixed rate. Recorded in milliseconds, defaults to 1000.
Sample Output
Synchronization Result Details
The synchronization result contains two key properties:-
Offset:
- Description: This represents the calculated time difference between the local clock and the master clock.
- Purpose: The offset is used to adjust the local clock to align it with the master clock. A positive offset indicates that the local clock is behind the master clock, while a negative offset indicates it is ahead.
-
Synchronized Time:
- Description: This is the local time adjusted by the calculated offset, effectively representing the current time as per the master clock.
- Purpose: The synchronized time provides a corrected timestamp that can be used for time-sensitive operations, ensuring consistency with the master clock
Synchronization Process
The synchronization process involves the following steps:-
Sync Message:
- A request is sent to the master clock server.
- The server returns a timestamp, and the local timestamp is recorded immediately after receiving the response.
-
Delay Request:
- A local timestamp is recorded, and a request is sent to the master clock server.
- The server returns another timestamp.
-
Offset Calculation:
-
The offset is calculated using the formula:
offset = ((local timestamp after sync - server timestamp) - (local timestamp before delay - delay)) / 2
-
The synchronized time is calculated as:
synchronized time = local timestamp after sync + offset
-
The offset is calculated using the formula: