Monitoring API Reference
The below reference informs you on what features are available in our Schema in order to enable you to write optimal TSQL.
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.
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": ... |
http_post
http_post(url text, params jsonb DEFAULT NULL::jsonb, headers JSONB DEFAULT NULL::jsonb, body jsonb DEFAULT NULL::jsonb) returns varchar
It will send an HTTP POST request. It returns a varchar representing the response
Example Usage:
SELECT http_post(
url=>'https://docs-demo.quiknode.pro',
body=>'{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}'::jsonb,
headers=>'{"Content-Type": "application/json"}'::jsonb);
http_post |
---|
{"jsonrpc":"2.0","id":1,"result":"0x1"} |
http_put
http_put(url text, params jsonb DEFAULT NULL::jsonb, headers JSONB DEFAULT NULL::jsonb, body jsonb DEFAULT NULL::jsonb) returns varchar
It will send an HTTP PUT request. It returns a varchar representing the response
Example Usage:
SELECT http_put(
'https://jsonplaceholder.typicode.com/posts/1',
body=>'{"id": 1, "title": "foo", "body": "bar", "userId": 1}',
headers=>'{"Content-Type": "application/json; charset=UTF-8"}');
http_put |
---|
{"id": 1, "body": "bar","title": "foo","userId": 1} |
Gadgets:
block
{{ <network>.block(duration: Optional['5m', '1h', '24h', '3d'] = '24h', start_time: Optional['YYYY-MM-DDTHH:MM:SS'] = 'now()') }}
Returns an interval of blocks from block.
Example Usage:
select block_number from {{ ethereum.block(duration='5m') }} _
BLOCK_NUMBER |
---|
18542144 |
18542145 |
18542146 |
18542147 |
... |
contracts
{{ <network>.contracts(protocols: Optional[list[str]] = None) }}
Returns a list of contracts from contracts.
Example Usage:
select address from {{ ethereum.contracts(protocols=['Maker']) }} _
ADDRESS |
---|
004b750a71f1aa80150b18ecd510e6abf7e25480 |
00efe35880071c16832b3ad135885e7746adf889 |
010df1cd88f927c8a77f39265c3eac634ec072c0 |
... |
contract_list
{{ contract_list(name:str, owner: str = query_creator) }}
Returns a contracts present in a contract list with the same name and owner. If no owner is provided, it defaults to the user creating the query.