Monitoring API Reference
The below reference informs you on what features are available in our Schema in order to enable you to write optimal DedaubQL.
Functions:
block_timestamp
<network>.block_timestamp(block_number bigint)
Returns the timestamp of a block.
Example Usage:
select ethereum.block_timestamp(1)
| BLOCK_TIMESTAMP |
|---|
| 2015-07-30T15:26:28+00:00 |
get_storage
<network>.get_storage(address text, position text)
Returns the hex representation of the value stored at a specific storage slot of a contract at the latest block.
Example Usage:
select * from ethereum.get_storage('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0') s
| s |
|---|
| 0x577261707065642045746865720000000000000000000000000000000000001a |
get_chain_id
<network>.get_chain_id()
Returns the chain id of the current network.
Example Usage:
select ethereum.get_chain_id()
| GET_CHAIN_ID |
|---|
| 1 |
Note: This was run with Ethereum selected
get_historical_block_number(bigint interval timestamp with time zone)
<network>.get_historical_block_number(start bigint, inter interval, _now timestamp with time zone default now()) returns bigint
Returns the block number given an interval of time in the past and the start block.
Example Usage:
select ethereum.get_historical_block_number(1700000, interval '1 days')
| GET_HISTORICAL_BLOCK_NUMBER |
|---|
| 1692846 |
get_historical_block_number(interval timestamp with time zone)
<network>.get_historical_block_number(inter interval, _now timestamp with time zone default now()) returns bigint
Returns the block number given an interval of time in the past.
Example Usage:
select ethereum.get_historical_block_number(interval '1 day')
| GET_HISTORICAL_BLOCK_NUMBER |
|---|
| 18534695 |
get_schema_name
<network>.get_schema_name() returns character varying
Returns the currently used blockchain network for monitoring.
Example Usage:
select ethereum.get_schema_name()
| GET_SCHEMA_NAME |
|---|
| ethereum |
last_block_number
<network>.last_block_number() returns bigint
Returns the last block number in the network.
Example Usage:
select ethereum.last_block_number()
| LAST_BLOCK_NUMBER |
|---|
| 18534695 |
safe_block_timestamp
<network>.safe_block_timestamp(block_num bigint) returns bigint
Returns the unix timestamp of a block.
Example Usage:
select ethereum.safe_block_timestamp(1)
| SAFE_BLOCK_TIMESTAMP |
|---|
| 1438269988 |
to_usd_value
<network>.to_usd_value(amount numeric, token_address bytea) returns numeric
Returns the USD value of an amount of token.
Example Usage:
select ethereum.to_usd_value(1e18, '\x6b175474e89094c44da98b954eedeac495271d0f')
| TO_USD_VALUE |
|---|
| 1 |
tx_hash
<network>.tx_hash(block_number bigint, tx_index integer) returns bytea
Returns the transaction hash given a block number and transaction index.
Example Usage:
select ethereum.tx_hash(1500000, 0)
| TX_HASH |
|---|
| be03790872e51ef0ffe1b5d741bdaa09b4e158a579f721da0725ace53b55b87f |
address_to_bytea
address_to_bytea(address varchar) returns common.ethaddress
Transforms an eth address represented as text to an equivalent byte array.
Example Usage:
select address_to_bytea('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
| address_to_bytea |
|---|
| 0xD8DA6BF26964AF9D7EED9E03E53415D37AA96045 |
address_to_varchar
address_to_varchar(address common.ethaddress) returns varchar
Transforms an eth address represented as a byte array to an equivalent varchar address.
Example Usage:
select address_to_varchar('\xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
| address_to_varchar |
|---|
| 0xd8da6bf26964af9d7eed9e03e53415d37aa96045 |
RPC fetch functions
You can send HTTP GET, POST or PUT requests to a remote REST service.
These limits apply to http_get, http_get_json, http_get_json_array, http_post and http_put:
- Only public addresses. The URL must use
httporhttps. A host that resolves to a private, loopback, link-local or other internal address is refused, as are names such aslocalhost. - No redirects. A
3xxresponse is an error, not followed. Use the final URL. - 10 seconds. The whole request, including the DNS lookup, must finish in 10 seconds.
- 10 MiB. A response body larger than 10 MiB (after decompression) is an error.
- Public DNS only. The host is resolved through DNS. A name that is defined only in
/etc/hostsdoes not resolve.
http_get
http_get(url text, params jsonb DEFAULT NULL::jsonb, headers jsonb DEFAULT NULL::jsonb) returns varchar
It will send an HTTP GET request. The result will be a varchar that can be further processed
Example Usage:
SELECT http_get(
url=>'https://api.geckoterminal.com/api/v2/tokens/info_recently_updated',
params=>'{"include":"network","network":"eth"}',
headers=>'{"Content-Type": "application/json"}');
| http_get |
|---|
{"data":[{"id":"solana_5Nu2hLo3ffU4fs2yVtsCvAT7ymysuYs5NSFRpvLMVSBi"...}]} |
http_get_json
http_get_json(url text, params jsonb DEFAULT NULL::jsonb, headers jsonb DEFAULT NULL::jsonb) returns jsonb
It will send an HTTP GET request. It assumes that the response to the GET request is a json string
Example Usage:
SELECT http_get_json(
url=>'https://api.geckoterminal.com/api/v2/tokens/info_recently_updated',
params=>'{"include":"network","network":"eth"}',
headers=>'{"Content-Type": "application/json"}');
| http_get_json |
|---|
{"data":[{"id":"solana_5Nu2hLo3ffU4fs2yVtsCvAT7ymysuYs5NSFRpvLMVSBi"... |
http_get_json_array
http_get_json_array(url text, params jsonb DEFAULT NULL::jsonb, headers jsonb DEFAULT NULL::jsonb) returns setof jsonb
It will send an HTTP GET request. It assumes that the response to the request is a json array
Example Usage:
SELECT common.http_get_json_array('https://api.dedaub.com/api/contracts/ethereum/trending');
| http_get_json_array |
|---|
{"name": "Wrapped Ether", "nonce": 0, "address": ... |
{"name": "Tether USD", "nonce": 0, "address": ... |
{"name": "FiatTokenV2_2", "nonce": 0, "address": ... |