GithubHelp home page GithubHelp logo

bens / hs-web3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from airalab/hs-web3

0.0 1.0 0.0 1.92 MB

Web3 API for Haskell.

Home Page: http://hackage.haskell.org/package/web3

License: Apache License 2.0

Haskell 73.74% C 26.26%

hs-web3's Introduction

Web3 API for Haskell

This library implements Haskell API client for popular Web3 platforms.

Documentation Status CI Hackage Matrix Hackage LTS-14 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

hs-web3's People

Contributors

akru avatar aupiff avatar amany9000 avatar martyall avatar iostat avatar proofofkeags avatar alexfmpe avatar benweitzman avatar charlescrain avatar kejace avatar aherrmann avatar bens avatar gromakovsky avatar ivanovs-4 avatar proger avatar enolan avatar hvr avatar zhangchiqing avatar o1lo01ol1o avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.