Fairorder is the World's First MDaaS **"Managed Decentralization as a Service"** which is the fastest way to achieve decentralization using fair ordering of sequence of events. The underlying technology we use is Hedera Hashgraph. The **fairorder-js-sdk
npm install fairorder-js-sdkInstall FairOrder SDK to your app by including a script tag between the "TODO" comment lines on the code below.
``html`
OR
Download/install our sdk package using npm in your javascript project. The command for the same is:
`ssh`
$ npm i --save fairorder-js-sdk$3
Make sure you are signed in to our web dashboard. You need to create your app using our dashboard which will generate appId and secretId of the respective app. These credentials are important for initializing our sdk. The example for the same is given below.

`javascript`
const FairOrderSDK = require('fairorder-js-sdk').FairOrderSDK;
const fairOrder = new FairOrderSDK();
- For projects where sdk is added using script tag:
`javascript`
const fairOrder = new window['FairOrderSDK']();
Call the init function to initialize the SDK with the app credentials.
The dragonglass secret key is optional if you want to use the dragonglass explorer as mirror node with V2 functions.
`javascript`
await fairOrder.init({app_id: "your-app's-app-id", secret_key:"your-app's-secret-key", dragonSecretKey:"your-dragon-glass-api-key"});$3
Call the submitMessage function with channelId and the message to submit.
`javascript`
fairOrder.submitMessage("0.0.195302", "message").then((res)=>{
console.log('Success::::::', res);
// res example:::
// {
// nodePrecheckcode: 22,
// receiptStatus: 22,
// transactionId: 0.0.194939@1584011966.128000000
// }
}).catch((error)=>{
console.log('Error::::::', error);
});
- [FairOrderSDK][1]
- [Example][2]
- [init][3]
- [Parameters][4]
- [Example][5]
- [getChannelList][6]
- [Example][7]
- [createChannel][8]
- [Parameters][9]
- [Example][10]
- [updateChannel][11]
- [Parameters][12]
- [Example][13]
- [channelInfo][14]
- [Parameters][15]
- [Example][16]
- [submitMessage][17]
- [Parameters][18]
- [Example][19]
- [getMessageListByChannelId][20]
- [Parameters][21]
- [Example][22]
- [getMessageByMessageId][23]
- [Parameters][24]
- [Example][25]
- [getChannelListV2][26]
- [Parameters][27]
- [Example][28]
- [getMessageListByChannelIdV2][29]
- [Parameters][30]
- [Example][31]
Class represents the entry point of the sdk. By initializing the object of the class the functions are accessible
javascript
const fairOrder = new FairOrderSDK();
`
$3
function to initialize the sdk with app credentials.
$3
- credentials [Object][32] the object containing
- credentials.app_id [string][33] the application id which you get from dashboard
- credentials.secret_key [string][33] the secret key which you get from dashboard
- credentials.dragonSecretKey [string][33] this key is optional if you wish to use dragonglass explorer as mirror node with V2 functions.`javascript
fairOrder.init(credetials).then(()=>{
console.log('Success::::::');
}).catch((error)=>{
console.log('Error::::::', error); });
`$3
function to get channel list for the application
Returns [Array][34] list of channels
#### Example
`javascript
fairOrder.channelList().then((res)=>{
console.log('Success::::::', res);
// res example::::::
// [
// {
// id: '0.0.195302',
// createdByTransactionHash: '6b65c6b557675a0b0c84058832f7585035872a1810e49380deefeb27db8bea3636277c99737a2635756a340e47b0ef56',
// createdAt: '2020-03-12T11:03:26.772434Z',
// creator: '0.0.194939',
// adminKey: {
// ed26519: 'e9d22a2f18afb34b5eaf8cc6967d151090c7cafbb9fcbddb87cb5ae4d0a37cb1'
// },
// submitKey: { keys: [Array] },
// memo: 'new-example-channel',
// autoRenewPeriod: 7890000,
// autoRenewAccount: '0.0.194939'
// },
// {
// id: '0.0.194960',
// createdByTransactionHash: '00391c242909274e221b1c2fb733cd99060b4f4a0cd7698824650288a853f158fec00d017dc4e23a14f426d05f992b8b',
// createdAt: '2020-03-11T14:39:18.222424Z',
// creator: '0.0.194939',
// adminKey: {
// ed26519: 'e9d22a2f18afb34b5eaf8cc6967d151090c7cafbb9fcbddb87cb5ae4d0a37cb1'
// },
// submitKey: { keys: [Array] },
// memo: 'vivek',
// autoRenewPeriod: 7890000,
// autoRenewAccount: '0.0.194939'
// },
// ]
}).catch((error)=>{
console.log('Error::::::', error);
});
``$3
function creates a new channel for the provided channel name
#### Parameters
-
channelName [string][33] refers to name of the channelReturns [Object][32] response obj with transaction receipt
#### Example
`javascript
fairOrder.createChannel("example-channel-name").then((res)=>{
console.log('Success::::::', res);
// res example:::
// {
// nodePrecheckcode: 22,
// receiptStatus: 22,
// transactionId: 0.0.194939@1584010996.271000000,
// channelId: 0.0.195302
// }
}).catch((error)=>{
console.log('Error::::::', error);
});
`
$3
function to update the name a given channel for the corresponding channelId
#### Parameters
-
newChannelName [string][33] refers to name of the channel
- channelID [string][33] refers to ID of the channelReturns [Object][32] response obj with transaction receipt.
#### Example
`javascript
fairOrder.updateChannel("new-channel-name", "0.0.195302").then((res)=>{
console.log('Success::::::', res);
// res example:::
// {
// nodePrecheckcode: 22,
// receiptStatus: 22,
// transactionId: 0.0.194939@1584011966.128000000
// }
}).catch((error)=>{
console.log('Error::::::', error);
});
`$3
function to get info for the corresponding channelId
#### Parameters
-
channelID [string][33] refers id of the channel.Returns [Object][32] channel info response obj.
#### Example
`javascript
fairOrder.channelInfo("new-channel-name", "0.0.195302").then((res)=>{
console.log('Success::::::', res);
// res::::
// {
// channelInfo: {
// topicMemo: 'new-example-channel',
// runningHash: Uint8Array(48) [
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 0, 0, 0, 0
// ],
// sequenceNumber: 0,
// expirationTime: Time { seconds: 1591901006, nanos: 772434000 },
// adminKey: 302a300506032b6570032100e9d22a2f18afb34b5eaf8cc6967d151090c7cafbb9fcbddb87cb5ae4d0a37cb1,
// submitKey: KeyList { _keys: [Array] },
// autoRenewPeriod: 7890000,
// autoRenewAccount: 0.0.194939
// }
// } }).catch((error)=>{
console.log('Error::::::', error);
});
`$3
function to submit a message on the corresponding channel
#### Parameters
-
channelID [string][33] refers to id of the channel
- msg [string][33] refers to the message text you want to submitReturns [Object][32] response obj with transaction receipt.
#### Example
`javascript
fairOrder.submitMessage("0.0.195302", "message").then((res)=>{
console.log('Success::::::', res);
// res example:::
// {
// nodePrecheckcode: 22,
// receiptStatus: 22,
// transactionId: 0.0.194939@1584011966.128000000
// }
}).catch((error)=>{
console.log('Error::::::', error);
});
`
$3
function to get the list of messages by channelId
#### Parameters
-
channelID [string][33] refers to id of the channelReturns [Array][34] list of messages on that channel
#### Example
`javascript
fairOrder.getMessageListByChannelId("0.0.195302").then((res)=>{
console.log('Success::::::', res);
// res example::::::
// [
// {
// runningHash: '78648fc4354ee39f29137d156f8b01b9e78ad87450a60f4536e446b2f0f7d57d34c3ca3e9cdb755cbd4a9116bac03a37',
// sequenceNumber: 1,
// submittedByTransactionHash: '41e9c97ab1cbceafd2a49db0c5616b82b5b47ad01478018a2b3726796179e7e14b03ff8ec2bef6c2a5cf1ab027a0b426',
// submittedAt: '2020-03-12T11:30:47.170218002Z',
// submitter: '0.0.194939'
// }
// ]
}).catch((error)=>{
console.log('Error::::::', error);
});
`
$3
function to get the message content by message id.
#### Parameters
-
msgId [string][33] refers to id of the channel
- channelId
- channelID [string][33] refers to id of the channelReturns [string][33] message content of the message id
#### Example
`javascript
fairOrder.getMessageByMessageId("1","0.0.195302").then((res)=>{
console.log('Success::::::', res);
// res example::::::
// message
}).catch((error)=>{
console.log('Error::::::', error);
});
``
$3
function to get channel list for the application from dragonglass explorer
Returns [Object][32] list of channels
#### Parameters
-
pageSize [Number][35] no of items in one call
- pageNum [Number][35] the page number#### Example
`javascript
fairOrder.channelListV2(10,1).then((res)=>{
console.log('Success::::::', res);
// res example:::::: where topicId is your channel id
// {
// "size": 2,
// "totalCount": 2,
// "data": [
// {
// "topicID": "0.0.47598",
// "memo": "",
// "createdDate": "2020-05-18T08:38:20.880+0000",
// "createdBy": "0.0.32247",
// "transactionID": "00322471589791090628000000",
// "readableTransactionID": "0.0.32247@1589791090-628000000"
// },
// {
// "topicID": "0.0.32248",
// "memo": "",
// "createdDate": "2020-04-28T06:01:27.183+0000",
// "createdBy": "0.0.32247",
// "transactionID": "00322471588053676891000000",
// "readableTransactionID": "0.0.32247@1588053676-891000000"
// }
// ]
// }
}).catch((error)=>{
console.log('Error::::::', error);
});
``$3
function to get the list of messages by channelId from dragonglass explorer
#### Parameters
-
channelID [string][33] refers to id of the channelReturns [Object][32] list of messages on that channel
#### Example
`javascript
fairOrder.getMessageListByChannelIdV2("0.0.195302").then((res)=>{
console.log('Success::::::', res);
// res example::::::
// {
// "size":2,
// "totalCount":2,
// "data":[
// {
// "transactionID":"00322471590406359860000000",
// "readableTransactionID":"0.0.32247@1590406359-860000000",
// "consensusTime":"2020-05-25T11:32:51.089+0000",
// "status":"SUCCESS",
// "topicID":"0.0.32248",
// "message":"74657374206d657373616765",
// "topicSequenceNumber":4,
// "topicRunningHash":"662231ca65ad289723c4e473cd66820969e166a9cf7da0fbb49b7dcbf52303c5b01262908ea07b1968c60c6087f699a3",
// "submitter":"0.0.32247"
// },
// {
// "transactionID":"00322471588054216738000000",
// "readableTransactionID":"0.0.32247@1588054216-738000000",
// "consensusTime":"2020-04-28T06:10:27.356+0000",
// "status":"SUCCESS",
// "topicID":"0.0.32248",
// "message":"7b227075626c69736865725f6964223a2231222c22616476657274697365725f6964223a22414431222c226576656e745f74797065223a22636c69636b222c2263616d706169676e5f6964223a224331222c226164756e69745f6964223a22415531227d",
// "topicSequenceNumber":3,
// "topicRunningHash":"0a7a6fb7bed1079f92472e48360864ca7c7b0bfcf3f533dd61ffc623af71aa9a92d415ba62d980f4fb9c95f2219127aa",
// "submitter":"0.0.32247"
// },
// ]
// }
}).catch((error)=>{
console.log('Error::::::', error);
});
``[1]: #fairordersdk
[2]: #example
[3]: #initaccount
[4]: #parameters
[5]: #example-1
[6]: #getchannellist
[7]: #example-2
[8]: #createchannel
[9]: #parameters-1
[10]: #example-3
[11]: #updatechannel
[12]: #parameters-2
[13]: #example-4
[14]: #channelinfo
[15]: #parameters-3
[16]: #example-5
[17]: #submitmessage
[18]: #parameters-4
[19]: #example-6
[20]: #getmessagelistbychannelid
[21]: #parameters-5
[22]: #example-7
[23]: #getmessagebymessageid
[24]: #parameters-6
[25]: #example-8
[26]: #getchannellistv2
[27]: #parameters-7
[28]: #example-9
[29]: #getmessagelistbychannelidv2
[30]: #parameters-8
[31]: #example-10
[32]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[33]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[34]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[35]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number