The Signum Network SDK for Javascript (written in Typescript)
@signumjs
is a modern SDK written in Typescript providing common functionalities for browsers and nodejs to
interact with the Signum Network blockchain, an advanced community-driven blockchain
technology.
π·ββοΈπ·ββοΈπ·ββοΈ ποΈποΈποΈ MODERNIZATION IN PROGRESS ποΈποΈποΈ π·ββοΈπ·ββοΈπ·ββοΈ
- CONTRACTS
- CORE
- CRYPTO
- HTTP
- UTILS
- STANDARDS
- WALLET
- DOCUMENTATION
- MORE EXAMPLES
Version 2 is now live. There are some major changes especially for the crypto package. Check more details here Consider this version as not fully stable yet.
Best way to start is with the extensive Online Documentation
The SDK is separated in the following packages
- @signumjs/core The main package providing an extensive API for blockchain interaction
- @signumjs/contracts A package providing Signum relevant functions for smart contracts
- @signumjs/crypto A package providing Signum relevant crypto functions
- @signumjs/util A package providing useful functions, e.g. common conversion functions
- @signumjs/http A package providing a simplified Http layer, with consistent response types, and exception handling
- @signumjs/wallets This package provides the communication with SIP22 compatible deeplinkable
- @signumjs/standards This package provides the communication with SIP22 compatible deeplinkable
@signumjs
aims modern browsers and nodejs >= v14, but can also be used as bundled JavaScript using <script>
Install using npm:
npm install @signumjs/core
npm install @signumjs/contracts (optional)
npm install @signumjs/crypto (optional)
npm install @signumjs/util (optional)
npm install @signumjs/http (optional)
npm install @signumjs/wallets (optional)
npm install @signumjs/standards (optional)
or using yarn:
yarn add @signumjs/core
yarn add @signumjs/contracts (optional)
yarn add @signumjs/crypto (optional)
yarn add @signumjs/util (optional)
yarn add @signumjs/http (optional)
yarn add @signumjs/wallets (optional)
yarn add @signumjs/standards (optional)
Each package is available as bundled standalone library using UMD. This way SignumJS can be used also
within <script>
-Tags. This might be useful for Wordpress and/or other PHP applications.
Just import one of the packages using the HTML <script>
tag.
<script src='https://cdn.jsdelivr.net/npm/@signumjs/core/dist/signumjs.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@signumjs/contracts/dist/signumjs.contracts.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@signumjs/crypto/dist/signumjs.crypto.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@signumjs/http/dist/signumjs.http.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@signumjs/util/dist/signumjs.util.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@signumjs/wallets/dist/signumjs.wallets.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@signumjs/standards/dist/signumjs.standards.min.js'></script>
Due to the way a package is imported following global variables are provided
Package | Variable |
---|---|
core | sig$ |
contracts | sig$contracts |
crypto | sig$crypto |
http | sig$http |
util | sig$util |
wallets | sig$wallets |
wallets | sig$standards |
Examples:
// using core
const ledger = sig$.LedgerClientFactory.create({
nodeHost: "https://europe3.testnet.signum.network",
});
ledger.network.getBlockchainStatus().then(console.log);
// using contracts
const dataView = new sig$contracts.ContractDataView(contract)
console.log(dataView.getVariable(2))
// using crypto
console.log(sig$crypto.sha256AsHex("test"))
// using util
const value = sig$util.Amount.fromSigna("1000")
// using http
const client = new sig$http.HttpClientFactory.createHttpClient('https://jsonplaceholder.typicode.com/');
client.get('/todos/1').then(console.log)
// using wallets
const wallet = new sig$wallets.GenericExtensionWallet()
const connection = await wallet.connect();
const subscription = connection.listen({
onAccountChanged: (accountId, publicKey) => { /*...*/ }
})
// ...
subscription.unlisten()
// using standards - depends on ledger
const ledger = sig$.LedgerClientFactory.create({
nodeHost: "https://europe3.testnet.signum.network",
});
// create Descriptor data object
const descriptorData = sig$standards.DescriptorDataBuilder
.create('ohager')
.setType('hum')
.setBackground('QmUFc4dyX7TJn5dPxp8CrcDeedoV18owTBUWApYMuF6Koc', 'image/jpeg')
.setAvatar('QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR', 'image/gif')
.setSocialMediaLinks(['https://somelink.com'])
.setDescription('Just a humble dev...')
.setHomePage('https://digital-independence.dev')
.build();
// updates account descriptor
const client = new sig$standards.DescriptorDataClient(ledger)
const transaction = await client.setAccountDescriptor({
descriptorData,
senderPublicKey: '497d559d18d989b8....ed2716a4b2121902',
senderPrivateKey: '**********************************'
});
The following example shows how to interact with the blockchain, i.e. getting the balance of a specific account
In a separate file, preferably index.js
or main.js
write your entry point like this:
import {LedgerClientFactory, ApiSettings} from '@signumjs/core'
import {Amount} from '@signumjs/util'
// this self-executing file makes turns this file into a starting point of your app
(async () => {
try {
const ledger = LedgerClientFactory.createClient({nodeHost: 'https://europe3.testnet.signum.network'});
const {balanceNQT} = await ledger.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}`)
}
})()
const ledger = sig$.LedgerClientFactory.create({nodeHost: 'https://europe3.testnet.signum.network'});
ledger.account.getAccountBalance('13036514135565182944')
.then(balance => {
console.log(`Account Balance: ${sig$util.Amount.fromPlanck(balance.balanceNQT).toString()}`)
})
.catch(e => { // e is of type HttpError (as part of @signumjs/http)
console.error(`Whooops, something went wrong: ${e.message}`)
})
Contributors are warmly welcome. To start your local build just hit
npm install
That's it!
The SDK is using Turborepo to manage all subpackages in a developer friendlier way:
npm run build
- Single test run
npm run test
2Run end-to-end testnpm run test:e2e
| Keep in mind that these tests are slow as they run against true servers. And therefore, it cannot be guaranteed that all E2E tests always work
This monorepo uses changeset to manage the versions and publish the package. We use one version for all packages.
- Create a changeset:
npx changeset
- Bump version:
npx changeset version
- Publish
npx changeset publish --tag <VERSION> --otp <NPM_OTP>
The latter can be run as
npm run publish v2.0.1 --otp 123456
Note: Only with a valid npm OTP token