diff --git a/.husky/pre-push b/.husky/pre-push
new file mode 100755
index 00000000..449fcdee
--- /dev/null
+++ b/.husky/pre-push
@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")/_/husky.sh"
+
+npm test
diff --git a/README.md b/README.md
index 8c226264..68ab2695 100644
--- a/README.md
+++ b/README.md
@@ -1,33 +1,33 @@
-
+
-> The Signum Network Type/Javascript Reference Library
+> The Signum Network SDK for Javascript (written in Typescript)

[](https://lernajs.io/)
-[](https://www.codacy.com/app/ohager/phoenix?utm_source=github.com&utm_medium=referral&utm_content=burst-apps-team/phoenix&utm_campaign=Badge_Grade)
[](https://github.com/burst-apps-team/phoenix/actions?query=workflow%3A%22Build+BurstJS%22)
[](https://snyk.io/test/github/burst-apps-team/phoenix?targetFile=lib%2Fpackage.json)
-[](https://codecov.io/gh/burst-apps-team/phoenix)
[](https://www.jsdelivr.com/package/npm/@signumjs/core)
-`@signumjs` is a modern library written in Typescript providing common functionalities for _browsers_ and _nodejs_ to interact with the [Signum Network blockchain](https://signum.network/),
-an advanced community-driven blockchain technology.
+`@signumjs` is a modern SDK written in Typescript providing common functionalities for _browsers_ and _nodejs_ to
+interact with the [Signum Network blockchain](https://signum.network/), an advanced community-driven blockchain
+technology.
## Packages
-The library is separated in the following packages
+The SDK is separated in the following packages
- [@signumjs/core](./modules/core.html) The main package providing an extense API for blockchain interaction
- [@signumjs/contracts](./modules/contracts.html) A package providing Signum relevant functions for _smart contracts_
- [@signumjs/crypto](./modules/crypto.html) A package providing Signum relevant crypto functions
-- [@signumjs/util](./modules/util.html) A package providing useful functions, e.g. common conversion functions
-- [@signumjs/http](./modules/http.html) A package providing a _simplified_ Http layer, with consistent response types, and exception handling
-- [@signumjs/monitor](./modules/monitor.html) A package providing a class to execute recurring async operations with de/serialization feature, good for listening to blockchain transactions
-
+- [@signumjs/util](./modules/util.html) A package providing useful functions, e.g. common conversion functions
+- [@signumjs/http](./modules/http.html) A package providing a _simplified_ Http layer, with consistent response types,
+ and exception handling
+- [@signumjs/monitor](./modules/monitor.html) A package providing a class to execute recurring async operations with
+ de/serialization feature, good for listening to blockchain transactions
## Installation
-`@signumjs` aims modern browsers and nodejs > v10, but can also be used as bundled JavaScript using ``
-Due to the way a package is imported following global variables are provided
+``
+Due to the way a package is imported following global variables are provided
| Package | Variable |
|---------|----------|
@@ -89,7 +88,7 @@ Examples:
```js
// using core
const api = sig$.composeApi({
- nodeHost: "http://testnet.signum.network",
+ nodeHost: "http://testnet.signum.network",
});
api.network.getBlockchainStatus().then(console.log);
@@ -111,79 +110,73 @@ console.log(sig$crypto.hashSHA256("test"))
const value = sig$util.Value.fromSigna("1000")
```
-```js
+```ts
// using http
const client = new sig$http.HttpClientFactory.createHttpClient('https://jsonplaceholder.typicode.com/');
client.get('/todos/1').then(console.log)
```
-```js
+```ts
// using monitor
-
- // A method that checks if an account exists
- // > IMPORTANT: Do not use closures, when you need to serialize the monitor
- async function tryFetchAccount() {
- const Api = composeApi({nodeHost: 'https://testnet.signum.network:6876/'})
- try {
- const {account} = await Api.account.getAccount('1234')
- return account;
- } catch (e) {
- // ignore error
- return null;
- }
- }
-
- // A comparing function to check if a certain condition for the returned data from fetch function
- // is true. If it's true the monitor stops
- function checkIfAccountExists(account) {
- return account !== null;
- }
-
- // Create your monitor
- const monitor = new Monitor < Account > ({
- asyncFetcherFn: tryFetchAccount,
- compareFn: checkIfAccountExists,
- intervalSecs: 10, // polling interval in seconds
- key: 'monitor-account',
- timeoutSecs: 2 * 240 // when reached timeout the monitor stops
- })
- .onFulfilled(() => {
- // called when `checkIfAccountExists` returns true
- console.log('Yay, account active');
- })
- .onTimeout(() => {
- // called when `timeoutSecs` is reached
- console.log('Hmm, something went wrong');
- }).start();
-```
+// A method that checks if an account exists
+// > IMPORTANT: Do not use closures, when you need to serialize the monitor
+async function tryFetchAccount() {
+ try {
+ const api = composeApi({nodeHost: 'https://testnet.signum.network:6876/'})
+ const {account} = await api.account.getAccount('1234')
+ return account;
+ } catch (e) {
+ // ignore error
+ return null;
+ }
+}
+
+// A comparing function to check if a certain condition for the returned data from fetch function
+// is true. If it's true the monitor stops
+function checkIfAccountExists(account) {
+ return account !== null;
+}
+
+// Create your monitor
+const monitor = new Monitor({
+ asyncFetcherFn: tryFetchAccount,
+ compareFn: checkIfAccountExists,
+ intervalSecs: 10, // polling interval in seconds
+ key: 'monitor-account',
+ timeoutSecs: 2 * 240 // when reached timeout the monitor stops
+})
+ .onFulfilled(() => {
+ // called when `checkIfAccountExists` returns true
+ console.log('Yay, account active');
+ })
+ .onTimeout(() => {
+ // called when `timeoutSecs` is reached
+ console.log('Hmm, something went wrong');
+ }).start();
+```
## Usage
The following example shows how to interact with the blockchain, i.e. getting the balance of a specific account
-
### ES6/NodeJS style
In a separate file, preferably `index.js` or `main.js` write your entry point like this:
```js
import {composeApi, ApiSettings} from '@signumjs/core'
-import {convertNQTStringToNumber} from '@signumjs/util'
-
-const apiSettings = new ApiSettings('http://at-testnet.burst-alliance.org:6876', 'burst');
-const api = composeApi(apiSettings);
+import {Amount} from '@signumjs/util'
// this self-executing file makes turns this file into a starting point of your app
-
(async () => {
- try{
- const {balanceNQT} = await api.account.getAccountBalance('13036514135565182944')
- console.log(`Account Balance: ${Value.fromPlanck(balanceNQT).toString()}`)
- }
- catch(e){ // e is of type HttpError (as part of @signumjs/http)
- console.error(`Whooops, something went wrong: ${e.message}`)
- }
+ try {
+ const api = composeApi({nodeHost: 'https://testnet.burstcoin.network:6876'});
+ const {balanceNQT} = await api.account.getAccountBalance('13036514135565182944')
+ console.log(`Account Balance: ${Amount.fromPlanck(balanceNQT).toString()}`)
+ } catch (e) { // e is of type HttpError (as part of @signumjs/http)
+ console.error(`Whooops, something went wrong: ${e.message}`)
+ }
})()
```
@@ -191,41 +184,42 @@ const api = composeApi(apiSettings);
### `