Skip to content

Instantly share code, notes, and snippets.

@joefiorini joefiorini/Main.hs
Last active Dec 18, 2017

Embed
What would you like to do?
[
{
"constant": true,
"inputs": [],
"name": "greeting",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "greet",
"outputs": [
{
"name": "_greeting",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "_greeting",
"type": "string"
}
],
"name": "GreetingChanged",
"type": "event"
},
{
"constant": false,
"inputs": [
{
"name": "_greeting",
"type": "string"
}
],
"name": "setGreeting",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"name": "_greeting",
"type": "string"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}
]
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
import Network.Ethereum.Web3
import Network.Ethereum.Web3.TH
import System.Environment (getEnv)
import Control.Monad.IO.Class (liftIO)
import Data.Text (unpack)
import Data.String (fromString)
import Text.Printf
[abiFrom|data/greeting.json|]
getInfo :: Address -> Web3 DefaultProvider Text
getInfo addr = do
liftIO . (putStr "Name: " >>) . print =<< greet addr
return ""
-- nameStr <- name addr
-- return nameStr
main :: IO ()
main = do
address <- fromString <$> getEnv "ADDRESS"
market <- runWeb3' (getInfo address)
case market of
Left e -> do
putStrLn "Unable to get info"
print e
Right name -> do
putStrLn "Got name:"
print name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.