Web3 API for Haskell.
Go to file
2024-10-03 15:55:11 +03:00
.github/workflows [CI] update actions 2024-10-03 15:21:44 +03:00
docs docs: added polkadot extrinsic section 2021-08-11 08:45:15 +03:00
examples Update to latest LTS, change pkg names a bit 2022-01-25 11:57:39 +03:00
packages Uplift to lts-22.27 2024-10-03 15:46:28 +03:00
.ghci Added ABI parser; Added Filter creator from Event defs 2016-10-04 11:56:22 +03:00
.gitignore Added .cabal files to repo (#123) 2022-02-11 08:24:47 +09:00
.stylish_haskell.yaml Update package meta 2020-05-23 10:05:13 +03:00
CHANGELOG.md Update dependencies, bump version 2024-10-03 15:17:23 +03:00
LICENSE Bump license to 2021 2021-02-13 04:21:49 +03:00
README.md [README] Drop hackage matrix badge (obsolete) 2024-10-03 15:55:11 +03:00
stack.yaml Uplift to lts-22.27 2024-10-03 15:46:28 +03:00

Web3 API for Haskell

This library implements Haskell API client for popular Web3 platforms.

Documentation Status CI Hackage LTS-22 nightly Code Triagers

Install

stack install web3

Usage

{-# LANGUAGE OverloadedStrings #-}

module Main where

-- Basic imports
import           Network.Ethereum
import           Network.Web3

-- Eth API support
import qualified Network.Ethereum.Api.Eth   as Eth
import           Network.Ethereum.Api.Types

-- ENS support
import qualified Network.Ethereum.Ens       as Ens

-- Lens to simple param setting
import           Lens.Micro                 ((.~))

main :: IO ()
main = do
    -- Use default provider on http://localhost:8545
    ret <- runWeb3 $ do

        -- Get address of default account
        me <- head <$> Eth.accounts

        -- Get balance of default account on latest block
        myBalance <- Eth.getBalance me Latest

        -- Get half of balance
        let halfBalance = fromWei (myBalance / 2)

        -- Use default account
        withAccount () $ do
            -- Get Ethereum address via ENS
            alice <- Ens.resolve "alice.address.on.eth"
            bob   <- Ens.resolve "bob.address.on.eth"

            -- Send transaction with value
            withParam (value .~ halfBalance) $ do

                -- Send transaction to alice account
                withParam (to .~ alice) $ send ()

                -- Send transaction to bob account
                withParam (to .~ bob) $ send ()

        -- Return sended value
        return halfBalance

    -- Web3 error handling
    case ret of
        Left e  -> error $ show e
        Right v -> print (v :: Ether)  -- Print returned value in ethers

Read more in the documentation on ReadTheDocs.

License

  • Network.Polkadot and Codec.Scale is licensed under Apache 2.0
  • All other source is licensed under BSD-3-Clause