Important
Since the launch of Kaia Blockchain, this repository has been parked in favour of the new open-source projects in Kaia's Github. Contributors have now moved there continuing with massive open-source contributions to our blockchain ecosystem. A big thank you to everyone who has contributed to this repository.
For future development and contributions, please refer to the new tx-latency-measurement repository
More information about Klaytn's chain merge with Finschia blockchain, please refer to the launching of Kaia blockchain kaia.io.
Using this repo, you can measure transaction latency on differenct blockchain platforms(ex: Solana mainnet-beta, Avalanche C-chain, Polygon PoS, and Klaytn). Transaction latency is measured by sending a simple value transfer transaction through public RPC url provided by each chain. Each subdirectory is for each different blockchain platform. Codes for other chains will be updated.
This project uses NodeJS v16.14.2.
- Open terminal
- Clone the repo by running
https://github.com/klaytn/tx-latency-measurement.git
cd tx-latency-measurement/{BlockchainName}-tx-latency-measurement
by selecting which blockchain you want to measure.- Run
npm install
to install node packages. - Copy and paste
.env.template
file. Then rename it to.env
and update variables with your Private key, url of blockchain explorer, and public rpc url. You should also decide whether to upload to GCS/S3, and provide appropriate credentials. - Run
node sendtx_{BlockchainName}.js
.
- Open terminal
- Clone the repo by running
https://github.com/klaytn/tx-latency-measurement.git
- Run
npm install
to install node packages.
cd tx-latency-measurement/klaytn-tx-latency-measurement
npm install
- Copy and paste
.env.template
file. Then rename it to.env
.
cp .env.template .env
- Update
.env
and make sure PRIVATE_KEY and S3_BUCKET is empty as below:
PRIVATE_KEY=
CAVER_URL=https://public-node-api.klaytnapi.com/v1/baobab
S3_BUCKET=
- Run
node sendtx_klaytn.js
. Then the output will give you new Private Key and Address.
starting tx latency measurement... start time = 1661338618926
Private key is not defined. Use this new private key({NEW_PRIVATE_KEY}).
Get test KLAY from the faucet: https://baobab.wallet.klaytn.foundation/faucet
Your Klaytn address = {NEW_ADDRESS}
- With
NEW_ADDRESS
, get test KLAY from faucet page. - Update PRIVATE_KEY in .env file with this
NEW_PRIVATE_KEY
.
- Run
node sendtx_klaytn.js
. You can see the result as below:
starting tx latency measurement... start time = 1661339036754
failed to s3.upload! Printing instead! undefined bucket name
{"executedAt":1661339056756,"txhash":"0x78273bf3015cffc003b09908b322562eda5d830b455ae1c80b7a090d3b60a43b","startTime":1661339057100,"endTime":1661339059192,"chainId":1001,"latency":2092,"error":"","txFee":0.00105,"txFeeInUSD":0.00026812274999999996,"resourceUsedOfLatestBlock":38800,"numOfTxInLatestBlock":1,"pingTime":24}
-
Install Docker https://docs.docker.com/install/
-
Build a docker image in a folder you would like to measure.
> docker build -t klaytn-tx-latency-measurement:latest .
-
Run a container out of the image
> docker run klaytn-tx-latency-measurement:latest
Note: You need to provide credentials JSON inside a directory if you wish to upload to GCS
(unchecked: to be updated)
- Klaytn
- Polygon PoS
- Avalanche C-chain
- Solana
- Near Protocol
- EOS
- Fantom
- Polkadot
- Cosmos
- BNB
- Hedera
- Elrond
- Harmony
- Please find out ways to collect data like other chains in this repo. You might be able to use javascript sdk for other chains.
- What should be included in your code
- Use same structure(ex: sendtx_klaytn.js & .env.template) and functions(ex: uploadToS3, uploadToGCS, uploadChoice, makeParquetFile, loadConfig, sendSlackMsg in sendtx_klaytn.js)
- In sendTx function, check if balance of the account is enough to send transaction and set
chainId
. - Measure pingtime using simple rpc api (like getBlockNumber())
- Measure
resourceUsedOfLatestBlock
&numOfTxInLatestBlock
from the latest block info. - Configure the transaction and sign it with private key.
- Measure the time it took for the signed transaction to be confirmed and receive a receipt. Enter the
txHash
,start time
,end time
, andlatency
(time in between) into the data. - Calculate
txFeeInUSD
using CoinGecko API, then recordtxFee
(in Native Coin) andtxFeeInUSD
into data. - If an error occurs, write the
error
to the data.
- Open a new pull request and write which info you collect for data (ex: total gas used in the latest block for
resourceUsedOfLatestBlock
) - Set
@Yeonju-Kim
as a reviewer.