Skip to content

Instantly share code, notes, and snippets.

@technoY2K
Last active February 4, 2022 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technoY2K/faba429e13c69672e035637737fdf116 to your computer and use it in GitHub Desktop.
Save technoY2K/faba429e13c69672e035637737fdf116 to your computer and use it in GitHub Desktop.
An example of using the blockfrost API.
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