Running the Syscoin API NodeJS Server
Prior to running the server a Syscoin node must be installed and properly configured as a JSON-RPC server. After the full node is configured the syscoin-api server
needs to know the location of syscoin.conf using the SYS_LOCATION
environmental variable, replacing DATALOCATION
in the examples below
with the path to your Syscoin data directory, including the trailing slash.
To run the server, follow these simple steps:
npm install
SYS_LOCATION=DATALOCATION npm run start
Running the server in daemon mode
Running the server in daemon mode is dependent on pm2. To run the server as a daemon
use the below command after npm install
completes:
SYS_LOCATION=DATALOCATION npm run startd
Running unit tests
Syscoin API has a series of "sanity" unit tests written using the Mocha + Chai test framework and assertions library. Due to the confirmation-based nature of blockchain transactions and for ease of use, you must first create a few Syscoin services manually and use the data from these to configure the test, before running the tests.
Follow the steps below before running the test suite:
-
First ensure your wallet is running on a working testnet as the test suite will spend SYS in its execution. You can do this by editing
syscoin.conf
and specifyingtestnet=1
. -
Transfer at least 100 syscoin to the root wallet address (can be acquired by running
getaccountaddress ""
via syscoind or QT debug console) -
Manually create the following entities on the Syscoin network, and populate the result values mentioned below into
server/nodejs/spec/config.js
:- Create an alias with a password. Set
TEST_ALIAS
andTEST_ALIAS_PASSWORD
to the alias and password. - Create an offer with 100 qty and a price of 1 SYS using
TEST_ALIAS
and setTEST_OFFER_GUID
to the guid of the new offer. - Create a certificate using
TEST_ALIAS
, and setTEST_CERT_GUID
to the guid of the new cert. - Create a new message from
TEST_ALIAS
toTEST_ALIAS
, and setTEST_MESSAGE_GUID
to the guid of the new message. - Create a new escrow using
TEST_ALIAS
as buyer and arbiter, purchasingTEST_OFFER_GUID
, and setTEST_ESCROW_GUID
to the guid of the new escrow.
- Create an alias with a password. Set
-
Run the test suite using the commend below, ensuring both Syscoin API Server and the Syscoin Core RPC Server are running.
npm run test
Note: Depending on network variables some tests may fail due to lack of confirmation on transactions/operations earlier in the test suite. The test try to accomodate this by waiting 3mins for confirmations around these confirmation-sensitive transaction types. These are typically
offerAccept
andofferAcceptFeedback
tests. Additionally if theTEST_*
identifiers you're using inConfig.js
have large result lists you may need to modify the specifics tests by adding athis.timeout(n)
wheren
represents a time in ms that allows for the full response to be returned. The default is 2000ms.
Configuring for Production Use
Before deploying syscoin-api for production use you will need to modify the following files:
-
host
value in/api/swagger.yaml
-
swaggerSpec.host
value located in../../swagger-ui/dist/swagger-spec.js
-
HOST
value in/spec/config.js
In all these files modify the specified value from localhost:8001
to SERVERIP:8001
. Replacing SERVERIP
with your server's
production IP or domain. You can also optionally change the port.
It is highly recommended that you allow only HTTPS access in production deployments and secure all connections with a valid SSL certificate. Failure to do this can expose the wallet to attack.