TzKT is a lightweight Tezos blockchain indexer with an advanced API created by the Baking Bad team with huge support from the Tezos Foundation.
The indexer fetches raw data from the Tezos node, then processes it and stores in the database in such a way as to provide effective access to the blockchain data. For example, getting operations by hash, or getting all operations of the particular account, or getting detailed baking rewards, etc. None of this can be accessed via node RPC, but TzKT indexer makes this data (and much more) available.
First of all, install git, make, docker, docker-compose, then run the following commands:
git clone https://github.com/baking-bad/tzkt.git
cd tzkt/
make init #run this command just once to init database from the latest snapshot
make start
curl http://127.0.0.1:5000/v1/head
make stop
This is the preferred way, because you have more control over each TzKT component (database, indexer, API). This guide is for Ubuntu 20.04, but if you are using a different OS, the installation process will probably differ only in the "Install packages" step.
sudo apt update
sudo apt install git
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update
sudo apt install -y apt-transport-https
sudo apt update
sudo apt install -y dotnet-sdk-5.0
wget -q -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt -y install postgresql-13 postgresql-client-13
sudo -u postgres psql
postgres=# create database tzkt_db;
postgres=# create user tzkt with encrypted password 'qwerty';
postgres=# grant all privileges on database tzkt_db to tzkt;
postgres=# \q
wget "https://tzkt-snapshots.s3.eu-central-1.amazonaws.com/tzkt_v1.5.2.backup" -O /tmp/tzkt_db.backup
// mainnet restoring takes ~10 min (of course, depending on hardware)
sudo -u postgres pg_restore -c --if-exists -v -d tzkt_db -1 /tmp/tzkt_db.backup
cd ~
git clone https://github.com/baking-bad/tzkt.git
cd ~/tzkt/Tzkt.Sync/
dotnet publish -o ~/tzkt-sync
Edit configuration file ~/tzkt-sync/appsettings.json with your favorite text editor. What you need is to specify Diagnostics (just disable it), TezosNode.ChainId, TezosNode.Endpoint and ConnectionStrings.DefaultConnection.
Like this:
{
"Protocols": {
"Diagnostics": false,
"Validation": true
},
"TezosNode": {
"ChainId": "NetXdQprcVkpaWU",
"Endpoint": "https://mainnet-tezos.giganode.io/",
"Timeout": 60
},
"Quotes": {
"Async": true,
"Provider": {
"Name": "TzktQuotes"
}
},
"ConnectionStrings": {
"DefaultConnection": "server=localhost;port=5432;database=tzkt_db;username=tzkt;password=qwerty;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
cd ~/tzkt-sync
dotnet Tzkt.Sync.dll
// info: Microsoft.Hosting.Lifetime[0]
// Application started. Press Ctrl+C to shut down.
// info: Microsoft.Hosting.Lifetime[0]
// Hosting environment: Production
// info: Microsoft.Hosting.Lifetime[0]
// Content root path: /home/tzkt/tzkt-sync
// warn: Tzkt.Sync.Services.Observer[0]
// Observer is started
// info: Tzkt.Sync.Services.Observer[0]
// Applied 776913
// info: Tzkt.Sync.Services.Observer[0]
// Applied 776914
// ....
That's it. If you want to run the indexer as a daemon, take a look at this guide: https://docs.microsoft.com/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-3.1#create-the-service-file.
Suppose you have already created database tzkt_db, database user tzkt and cloned Tzkt repo to ~/tzkt.
cd ~/tzkt/Tzkt.Api/
dotnet publish -o ~/tzkt-api
Edit configuration file ~/tzkt-api/appsettings.json with your favorite text editor. What you need is to specify ConnectionStrings.DefaultConnection, a connection string for the database created above.
Like this:
{
"Metadata": {
"AccountsPath": "*",
"ProposalsPath": "*",
"ProtocolsPath": "*"
},
"Websocket": {
"Enabled": true,
"MaxConnections": 100,
"MaxAccountSubscriptions": 10
},
"Cache": {
"LoadRate": 0.75,
"MaxAccounts": 32000
},
"ConnectionStrings": {
"DefaultConnection": "server=localhost;port=5432;database=tzkt_db;username=tzkt;password=qwerty;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
cd ~/tzkt-api
dotnet Tzkt.Api.dll
// info: Tzkt.Api.Services.Metadata.AccountMetadataService[0]
// Accounts metadata not found
// info: Tzkt.Api.Services.Sync.SyncWorker[0]
// Sync worker initialized with level 776917 and blocks time 60s
// info: Tzkt.Api.Services.Sync.SyncWorker[0]
// Syncronization started
// info: Microsoft.Hosting.Lifetime[0]
// Now listening on: http://localhost:5000
// info: Microsoft.Hosting.Lifetime[0]
// Now listening on: https://localhost:5001
// info: Microsoft.Hosting.Lifetime[0]
// Application started. Press Ctrl+C to shut down.
// info: Microsoft.Hosting.Lifetime[0]
// Hosting environment: Production
// info: Microsoft.Hosting.Lifetime[0]
// Content root path: /home/tzkt/tzkt-api
// ....
That's it. By default API is available on ports 5000 (HTTP) and 5001 (HTTPS). If you want to use HTTPS, you also need to configure certificates. If you want to run API on a different port, add the "Kestrel" section to the appsettings.json (see example below).
In general the steps are the same as for the mainnet, you just need to use different database, different snapshot and different appsettings (chain id and RPC endpoint). Here are some presets for testnets:
Anyway, let's do it, for reference, from scratch for the florencenet.
sudo -u postgres psql
postgres=# create database flor_tzkt_db;
postgres=# create user tzkt with encrypted password 'qwerty';
postgres=# grant all privileges on database flor_tzkt_db to tzkt;
postgres=# \q
wget "https://tzkt-snapshots.s3.eu-central-1.amazonaws.com/flor_tzkt_v1.5.1.backup" -O /tmp/flor_tzkt_db.backup
// florencenet restoring takes ~1 min
sudo -u postgres pg_restore -c --if-exists -v -d flor_tzkt_db -1 /tmp/flor_tzkt_db.backup
cd ~
git clone https://github.com/baking-bad/tzkt.git
cd ~/tzkt/Tzkt.Sync/
dotnet publish -o ~/flor-tzkt-sync
Edit configuration file ~/flor-tzkt-sync/appsettings.json with your favorite text editor. What you need is to specify Diagnostics (just disable it), TezosNode.ChainId, TezosNode.Endpoint and ConnectionStrings.DefaultConnection.
Like this:
{
"Protocols": {
"Diagnostics": false,
"Validation": true
},
"TezosNode": {
"ChainId": "NetXxkAx4woPLyu",
"Endpoint": "https://rpc.tzkt.io/florencenobanet/",
"Timeout": 30
},
"Quotes": {
"Async": true,
"Provider": null
},
"ConnectionStrings": {
"DefaultConnection": "server=localhost;port=5432;database=flor_tzkt_db;username=tzkt;password=qwerty;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
cd ~/flor-tzkt-sync
dotnet Tzkt.Sync.dll
// info: Microsoft.Hosting.Lifetime[0]
// Application started. Press Ctrl+C to shut down.
// info: Microsoft.Hosting.Lifetime[0]
// Hosting environment: Production
// info: Microsoft.Hosting.Lifetime[0]
// Content root path: /home/tzkt/flor-tzkt-sync
// warn: Tzkt.Sync.Services.Observer[0]
// Observer is started
// info: Tzkt.Sync.Services.Observer[0]
// Applied 125790
// info: Tzkt.Sync.Services.Observer[0]
// Applied 125791
// ....
That's it. If you want to run the indexer as a daemon, take a look at this guide: https://docs.microsoft.com/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-3.1#create-the-service-file.
Suppose you have already created database flor_tzkt_db, database user tzkt and cloned Tzkt repo to ~/tzkt.
cd ~/tzkt/Tzkt.Api/
dotnet publish -o ~/flor-tzkt-api
Edit configuration file ~/flor-tzkt-api/appsettings.json with your favorite text editor. What you need is to specify ConnectionStrings.DefaultConnection, a connection string for the database created above.
By default API is available on ports 5000 (HTTP) and 5001 (HTTPS). If you want to use HTTPS, you also need to configure certificates.
If you want to run API on a different port, add the "Kestrel" section to the appsettings.json.
Like this:
{
"Metadata": {
"AccountsPath": "*",
"ProposalsPath": "*",
"ProtocolsPath": "*"
},
"Cache": {
"LoadRate": 0.75,
"MaxAccounts": 32000
},
"Websocket": {
"Enabled": true,
"MaxConnections": 100,
"MaxAccountSubscriptions": 10
},
"ConnectionStrings": {
"DefaultConnection": "server=localhost;port=5432;database=flor_tzkt_db;username=tzkt;password=qwerty;"
},
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://localhost:5010"
}
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
cd ~/flor-tzkt-api
dotnet Tzkt.Api.dll
// info: Tzkt.Api.Services.Metadata.AccountMetadataService[0]
// Accounts metadata not found
// info: Tzkt.Api.Services.Sync.SyncWorker[0]
// Sync worker initialized with level 205804 and blocks time 30s
// info: Tzkt.Api.Services.Sync.SyncWorker[0]
// Syncronization started
// info: Microsoft.Hosting.Lifetime[0]
// Now listening on: http://localhost:5020
// info: Microsoft.Hosting.Lifetime[0]
// Now listening on: https://localhost:5021
// info: Microsoft.Hosting.Lifetime[0]
// Application started. Press Ctrl+C to shut down.
// info: Microsoft.Hosting.Lifetime[0]
// Hosting environment: Production
// info: Microsoft.Hosting.Lifetime[0]
// Content root path: /home/tzkt/flor-tzkt-api
// ....
That's it.
Feel free to contact us via:
Cheers! 🍺
Content type
Image
Digest
Size
6.8 GB
Last updated
about 5 years ago
docker pull bakingbad/tzkt-snapshot