FOAM Developer stack

An overview of the high quality, fully general purpose open-source libraries developed by the FOAM team.

At FOAM we strive to release high quality, fully general purpose open-source libraries for the general Ethereum community to use. They grow out of our efforts of building the functional stack to support the smart contracts and functionality of the Spatial Index. So FOAM has spent the last year and a half developing a unique suite of developer tools that will ultimately lead to a fraud-proof and privacy-preserving Proof of Location protocol for Ethereum. Much of our stack is written in the functional programming languages Haskell and PureScript. As a result we have had to develop viable alternatives and rework common Etheruem solutions like web3.js and truffle. There are some obvious benefits to using functional programming for Ethereum; composability, strong type-level programming, and compile-time guarantees (which are especially important when dealing with potentially large assets).

FOAM has spent the last year and a half developing a unique suite of developer tools that will ultimately lead to a fraud-proof and privacy-preserving Proof of Location protocol for Ethereum.

Out of this came:

Chanterelle , a purely functional smart contract manager and build tool;

, a purely functional smart contract manager and build tool; purescript-web3 library, to write front-end dApps in purescript

library, to write front-end dApps in purescript hs-web3 library, we’ve made significant additions and are now maintaining our own fork of this library

library, we’ve made significant additions and are now maintaining our own fork of this library cliquebait, a fast standalone blockchain docker-image with pre-allocated ether

Standalone examples of usage our libraries can be found in:

hethcon , an example of how to build a completely general event processor that persists smart contract state-changes to postgres and other databases. The rich haskell ecosystem automatically leverages a REST-API and a graphql layer for querying the data. We wrote this in a weekend for the ethdenver hackathon for which we won the 0x price

, an example of how to build a completely general event processor that persists smart contract state-changes to postgres and other databases. The rich haskell ecosystem automatically leverages a REST-API and a graphql layer for querying the data. We wrote this in a weekend for the ethdenver hackathon for which we won the 0x price purescript-kitty-monitor , an example app demonstrating how to use purescript-web3 together with the purescript frontend library thermite

, an example app demonstrating how to use purescript-web3 together with the purescript frontend library thermite chanterelle-halogen-template, an evolution of the above, demonstrating purescript-web3 together with halogen, a more contemporary purescript frontend library

The stack we develop for the Spatial Index is heavily used as an event processor and server that repopulates the user interface with real time information from the Ethereum blockchain.

Spatial Index

The Spatial Index is the front-end user interface that allows for browser-based interaction with spatially-aware smart contracts. Through the Mapbox API, the Spatial Index uses Uber’s WebGL map visualization library called deck.gl, which allows for enhanced layering and rendering functionality. The functionality of the app is written in PureScript — assisted by our purescript-web3 library — and allows users to add Points of Interests (POIs), challenge the validity of points, signal demand for future mining rewards and contribute to the community-lead growth of the Proof of Location protocol. Application users can filter POIs depending on categories by layering and can also search the history of interactions between the map and the blockchain. Users can deploy Cryptospatial Coordinates as smart contracts directly using Metamask.

Smart Contracts

The kernel of all of our software is comprised of FOAM’s Smart Contracts, which are written in Solidity and act as a source of truth for the application itself. Chanterelle manages smart contracts, but provides a few key improvements over its non-functional counterpart Truffle. For one, Chanterelle offers vastly improved error-handling because a build’s control flow can be easily managed and allows developers to pinpoint where exactly the code failed. Also, Chanterelle brings the concept of modules to Solidity projects, and as a result enforces a consistent way of organizing code. Traditionally, the web.js + truffle stack uses testrpc as an Ethereum client substitute, but testrpc is often a mismatch with the latest solidity compiler. More sensibly, Chanterelle can use our cliquebait solution to faithfully mimic a geth or parity node. It is highly configurable, allowing for library injection, preallocating account balances, as well as any other production node configuration options.

Chanterelle ultimately produces a directory of build artifacts that contains ABIs and documentation that are compatible with truffle.

Back-end Indexer and Database

An indexer serializes the data emitted by the Spatial Index contracts as Ethereum logs and makes it available to queries using databases like Postgres, Redis and ElasticSearch. The only requirement to run the indexer is access to a web3 enabled node. We run a kubernetes cluster of geth and parity nodes that can be scaled based on demand, but the indexer can be used as a standalone docker instance for other developers who want access to the underlying data. Data from the Ethereum logs are served via our REST API. All of this is written in Haskell, meaning up-to-date documentation and client libraries can be autogenerated using the servant library.

These elements together — front-end, smart contracts, Ethereum blockchain, and back-end indexer and database — combine to form a seamless loop of information flow. They are written in functional languages that provide strong types, implying greater control over the security of the program. This is vital when dealing with valuable transactions and the data of others. Our advanced developer stack lays a strong foundation for the development of our Proof of Location protocol but also provides strong functional alternatives for other developers looking beyond existing development patterns for Ethereum.