Giter Club home page Giter Club logo

firefly-tokens-erc1155's Introduction

FireFly Tokens Microservice for ERC1155

This project provides a thin shim between FireFly and an ERC1155 contract exposed via ethconnect.

Based on Node.js and Nest.

This service is entirely stateless - it maps incoming REST operations directly to ethconnect calls, and maps ethconnect events to outgoing websocket events.

This repository also includes sample Solidity contracts that conform to the ABIs expected by this connector. These contracts may be used to get up and running with simple token support, and may provide a starting point for developing production contracts that can be used with this connector.

POST APIs

The following POST APIs are exposed under /api/v1:

  • POST /init - Begin listening for created pools (inputs: namespace)
  • POST /createpool - Create a new token pool (inputs: type, data)
  • POST /activatepool - Activate a token pool to begin receiving transfers (inputs: namespace, poolLocator)
  • POST /mint - Mint new tokens (inputs: poolLocator, to, amount, data)
  • POST /burn - Burn tokens (inputs: poolLocator, tokenIndex, from, amount, data)
  • POST /transfer - Transfer tokens (inputs: poolLocator, tokenIndex, from, to, amount, data)

All requests may be optionally accompanied by a requestId, which must be unique for every request and will be returned in the "receipt" websocket event.

All APIs are async and return 202 immediately with a response of the form {id: string}. If no requestId was provided, this will be a randomly assigned ID. Clients should subscribe to the websocket (see below) in order to receive feedback when the async operation completes.

Websocket events

Websocket notifications can be received by connecting to /api/ws. All events have the form {event: string, id: string, data: any}.

When any POST operation completes, it will trigger a websocket event of the form: {event: "receipt", data: {id: string, success: bool, message?: string}}. This event is sent to all connected websocket clients and is informative only (does not require any acknowledgment).

Successful POST operations will also result in a detailed event corresponding to the type of transaction that was performed. The events and corresponding data items are:

  • token-pool - Token pool created (outputs: poolLocator, signer, type, data)
  • token-mint - Tokens minted (outputs: id, poolLocator, tokenIndex, uri, signer, to, amount, data)
  • token-burn - Tokens burned (outputs: id, poolLocator, tokenIndex, uri, signer, from, amount, data)
  • token-transfer - Tokens transferred (outputs: id, poolLocator, tokenIndex, uri, signer, from, to, amount, data)
  • token-approval - Tokens approved (outputs: id, subject, poolLocator, signer, operator, approved, data)

If multiple websocket clients are connected, only one will receive these events. Each one of these must be acknowledged by replying on the websocket with {event: "ack", data: {id}}.

GET APIs

The following GET APIs are exposed under /api/v1:

  • GET /balance - Get token balance (inputs: poolLocator, tokenIndex, account)
  • GET /receipt/:id - Get receipt for a previous request

Running the service

The easiest way to run this service is as part of a stack created via firefly-cli.

To run manually, you first need to run an Ethereum blockchain node and an instance of firefly-ethconnect, and deploy the ERC1155 smart contract.

Then, adjust your configuration to point at the deployed contract by editing .env or by setting the environment values directly in your shell.

Install and run the application using npm:

# install
$ npm install

# run in development mode
$ npm run start

# run in watch mode
$ npm run start:dev

# run in production mode
$ npm run start:prod

View the Swagger UI at http://localhost:3000/api
View the generated OpenAPI spec at http://localhost:3000/api-json

Testing

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# lint
$ npm run lint

# formatting
$ npm run format

firefly-tokens-erc1155's People

Contributors

awrichar avatar nguyer avatar onelapahead avatar peterbroadhurst avatar ryjones avatar shorsher 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.