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 if you want to restore the DB 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.s3.eu-central-1.amazonaws.com/snapshots/tzkt_v1.6_mainnet.backup" -O /tmp/tzkt_db.backup
// full mainnet restoring takes ~30 min (depending on hardware)
sudo -u postgres pg_restore -c --if-exists -v -d tzkt_db -1 /tmp/tzkt_db.backup
// for Docker use you may need to add "-U tzkt", like this
sudo -u postgres pg_restore -c --if-exists -v -d tzkt_db -U tzkt -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 TezosNode.Endpoint and ConnectionStrings.DefaultConnection.
Like this:
{
"Protocols": {
"Diagnostics": false,
"Validation": true
},
"TezosNode": {
"Endpoint": "https://mainnet-tezos.giganode.io/",
"Timeout": 60
},
"Quotes": {
"Async": true,
"Provider": {
"Name": "TzktQuotes"
}
},
"ConnectionStrings": {
"DefaultConnection": "host=localhost;port=5432;database=tzkt_db;username=tzkt;password=qwerty;"
},
"HealthChecks": {
"Enabled": true,
"Delay": 10,
"Period": 10,
"FilePath": "sync.health"
},
"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:
{
"Cache": {
"LoadRate": 0.75,
"MaxAccounts": 32000
},
"Websocket": {
"Enabled": true,
"MaxConnections": 1000,
"MaxOperationSubscriptions": 50,
"MaxBigMapSubscriptions": 50,
"MaxAccountsSubscriptions": 50
},
"ConnectionStrings": {
"DefaultConnection": "host=localhost;port=5432;database=tzkt_db;username=tzkt;password=qwerty;"
},
"Home": {
"Enabled": false,
"UpdatePeriod": 30
},
"HealthChecks": {
"Enabled": true,
"Endpoint": "/health"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
}
}
},
"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 (RPC endpoint). Here are some presets for testnets:
Feel free to contact us via:
Cheers! 🍺
Content type
Image
Digest
Size
87.3 MB
Last updated
over 4 years ago
docker pull demonmir/tzkt-api-test