Last active
February 4, 2022 02:34
-
-
Save technoY2K/faba429e13c69672e035637737fdf116 to your computer and use it in GitHub Desktop.
An example of using the blockfrost API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
import Blockfrost.Client | |
import qualified Data.Text as T | |
main :: IO () | |
main = do | |
project <- projectFromFile ".env" | |
result <- runBlockfrost project $ do | |
latestBlocks <- getLatestBlock | |
errors <- tryError $ getAccountRewards "Failed" | |
pure (latestBlocks, errors) | |
case result of | |
Left bfe -> print $ handleError bfe | |
Right (b, _) -> print $ _blockSlotLeader b | |
handleError :: BlockfrostError -> T.Text | |
handleError b = case b of | |
BlockfrostError t -> t | |
BlockfrostBadRequest t -> t | |
BlockfrostTokenMissing t -> t | |
BlockfrostFatal t -> t | |
BlockfrostNotFound -> "Not found" | |
BlockfrostIPBanned -> "IP Banned" | |
BlockfrostUsageLimitReached -> "Limit Reached" | |
_ -> "Client error" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment