https://github.com/airalab/hs-web3
Web3 API for Haskell
https://github.com/airalab/hs-web3
ethereum haskell ipfs kusama polkadot web3
Last synced: 18 days ago
JSON representation
Web3 API for Haskell
- Host: GitHub
- URL: https://github.com/airalab/hs-web3
- Owner: airalab
- License: apache-2.0
- Created: 2016-10-03T13:56:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-03T12:55:15.000Z (7 months ago)
- Last Synced: 2024-10-09T00:58:25.761Z (7 months ago)
- Topics: ethereum, haskell, ipfs, kusama, polkadot, web3
- Language: Haskell
- Homepage: http://hackage.haskell.org/package/web3
- Size: 1.7 MB
- Stars: 189
- Watchers: 12
- Forks: 68
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: docs/contributing.rst
- License: LICENSE
Awesome Lists containing this project
README
Web3 API for Haskell
====================This library implements Haskell API client for popular Web3 platforms.
[](https://hs-web3.readthedocs.io/en/latest/?badge=latest)
[](https://github.com/airalab/hs-web3/actions)
[](http://hackage.haskell.org/package/web3)
[](http://stackage.org/lts-22/package/web3)
[](http://stackage.org/nightly/package/web3)
[](https://www.codetriage.com/airalab/hs-web3)Install
-------`stack install web3`
Usage
-----```haskell
{-# 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](https://hs-web3.readthedocs.io).
License
-------* `Network.Polkadot` and `Codec.Scale` is licensed under [Apache 2.0](https://github.com/airalab/hs-web3/blob/master/LICENSE-APACHE2)
* All other source is licensed under [BSD-3-Clause](https://github.com/airalab/hs-web3/blob/master/LICENSE-BSD3)