pulsar_sdk_js
v1.0.3
Published
A convenient way for you to interact with Pulsar's Third Party APIs, using typified classes.
Downloads
320
Maintainers
Readme
This repository holds the code for our Javascript/Typescript SDK.
Commands
npm run build
- Builds the SDKnpm run test api_key=YOUR_API_KEY_HERE
- Runs the tests (Need to have an API key. Runcreate_sdk_test_account.py
in microservices-monorepo to get one.)npm pack
- Creates a tarball of the SDK, which can be installed in other projects usingnpm install <path_to_tarball>
, or published to NPM usingnpm publish
(Needsnpm run build
before running this command)
Getting Started
Installation
To install the SDK, git clone
the repository and run npm install
in the root directory. This will install all the dependencies and build the SDK. If you'd like to use this SDK in your own project, you can run npm pack
to create a tarball of the SDK, which you can then install in your project using npm install <path_to_tarball>
.
Alternatively, you can install the SDK directly from NPM using npm install pulsar_sdk_js
.
Usage
To use the SDK, you need to import the PulsarSDK
class from the pulsar_sdk_js
package. You can then instantiate the class with your API key, and use the SDK to make requests to the API.
import { PulsarSDK } from 'pulsar_sdk_js'
const API_KEY = 'YOUR_API_KEY'
const sdk = new PulsarSDK(API_KEY)
const token = sdk.tokens.get_token_info_by_address_and_chain(TokenType.ADDRESS, ChainKeys.TERRA2, 'YOUR TOKEN ADDRESS')
An example fetching wallet balances:
import { ChainKeys, PulsarSDK } from 'pulsar_sdk_js'
const API_KEY = 'YOUR_API_KEY'
const ETHEREUM_TEST_WALLET = '0x77984dc88aab3d9c843256d7aabdc82540c94f69'
const sdk = new PulsarSDK(API_KEY)
const responsesList = []
for await (const response of sdk.balances.getWalletBalances(ETHEREUM_TEST_WALLET, ChainKeys.ETHEREUM)) {
responsesList.push(response)
}
It's important to notice that the SDK uses async generators to iterate through the responses. This means that you can use a for await
loop to iterate through the responses. This is necessary because the SDK uses Websockets to fetch the data, and the responses are streamed in real time.
Which will fetch you all the wallet balances for your wallet, provided the Chain is active in our environment. For more information, check out our documentation.
Pull Requests
In order to contribute, you need to create a new branch, make your changes and open a pull request. Before opening the pull request, run npm run build
to build the SDK and npm run test
to run the tests. If you're adding a new feature, make sure to add tests for it. In order to run the tests, you will need to have a server instance running in your machine, and then pass an API key to the tests, like this: npm run test --api_key=YOUR_API_KEY_HERE
.
If the tests pass, you can open a pull request. This will then run the tests again, but on CircleCI connected to QA.
Make sure to npm pack
before opening the pull request, and testing the SDK in a separate project, to make sure everything works as expected when installed from NPM.
To publish this repository, save your npm credentials:
Generate an npm Access Token:
- Log in to your npm account.
- Navigate to the Access Tokens section under your account settings.
- Create a new token with the publish scope.
- Copy the generated token.
Store the Token with npm:
- Open your terminal.
- Run the following command:
npm set //registry.npmjs.org/:_authToken=your-npm-token
- Replace
your-npm-token
with the token you copied from npm.
Publishing
To publish the SDK to the NPM registry:
npm version patch/minor/major
to increment the version number.npm test api_key=YOUR_API_KEY_HERE
to make sure the tests pass.npm run build
to build the SDK.npm pack
to create a tarball of the SDK.- Optionally, you can test the SDK in a separate project by installing the tarball using
npm install <path_to_tarball>
to make sure everything works as expected.
- Optionally, you can test the SDK in a separate project by installing the tarball using
npm publish <path_to_tarball>
to publish the SDK to NPM.
Make sure to update the CHANGELOG.md
file with the changes you've made.
Incrementing Version
- Patch: For backward-compatible bug fixes.
npm version patch
- Minor: For backward-compatible new features.
npm version minor
- Major: For changes that break backward compatibility.
npm version major
Setting a Specific Version
You can also set the version directly:
npm version 1.2.3
Replace 1.2.3
with your desired version number.
Changelog
0.1.42
- Initial release.