libSimba-js Example

Initialise wallet from local storage

Using libsimba.LocalWallet we'll set up a wallet stored in the browsers local storage.

First we check if there's already a wallet in local storage with .walletExists(). If there is, we unlock that wallet. If not, we generate a new wallet. The callback passed to .unlockWallet() and .generateWallet() shows progres of the encryption/decryption of the wallet. You don't need to implement it, but it can be useful to provide feedback.


    Initialise Simba and connect to an app

    Using libsimba.getSimbaInstance we'll set up a Simba instance connected to an app.

    We pass in the Apps URL, the wallet we created previously, and our API Key. Once this is done, we have access to calls such as simba.getBalance() and simba.addFunds(). In this case, this App is running on Quorum, so our balance will be -1, and the add funds call will indicate "poa":true.


      Call Simba Method createRoom

      Using simba.callMethod we'll call the "createRoom" method.

      We pass in the method name, and it's params as an object. On success, this will return an object representing the transaction that's been sent to the blockchain. You can use simba.waitForSuccessOrError() on that object then to wait until the transaction has been successfully deployed and verified on the blockchain.


        Call Simba Method With File

        Using simba.callMethodWithFile we'll call the "sendMessage" method.

        This method is similar to .callMethod(), but also takes an array parameter. This array is a list of Blob or File objects. You can also use the file array obtained from a HTML Input elements .files.


          Get Transactions for the createRoom method

          Using simba.getMethodTransactions we'll retrieve a list of transactions on the "createRoom" method.

          This method is returns the array of transactions wrapped in a PagedResponse object. Calling .data() on this will return the array of transactions. Also available are .next() and .previous() which both return their own PagedResponse, with transactions representing the next and previous pages respectively.


            Get a Transaction using it's ID

            Using simba.getTransaction we'll retrieve a transaction.

            This method is returns the transaction.


              Get bundle metadata using the transactions hash

              Using simba.getBundleMetadataForTransaction we'll retrieve a the bundles metadata.

              This method is returns the transaction.


                Get a bundle using the transactions hash

                Using simba.getBundleForTransaction we'll retrieve a bundle.

                This method is returns the transaction.


                  Get a file from a bundle using the transactions hash

                  Using simba.getFileFromBundleForTransaction we'll retrieve a file from a bundle.

                  This method is returns the transaction.


                    Get a file from a bundle by name using the transactions hash

                    Using simba.getFileFromBundleByNameForTransaction we'll retrieve a file from a bundle.

                    This method is returns the transaction.