1

This is the contract code:-

pragma solidity ^0.4.7;

contract SimpleStorage {
     string public storedData;
     function set(string x) {
                  storedData = x;
     }
     function get() constant returns (string x) {
                 return storedData;
     }
 }

Index.html code

<html>
<head>
     <title>Embark - SimpleStorage Demo</title>
     <link rel="stylesheet" href="css/app.css">
     <script src="js/app.js"></script>
     <script src="web3.min.js"></script>
     <script src="ipfs.js"></script>
 </head>
 <body class="container">
       <h3>Embark - SimpleStorage Demo</h3>
    <h3> 1. Set the string in the blockchain</h3>
    <div class="form-group form-inline">
          <input type="text" class="text form-control">
          <button class="set btn btn-primary">Set String</button>
   </div>
   <h3> 2. Get the current value</h3>
   <div class="form-group">
        <div>
              current value is <span class="value"></span>
       </div>
       <button class="get btn btn-primary">Get String</button>
  </div>
  <h3>File Uploading</h3>
        <h3> 1. Set the file in the blockchain</h3>
        <div class="form-group form-inline">
             <input type="file">
             <button class="setfile btn btn-primary">Set File</button>
        </div>
        <h3> 2. Get the current value</h3>
             <div class="form-group">
                  <div>
                    current value is <span class="valuefile"></span>
                  </div>
                  <button class="getfile btn btn-primary">Get File</button>
            </div>
</body>
</html>

Index.js file

 EmbarkJS.Messages.setProvider('orbit',{server: 'localhost', port: '5001'});
 $(document).ready(function() {
           $("button.set").click(function() {
                    var value = $("input.text").val();
                    EmbarkJS.Storage.saveText(value).then(function(hash) {
                    SimpleStorage.set(hash);
                    });
           });
         $("button.get").click(function() {
                   SimpleStorage.get().then(function(hash) {
                   EmbarkJS.Storage.get(hash).then(function(content) {
                           $(".value").html(content);
                   });
                   });
        });

        $("button.setfile").click(function() {
                            var input = $("input[type=file]");
                     console.log(input);                                    

                   EmbarkJS.Storage.uploadFile(input).then(function(hash) {
                             SimpleStorage.set(hash);
                              console.log(hash);
                   });
           });
           $("button.getfile").click(function() {
                   SimpleStorage.get().then(function(hash) {
                             console.log("get");
                              console.log(hash);
                             EmbarkJS.Storage.getUrl(hash);
                            $(".valuefile").html("https://ipfs.io/ipfs/"+hash);
                              console.log("https://ipfs.io/ipfs/"+hash);

                            });
                    });
        });

I have created a dapp which saves the hash of text and file in orbit-db and retrieves it back. I have used orbit-db for storing data.How can i visualize the data stored in orbit-db?

1

You are setting up the provider for Messages instead of Storage. Note that the Orbit provider being used in Messages is intended for pub-sub messages just like whisper and not for database storage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.