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 is the package that will help in integrating our service in your application.
Download/install our sdk package using npm in your javascript project. The command for the same is:
$ npm i --save fairorder-js-sdk
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.
Then instantiate the sdk object with the app credentials.
const FairOrderSDK = require('fairorder-js-sdk');
const fairOrder = new FairOrderSDK();
Call the init function to initialize the SDK
await fairOrder.init({app_id: "your-app's-app-id", secret_key:"your-app's-secret-key"});
Call the submitMessage function with channelId and the message to submit.
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);
});
Class represents the entry point of the sdk. By initializing the object of the class the functions are accessible
const fairOrder = new FairOrderSDK();
function to initialize the sdk with app credentials.
credentials
Object the object containing
fairOrder.init(credetials).then(()=>{
console.log('Success::::::');
}).catch((error)=>{
console.log('Error::::::', error);
});
function to get channel list for the application
Returns Array list of channels
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);
});
function creates a new channel for the provided channel name
channelName
string refers to name of the channel
Returns Object response obj with transaction receipt
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);
});
function to update the name a given channel for the corresponding channelId
Returns Object response obj with transaction receipt.
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);
});
function to get info for the corresponding channelId
channelID
string refers id of the channel.
Returns Object channel info response obj.
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);
});
function to submit a message on the corresponding channel
channelID
string refers to id of the channelmsg
string refers to the message text you want to submit
Returns Object response obj with transaction receipt.
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);
});
function to get the list of messages by channelId
channelID
string refers to id of the channel
Returns Array list of messages on that channel
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);
});
function to get the message content by message id.
Returns string message content of the message id
fairOrder.getMessageByMessageId("1","0.0.195302").then((res)=>{
console.log('Success::::::', res);
// res example::::::
// message
}).catch((error)=>{
console.log('Error::::::', error);
});