0.0.1-alpha-202108260553 • Published 2 years ago

rosetta-sdk-typescript v0.0.1-alpha-202108260553

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Version Downloads/week License Build Status Coverage Status Api Doc

Overview

The rosetta-sdk-typescript provides an easy to use and extend Express server ready to serve your Rosetta typescript implementation for your blockchain.

Much of the code in this repository is generated from the rosetta-specifications.

Documentation

Before diving into the SDK, we recommend taking a look at the Rosetta API Docs:

Packages

  • OpenApi: Auto-generated Rosetta types, including api clients and server service extension points. Don't modify this code!
  • Client: Low-level communication with any Rosetta server. Main class is RosettaRestClientFactory.
  • Server: Simplified Rosetta API server development. Main class is RosettaServer. This SDK uses and Express server integrated with express-openapi-validator.

This current SDK implementation is not complete, most GO's sdk packages should be implemented in typescript.

Examples

First typescript WORK IN PROGRESS example is for the Symbol network.

You can see here how to create and run a network specific MyBlockchainApiServiceFactory.

The current implementation is incorrect as it relies on an external testnet node when the symbol node should be bundled wit the docker image.

This Example would be moved to its own repository and project.

  • npm run symbol:dev to run the server

Integration test with rosetta-cli is in progress.

Usage

Install this package:

npm install rosetta-sdk-typescript@alpha

The following script shows how to create a Rosetta Express server:

import { RosettaServer } from './server';

// The factory you need to provide that creates the services connecting to your blockchain client/node
const apiServiceFactory = new MyBlockchainApiServiceFactory(); 

new RosettaServer({ apiServiceFactory }).start(8080).catch((e) => {
    console.error(e);
});

The following script shows how to create a Rosetta network client:

import { RosettaRestClientFactory } from 'rosetta-sdk-typescript';

const restClientFactory = new RosettaRestClientFactory({
    url: 'http://localhost:8080',
});

const networkClient = restClientFactory.network();
const networkList = await networkClient.networkList({
    metadataRequest: {},
});
console.log(JSON.stringify(networkList, null, 2));

Development

  • npm install to install dependencies
  • npm run gen to generate types and helpers
  • npm test to run tests
  • npm style:fix to pretty, index, and lint the source code (including generated code)

License

This project is available open source under the terms of the Apache 2.0 License.

© 2021 Fernando Boucquez