Typescript SDK to create and interact with Rosetta API implementations (WORK IN PROGRESS!)
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.
Before diving into the SDK, we recommend taking a look at the Rosetta API Docs:
- 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.
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));
npm install
to install dependenciesnpm run gen
to generate types and helpersnpm test
to run testsnpm style:fix
to pretty, index, and lint the source code (including generated code)
This project is available open source under the terms of the Apache 2.0 License.
© 2021 Fernando Boucquez