3

I am using Embark Framework.I am trying to store a string value in IPFS and then to retrieve that string using the hash.

Contract Code (simple_storage.sol) :-

pragma solidity ^0.4.7;

contract SimpleStorage {
         string public storedData;
         function SimpleStorage() {
                      storedData = "hello world";
         }
         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>
</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>
 </body>
</html>

Index.js Code :-

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

I am given a string as input and it returns string as output correctly.How can i verify the values stored in orbit db?

I have tried using 'ipfs' instead of 'orbit'.But the code won't get worked?What is the issue?

  • @samuraj jack Please help me to develop a dapp using IPFS – Crissi Mariam Robert Jan 18 '17 at 5:10
3

It seems you are mixing up EmbarkJS.Storage and EmbarkJS.Messages. You should be configuring the storage provider not the messages one:

EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});

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.