forked from hedera-dev/hedera-code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobtain.sh
executable file
·16 lines (10 loc) · 833 Bytes
/
obtain.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
TIMESTAMP=$(date -u -j -f "%F %T" "2023-05-10 08:27:52" "+%s")
echo "Timestamp : ${TIMESTAMP}"
curl -s "https://testnet.mirrornode.hedera.com/api/v1/blocks?limit=1&order=asc×tamp=gte:${TIMESTAMP}" | jq
BLOCKNUM=$( curl -s "https://testnet.mirrornode.hedera.com/api/v1/blocks?limit=1&order=asc×tamp=gte:${TIMESTAMP}" | jq ".blocks[].number" )
echo "Block number (decimal) : ${BLOCKNUM}"
curl -s "https://testnet.mirrornode.hedera.com/api/v1/blocks?limit=1&order=asc&block.number=eq:${BLOCKNUM}" | jq
BLOCKNUMHEX=$( printf "0x%x\n" ${BLOCKNUM} )
echo "Block number (hexadecimal): ${BLOCKNUMHEX}"
curl -s -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"2","method":"eth_getBlockByNumber","params":["'"${BLOCKNUMHEX}"'", false]}' http://localhost:7546 | jq ".result"