2.0.2 • Published 4 years ago

fairorder-js-sdk v2.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

FairOrder

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.

Installation

Step 1: Include FairOrder SDK in your project

Install FairOrder SDK to your app by including a script tag between the "TODO" comment lines on the code below.

    <!-- TODO: Step 1: Include FairOrder SDK Script -->
    <script charset="utf-8" src="https://cdn.jsdelivr.net/npm/fairorder-js-sdk@latest/dist/fairorder.js"></script>
    <!-- End Step 1 -->

OR

Download/install our sdk package using npm in your javascript project. The command for the same is:

$ npm i --save fairorder-js-sdk

Step 2: Setup developer API credentials

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.

npm.io

Step 3: Initialize the SDK

Then instantiate the sdk object.

  • For NodeJs project:

        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.

    await fairOrder.init({app_id: "your-app's-app-id", secret_key:"your-app's-secret-key", dragonSecretKey:"your-dragon-glass-api-key"});

Step 4: Submit your transactions

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);
    });

Table of Contents

FairOrderSDK

Class represents the entry point of the sdk. By initializing the object of the class the functions are accessible

Example

    const fairOrder = new FairOrderSDK();

init

function to initialize the sdk with app credentials.

Parameters

  • credentials Object the object containing
    • credentials.app_id string the application id which you get from dashboard
    • credentials.secret_key string the secret key which you get from dashboard
    • credentials.dragonSecretKey string this key is optional if you wish to use dragonglass explorer as mirror node with V2 functions.
    fairOrder.init(credetials).then(()=>{
        console.log('Success::::::');
    }).catch((error)=>{
        console.log('Error::::::', error);

    });

getChannelList

function to get channel list for the application

Returns Array list of channels

Example

    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);
    });

createChannel

function creates a new channel for the provided channel name

Parameters

  • channelName string refers to name of the channel

Returns Object response obj with transaction receipt

Example

    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);
    });

updateChannel

function to update the name a given channel for the corresponding channelId

Parameters

  • newChannelName string refers to name of the channel
  • channelID string refers to ID of the channel

Returns Object response obj with transaction receipt.

Example

    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);
    });

channelInfo

function to get info for the corresponding channelId

Parameters

  • channelID string refers id of the channel.

Returns Object channel info response obj.

Example

    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);
    });

submitMessage

function to submit a message on the corresponding channel

Parameters

  • channelID string refers to id of the channel
  • msg string refers to the message text you want to submit

Returns Object response obj with transaction receipt.

Example

    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);
    });

getMessageListByChannelId

function to get the list of messages by channelId

Parameters

  • channelID string refers to id of the channel

Returns Array list of messages on that channel

Example

    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);
    });

getMessageByMessageId

function to get the message content by message id.

Parameters

  • msgId string refers to id of the channel
  • channelId
  • channelID string refers to id of the channel

Returns string message content of the message id

Example

    fairOrder.getMessageByMessageId("1","0.0.195302").then((res)=>{
        console.log('Success::::::', res);
//       res example::::::
//       message
    }).catch((error)=>{
        console.log('Error::::::', error);
    });

getChannelListV2

function to get channel list for the application from dragonglass explorer

Returns Object list of channels

Parameters

  • pageSize Number no of items in one call
  • pageNum Number the page number

Example

    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);
    });

getMessageListByChannelIdV2

function to get the list of messages by channelId from dragonglass explorer

Parameters

  • channelID string refers to id of the channel

Returns Object list of messages on that channel

Example

    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);
    });
2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago