2

I created a smart contract (currently on ghostnet) with an on-chain view get_latest_hash which, once executed, returns a string, i.e. "test_hash_x"

I would like to query this get_latest_hash view from a web page, with a simple REST API call.

I'm looking for a stable public API (i.e. not better-call.dev, see below) that allows me to do the same thing. I looked through the tzkt.io API but could not find an obvious way to execute endpoints on smart contracts.

I also know I could use Taquito or ConseilJS, but that requires importing libraries, and I'm really looking to do a basic HTTP call (hence my need for a REST API).

I'm also trying to avoid reading directly from the smart contract's internal storage (i.e. using tzkt BigMaps API). The whole point of this exercise is to expose the data through a smart contract interface (the view).


A note regarding better-call.dev:

I am able to achieve this by replicating the HTTP call that better-call.dev uses from their web UI:

A POST to:

https://api.better-call.dev/v1/contract/ghostnet/KT1SHkHGQXhbW9dTU5Bm9PnmZg657oQ1NvG9/views/execute

with application/json payload:

{"name":"get_latest_hash","implementation":0,"data":{},"kind":"on-chain"}

works fine.

However this is not a public API, and better-call.dev are known for regularly updating their API which breaks external apps that use it.

1 Answer 1

2

Upon further research I found that the tzkt API does support executing views. It is documented under the Helpers section.

The syntax is as follows:

POST to /v1/helpers/view/{contract}/{name}

where {contract} is the contract address and {name} is the view name.

You may, optionally, include parameters as an application\json payload.

In my example, I didn't need any parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.