How to query all transaction using stacks-blockchain-api?

Hi all. I want to make stacks 2.0 environment for local development. So I have built stacks-node(GitHub - blockstack/stacks-blockchain: The Stacks 2.0 blockchain implementation) and started node connecting the mainnet. And I’m trying to connect the node using stacks-blockchain-api(GitHub - blockstack/stacks-blockchain-api: API for the Stacks 2.0 blockchain)

But I found the problem using Stacks Blockchain API.

Following this:

curl http://192.168.56.114:3999/extended/v1/block
{"limit":20,"offset":0,"total":0,"results":[]}
curl http://localhost:3999/extended/v1/tx
{"limit":96,"offset":0,"total":0,"results":[]}

Command for executing the API server:

cd stacks-blockchain-api
npm install
./node_modules/.bin/ts-node src/index.ts

API Server Log:

{"message":"Event observer listening at: http://127.0.0.1:3700","level":"info","timestamp":"2021-04-15T00:07:51.300Z"}
{"message":"/v2/* proxying to: 0.0.0.0:20443","level":"info","timestamp":"2021-04-15T00:07:51.749Z"}
[HPM] Proxy created: /  -> http://0.0.0.0:20443
{"message":"API server listening on: http://0.0.0.0:3999","level":"info","timestamp":"2021-04-15T00:07:51.779Z"}
{"message":"@promster/server started on port 9153.","level":"info","timestamp":"2021-04-15T00:07:51.780Z"}
{"message":"App initialized","level":"info","timestamp":"2021-04-15T00:07:51.780Z"}
{"message":"Connection to Stacks core node API server at: 0.0.0.0:20443","level":"info","timestamp":"2021-04-15T00:07:51.912Z"}
{"message":"Event observer listening at: http://127.0.0.1:3700","level":"info","timestamp":"2021-04-15T00:26:50.914Z"}
{"message":"/v2/* proxying to: 0.0.0.0:20443","level":"info","timestamp":"2021-04-15T00:26:51.246Z"}
[HPM] Proxy created: /  -> http://0.0.0.0:20443
{"message":"API server listening on: http://0.0.0.0:3999","level":"info","timestamp":"2021-04-15T00:26:51.271Z"}
{"message":"@promster/server started on port 9153.","level":"info","timestamp":"2021-04-15T00:26:51.271Z"}
{"message":"App initialized","level":"info","timestamp":"2021-04-15T00:26:51.271Z"}
{"message":"Connection to Stacks core node API server at: 0.0.0.0:20443","level":"info","timestamp":"2021-04-15T00:26:51.380Z"}
{"req":{"url":"/extended/v1/block","headers":{"user-agent":"curl/7.29.0","host":"192.168.56.114:3999","accept":"*/*"},"method":"GET","httpVersion":"1.1","originalUrl":"/extended/v1/block","query":{}},"res":{"statusCode":200},"responseTime":29,"level":"info","message":"HTTP GET /extended/v1/block","timestamp":"2021-04-15T00:59:34.026Z"}
{"req":{"url":"/extended/v1/tx","headers":{"user-agent":"curl/7.29.0","host":"localhost:3999","accept":"*/*"},"method":"GET","httpVersion":"1.1","originalUrl":"/extended/v1/tx","query":{}},"res":{"statusCode":200},"responseTime":25,"level":"info","message":"HTTP GET /extended/v1/tx","timestamp":"2021-04-15T01:00:08.659Z"}
{"req":{"url":"/extended/v1/block/by_height/123","headers":{"user-agent":"curl/7.29.0","host":"localhost:3999","accept":"*/*"},"method":"GET","httpVersion":"1.1","originalUrl":"/extended/v1/block/by_height/123","query":{}},"res":{"statusCode":404},"responseTime":6,"level":"info","message":"HTTP GET /extended/v1/block/by_height/123","timestamp":"2021-04-15T01:03:53.429Z"}
{"req":{"url":"/extended/v1/block/0xbc2a4a75cf7e508d683481a7b952c5e52bda2c6a4096210da1fcc7d81ee15e5c","headers":{"user-agent":"curl/7.29.0","host":"localhost:3999","accept":"*/*"},"method":"GET","httpVersion":"1.1","originalUrl":"/extended/v1/block/0xbc2a4a75cf7e508d683481a7b952c5e52bda2c6a4096210da1fcc7d81ee15e5c","query":{}},"res":{"statusCode":404},"responseTime":3,"level":"info","message":"HTTP GET /extended/v1/block/0xbc2a4a75cf7e508d683481a7b952c5e52bda2c6a4096210da1fcc7d81ee15e5c","timestamp":"2021-04-15T01:04:03.241Z"}

I think my API Server(stacks-blockchain-api) cannot find any transaction data although running node well. I want to query all block & transaction data. Please let me know how to resolve the problem. Thanks.

The reason why is that the API service requires a DB backend to store the records for quicker querying.

You can query the blockchain directly, but it will be slower and the queries will be a bit harder to craft (you could also query the sqlite db directly if you have local access).

If you’re interested in running a mainnet node with the API, take a look here: GitHub - blockstack/stacks-local-dev at mainnet

This will help you get a follower, api, and the postgres DB up and running quickly with docker-compose. be sure to look at the README first though!

You can also replicate what that repo is doing locally without docker-compose - basically it only requires you to run postgres, and then you have to set the env vars for the API to access postgres.

1 Like