Hancock DLT Adapter

Microservice belonging to Hancock's ecosystem, which adapts transactions described in a common schema to the different blockchain implementations internal schemas.

Motivation

Smart Contracts are small programs that serve as interfaces for state changes on a distributed ledger. Currently there is no standard specification for these interfaces, and invocations are done in a very specific and unusable way, e.g. in Ethereum by translating transactions into a binary interface.

Furthermore, in order to exploit the full decentralization provided by blockchain, users should retain control over their wallets and trusted peers, and avoid scenarios where communication with blockchain is centralized on a gateway service that controls user private keys and trusted peers.

Proposed Change

DLT Adapter aims to provide a high-level interface to operations that can be performed on DLT Networks.

DLT Adapter is a web service that abstracts the user from interactions with DLT networks on a high-level common HTTP REST interface, that conveniently provides the user with the specific DLT type adapted transaction, and that can be easily inspected, signed and personally sent to a DLT network trusted node of the choice of the user.

There are 4 identified high-level interactions with a blockchain:

  • Smart Contract creation
  • Smart Contract transactions
  • Token transfers
  • Notarizations

One must remember to include the chain identifier in the adapted transaction, which must be executed just in the appropriate network.

Current blockchains supported

  • Ethereum

Building the service

Clone the project:

  # Clone the project 
  git clone https://github.com/BBVA/hancock-dlt-adapter.git
  cd kst-hancock-ms-dlt-adapter

With node and npm or yarn:

  # With npm
  npm install
  npm run build:ts
  npm run serve:prod

  # With yarn
  yarn install
  yarn run build:ts
  yarn run serve:prod

With docker:

  # Build the docker image
  docker build -t hancock_dlt_adapter .

  # Run the docker container
  docker run -d -it --name -p 80:80 hancock_dlt_adapter_container hancock_dlt_adapter

Setting up the service

Once we have built the service, we need to configure a few things before launching it. You can find all environment variables available to configure the service in config/custom-environment-variables.yaml.

An example of configuration of the most important variables:

Ethereum rpc node:
  export HANCOCK_BLOCKCHAIN_ETHEREUM_PROTOCOL="http"
  export HANCOCK_BLOCKCHAIN_ETHEREUM_HOST="52.80.128.77"
  export HANCOCK_BLOCKCHAIN_ETHEREUM_PORT="34774"
Mongo ddbb host:
  export HANCOCK_DB_HOSTS="localhost:27017"
  export HANCOCK_DB_DATABASE="hancock"
  export HANCOCK_DB_ETHEREUM_DATABASE="hancock_eth"

Using the service

Next sections describe the operations available on Hancock DLT Adapter.

Common operations

Allow operations like get balance, and adapt transfer.

For more info, go to Common operations over blockchain network.

Smartcontracts operations

Offer different operations to manage smart contracts:

  • Deploy (Useful for deploying new contracts with the same interface)
  • Call/Query (read operations)
  • Invoke/Apply (write operations)

It holds a registry for human-friendly smart contract management/interaction.

For more info, go to SmartContract operations over blockchain network.

Token operations

Facilitate a simple interface to work with a special case of Ethereum smartcontracts, with common ERC20 interface.

For more info, go to Token operations over Ethereum network.

Hancock protocol

Use Hancock protocol to encode and decode operations and work with data on QR code.

For more info, go to Protocol operations.

API documentation

DLT Adapter provides some endpoints to interact with the blockchain, allowing to read and to adapt different operations on DLT network. Take a look at the different sections of the API documentation to see examples of use:

API Documentation

Contribution guidelines

If you are thinking about contributing to the project, you should know that: