The Ledger Client
To post or get data to/from the Signum Blockchain you need to create a ledger client instance. Once instantiated you have access to all the functions provided by the Node HTTP API in a comfortable and intuitive way.
The client organizes the calls into groups according their functionality, i.e.
- account
- alias
- asset
- block
- contract
- message
- network
- transaction
Each of this subgroup provides a set of functions (see API Reference for complete documentation). For example, network related functionality like getting a list of connected peers are in network, while balance information are inside the account subgroup.
Instantiating a ledger client is very easy:
const ledger = LedgerClientFactory.createClient({
nodeHost: "https://europe3.testnet.signum.network"
});Networks
At this time of writing Signum runs two major networks: Main Net and Test Net
Test Net
As a general rule, all development should be done on Test Net first. The Signum Core Team provides a public Test Net Node: https://europe3.testnet.signum.network and a public explorer under https://t-chain.signum.network . But best is to run a local Test Net host http://localhost:6876
See how to Starting a Signum-Node for development purposes.
Main Net
The Main Net consists of hundreds of nodes, but some of them are considered as Featured Nodes, which are maintained by the Signum Core Team and further community members and guarantee better up times.
A full list of feature nodes can be found in the Main Net Explorer.
Automatic Node Selection
As a blockchain is a distributed ledger, you can connect the ledger client with any of the nodes. If you provide an application and want to offer better user experience through better loading times, it would be good if the application could be capable of selecting the "best" node. SignumJS provides such a functionality, which tests the response times of a set of given node urls. To auto-select the "best" node do the following:
const {LedgerClientFactory} = require("@signumjs/core");
async function selectBestHost() {
try {
const featuredNodes = [
'http://localhost:8125', // local main net host
'https://europe.signum.network',
'https://europe1.signum.network',
'https://europe2.signum.network',
'https://europe3.signum.network',
'https://brazil.signum.network',
'https://australia.signum.network',
'https://us-east.signum.network',
]
const ledger = LedgerClientFactory.createClient({
nodeHost: featuredNodes[0], // default node
reliableNodeHosts: featuredNodes // set this list, when you plan to use the `selectBestHost` method
})
// by calling this method all nodes from `reliableNodeHosts` will be requested to see who's responding fastest
// We want the ledger to be re-configured to the best node automatically, that's why we pass `true` as first argument
const selectedHost = await ledger.service.selectBestHost(true)
console.log('Fastest Responding Node', selectedHost)
// you can also get the current selected host from the ledger client, like this
// ledger.service.settings.nodeHost
} catch (e) {
// If the API returns an exception,
// the return error object is of type HttpError
handleError(e);
}
}
(async () => {
await selectBestHost();
})();