@syscoinorg/syscoin-nodejs v3.0.0-beta
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 startRunning 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 startdRunning 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.confand 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: 1. Create an alias with a password. SetTEST_ALIASandTEST_ALIAS_PASSWORDto the alias and password. 1. Create an offer with 100 qty and a price of 1 SYS usingTEST_ALIASand setTEST_OFFER_GUIDto the guid of the new offer. 1. Create a certificate usingTEST_ALIAS, and setTEST_CERT_GUIDto the guid of the new cert. 1. Create a new message fromTEST_ALIAStoTEST_ALIAS, and setTEST_MESSAGE_GUIDto the guid of the new message. 1. Create a new escrow usingTEST_ALIASas buyer and arbiter, purchasingTEST_OFFER_GUID, and setTEST_ESCROW_GUIDto the guid of the new escrow. Run the test suite using the commend below, ensuring both Syscoin API Server and the Syscoin Core RPC Server are running.
npm run testNote: 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
offerAcceptandofferAcceptFeedbacktests. Additionally if theTEST_*identifiers you're using inConfig.jshave large result lists you may need to modify the specifics tests by adding athis.timeout(n)wherenrepresents 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:
hostvalue in/api/swagger.yamlswaggerSpec.hostvalue located in../../swagger-ui/dist/swagger-spec.jsHOSTvalue 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.
7 years ago