Blockchain | Vikram | 19th Jan

Discussion in 'Cloud Computing' started by Ravi T, Jan 19, 2019.

  1. Ravi T

    Ravi T Well-Known Member
    Simplilearn Support

    Joined:
    Jan 8, 2018
    Messages:
    223
    Likes Received:
    17
    Hi All,

    Please use this thread to connect with other learners, trainer and teaching assistant ( TA ) offline.
     
    #1
  2. Ravi T

    Ravi T Well-Known Member
    Simplilearn Support

    Joined:
    Jan 8, 2018
    Messages:
    223
    Likes Received:
    17
    Hi this is my first query.
     
    #2
  3. _49392

    _49392 Member

    Joined:
    Nov 24, 2018
    Messages:
    4
    Likes Received:
    1
    Hi Ravi,
    I am unable to locate the ebooks for blockchain. Please help.

    Thank you.

    Regards,
    Prashant
     
    #3
  4. Jai_16

    Jai_16 Member

    Joined:
    Mar 12, 2016
    Messages:
    2
    Likes Received:
    0
    #4
  5. Ravi T

    Ravi T Well-Known Member
    Simplilearn Support

    Joined:
    Jan 8, 2018
    Messages:
    223
    Likes Received:
    17
    Hi Prashant,

    Ebook is already present in the LMS in the Self-Learning ta, extreme bottom as Course Resources.

    Regards,
    Ravi Tulsiani
     
    #5
  6. _54259

    _54259 New Member

    Joined:
    Jan 2, 2019
    Messages:
    1
    Likes Received:
    0
    I couldn't attend the first two classes, but am attempting to watch the downloaded recordings.

    Now, to complete the attendance criterion, do I have to again attend the classes that I missed in next batch - even if I would have learnt the concepts through downloaded recordings?

    Kindly suggest.
     
    #6
  7. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    Code:
    const SHA256 = require("crypto-js/sha256");
    
    class Block {
        constructor(index, timestamp, data, previousHash = '') {
            this.index = index;
            this.previousHash = previousHash;
            this.timestamp = timestamp;
            this.data = data;
            this.hash = this.calculateHash();
        }
    
        calculateHash() {
          return SHA256(this.index + this.previousHash + this.timestamp + JSON.stringify(this.data)).toString();
        }
    }
    
    
    class Blockchain{
        constructor() {
            this.chain = [this.createGenesisBlock()];
        }
    
        createGenesisBlock() {
            return new Block(0, "01/01/2017", "Genesis block", "0");
        }
    
        getLatestBlock() {
            return this.chain[this.chain.length - 1];
        }
    
        addBlock(newBlock) {
            newBlock.previousHash = this.getLatestBlock().hash;
            newBlock.hash = newBlock.calculateHash();
            this.chain.push(newBlock);
        }
    }
    
    let myCoin = new Blockchain();
    myCoin.addBlock(new Block(1, "20/07/2017", { amount: 4 }));
    myCoin.addBlock(new Block(2, "20/07/2017", { amount: 8 }));
    
    
    console.log(JSON.stringify(myCoin, null, 4));
     
    #7
  8. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
     
    #8
  9. _49392

    _49392 Member

    Joined:
    Nov 24, 2018
    Messages:
    4
    Likes Received:
    1
    Hi,
    How are the non-responsive nodes removed? Since it is a random topology, nodes are randomly joining and leaving. Given this, who sets such rules, when and where?

    Thanks & Regards,
    Prashant
     
    #9
    Vikram_109 likes this.
  10. _49392

    _49392 Member

    Joined:
    Nov 24, 2018
    Messages:
    4
    Likes Received:
    1
    #10
  11. _49392

    _49392 Member

    Joined:
    Nov 24, 2018
    Messages:
    4
    Likes Received:
    1
    Hi Ravi,
    I am still not able to locate the ebook under the aforementioned section; I received it now though from a co-student.

    New Query: I always see a highlighted "update" button under Courses-Blockchain, but nothing happens when I click it. Most of the self learning slides for blockchain are not visible in the portal.

    Please suggest as to how I can get latest updates.

    Thanks & Regards,
    Prashant
     
    #11
  12. _53566

    _53566 Member

    Joined:
    Dec 27, 2018
    Messages:
    2
    Likes Received:
    1
    how to identify the secondary chains?
     
    #12
    Vikram_109 likes this.
  13. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    lesson end project 2
     

    Attached Files:

    #13
  14. _55027

    _55027 Member

    Joined:
    Jan 8, 2019
    Messages:
    2
    Likes Received:
    0
    Hi All,
    It seems that all blockchain platforms already have code for block creation and adding block into the block chain, I think miners will have tasks of validation or finding random number(Nonce). Is there any role for developers or architects? please share your views.
    Thanks,
    JC
     
    #14
  15. Padmanaban_1

    Padmanaban_1 Member

    Joined:
    Jan 5, 2019
    Messages:
    2
    Likes Received:
    1
    Hi,
    Did anyone tried creating Steemit. While signing up shows 1-2 weeks of waiting time to create a free account. Is that the same for others.

    Thanks,
    P.Padmanaban
     
    #15
  16. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    #16
    _49392 likes this.
  17. _55027

    _55027 Member

    Joined:
    Jan 8, 2019
    Messages:
    2
    Likes Received:
    0
    Hi Padmanaban,
    I think so, I did not try as it's taking 1-2 weeks, It seems you can create paid account instantly. Better wait for 1-2 weeks and update us your experience.
    Thanks JC.
     
    #17
  18. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    the one with the second highest cumulative difficulty OR the second longest chain i.e. the chain with number of blocks less than the main chain
    What we are studying in a fundamental blockchain called Bitcoin. Every role is predefined in the bitcoin network and is open to every to join and leave whenever they want and its called Blockchain 1.0
    In Blockchain 2.0 such as Ethereum we have lots of necessity for developers and architects.
    Stay Tuned for that....:)
     
    #18
  19. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    Yes, i did and it will take that much time. its normal.
     
    #19
  20. _43333

    _43333 New Member

    Joined:
    Oct 9, 2018
    Messages:
    1
    Likes Received:
    0
    Hi Vikram,
    So i picked up the movie review ethereum project as given by simplilearn. I hve designed a small front end and used solidity to design the back end db. However when i push information through my front end i am getting VM Exception. Please help me resolve this.

    Front End Code:

    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="Viewport" content="width-device-width, initial-scale=1.0">
    <title> ABC Entertainment Review Page </title>
    <script src="./node_modules/web3/dist/web3.js"> </script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <style>
    #loader{
    width : 100px;
    height : 50px;
    display : none;
    }
    </style>
    </head>
    <body>
    <div class="container" id="c1">
    <div class="row">
    <div class="col-lg-6 offset-lg-3" >
    <h1> MovieReviews </h1> <br>
    <span id="insHash"></span>
    <span id="countIns"> </span> <hr>
    <img src="https://loading.io/spinners/double-ring/lg.double-ring-spinner.gif" id="loader">
    <h2 id="Movie"></h2>
    <label for="moviename">Movie Name</label>
    <input type="text" id="moviename" class="form-control form-control-lg"> <br>
    <label for="movierating">Movie Rating</label>
    <select id="movierating">
    <option value="1" selected>1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    </select>
    <br><button id="button2" type="submit" class="btn btn-success"> Submit </button>
    </div>
    </div>
    </div>
    <hr></hr>
    <div class="container1" id="c2">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"> </script>
    <script>
    if(typeof web3!=='undefined'){
    web3 = new Web3(web3.currentProvider);
    }
    else{
    web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    }
    web3.eth.defaultAccount=web3.eth.accounts[0];
    var connect = web3.eth.contract([
    {
    "constant": false,
    "inputs": [
    {
    "name": "_name",
    "type": "bytes32"
    },
    {
    "name": "_rating",
    "type": "uint256"
    }
    ],
    "name": "addRatingEntry",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
    },
    {
    "anonymous": false,
    "inputs": [
    {
    "indexed": false,
    "name": "name",
    "type": "bytes32"
    },
    {
    "indexed": false,
    "name": "rating",
    "type": "uint256"
    }
    ],
    "name": "AddEntry",
    "type": "event"
    },
    {
    "constant": true,
    "inputs": [
    {
    "name": "id",
    "type": "uint256"
    }
    ],
    "name": "getRatingEntryForMovie",
    "outputs": [
    {
    "name": "",
    "type": "uint256"
    },
    {
    "name": "",
    "type": "bytes32"
    },
    {
    "name": "",
    "type": "bool"
    },
    {
    "name": "",
    "type": "uint256"
    },
    {
    "name": "",
    "type": "uint256"
    }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
    },
    {
    "constant": true,
    "inputs": [],
    "name": "length",
    "outputs": [
    {
    "name": "",
    "type": "uint256"
    }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
    },
    {
    "constant": true,
    "inputs": [
    {
    "name": "",
    "type": "uint256"
    }
    ],
    "name": "objects",
    "outputs": [
    {
    "name": "id",
    "type": "uint256"
    },
    {
    "name": "name",
    "type": "bytes32"
    },
    {
    "name": "rating",
    "type": "uint256"
    },
    {
    "name": "isDone",
    "type": "bool"
    },
    {
    "name": "time",
    "type": "uint256"
    }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
    }
    ]);
    var blockchainRockstars = connect.at('0xaf5f0bb26f3a8341ce6ce7d17f640a2342f33098');
    var eventinsSet = blockchainRockstars.AddEntry({},'latest');
    eventinsSet.watch(function(error,result){
    if(!error){
    if(result.blockhash!= $("#insHash").html())
    $("#loader").hide();
    $("#insHash").html(result.blockhash);
    $("#Movie").html(result.args.name + result.args.rating);
    }
    else{
    $("#loader").hide();
    console.log("Error is" +error);
    }
    });
    /* blockchainRockstars.getMovieReviewCount((err,res)=>{

    if(res)
    $("#countIns").html(res.c+' Movie Reviews');

    }); */

    $("#button2").click(function(){
    console.log("Rating value is "+document.getElementById("movierating").value);
    $("#loader").show();
    blockchainRockstars.addRatingEntry($("#moviename").val(),parseInt(document.getElementById("movierating").value),(err,res)=>{
    console.log("Whether error is true or not "+err);
    console.log("Result is "+res);
    if(err){
    $("#loader").hide();
    console.log("Wrong contract " +err);
    }
    }

    );
    });

    </script>
    </body>
    </html>

    Back End Solidity Code:

    pragma solidity >=0.4.22 < 0.6.0;
    contract movieReviews {
    struct Object{
    uint id;
    bytes32 name;
    uint rating;
    bool isDone;
    uint time;

    }
    Object[] public objects;
    uint public length = 0;
    event AddEntry(

    bytes32 name,
    uint rating

    );

    function addRatingEntry(bytes32 _name, uint _rating) public {
    objects.push(Object( objects.length,_name, _rating, false,now));
    emit AddEntry(_name, _rating);
    length= length +1;
    }
    function getRatingEntryForMovie(uint id) public view
    returns(
    uint,
    bytes32,
    bool,
    uint,
    uint
    )
    {
    return(
    id,
    objects[id].name,
    objects[id].isDone,
    objects[id].rating,
    objects[id].time
    );

    }

    }

    Thanks in advance!

    Regards,
    Prakhar Chatterjee
     
    #20
  21. _53566

    _53566 Member

    Joined:
    Dec 27, 2018
    Messages:
    2
    Likes Received:
    1
    I am getting the below error
    "browser/newsuryacoin.sol:1:634: ParserError: Function, variable, struct or modifier declaration expected."
    while executing the code:

    pragma solidity ^0.4.0;
    contract SuryaCoin {
    address public creator;
    mapping(address => uint) public balance; // key-value pair
    uint constant PRICE = 5000000000000000000; // 5 ether
    function SuryaCoin() public {
    creator = msg.sender;
    }
    function createCoin() public payable {
    require(msg.value > 0 && msg.value % PRICE == 0);
    balance[msg.sender] += msg.value/PRICE;
    }
    function transfer(address receiver, uint amount) public {
    require(amount > 0 && balance[msg.sender] >= amount);
    balance[msg.sender] -= amount;
    balance[receiver] += amount;
    }
     
    #21
  22. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    Just put " } " in the end
     
    #22
  23. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    Hi,
    I want to add some programming files
    is there a library where i can upload the files ??
     
    #23
    Padmanaban_1 likes this.
  24. Padmanaban_1

    Padmanaban_1 Member

    Joined:
    Jan 5, 2019
    Messages:
    2
    Likes Received:
    1
    In the below code, in createcoin method we use "if" and in TransferCoin "require" what is the difference between If and require. when should we use what?
    pragma solidity ^0.4.0;

    contract PaddyCoin{

    address creator;
    mapping(address => uint) balance;

    function PaddyCoin() public{
    creator = msg.sender;
    }

    function CreateCoin(address reciever, uint amount) public {
    if(msg.sender == creator){
    balance[reciever] += amount;
    }
    }

    function TransferCoin(address reciever, uint amount) public {
    require(amount > 0 && balance[msg.sender] >= amount);
    balance[msg.sender] -= amount;
    balance[reciever] += amount;
    }
    }
     
    #24
    Vikram_109 likes this.
  25. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    pragma solidity ^0.4.0;

    contract DragonStone {

    address public creator;
    mapping(address => uint ) public balance;
    uint constant public PRICE = 5000000000000000000; // 5 ether

    function DragonStone(){
    creator = msg.sender;
    }
    function create() public payable {
    require(msg.value > 0 && msg.value % PRICE == 0);
    balance[msg.sender] += (msg.value/PRICE);
    }
    function transfer(address receiver, uint amount) public {
    if(amount > 0 && balance[msg.sender] > 0){
    balance[msg.sender] -= amount;
    balance[receiver] += amount;
    }
    }
    }
     
    #25
  26. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3
    pragma solidity ^0.4.0;

    contract Instructor {

    address creator;
    string fname;
    uint age;

    event InstructorEvent(string name, uint age);

    function Instructor() {
    creator = msg.sender;
    }

    function setInstructor(string _fname, uint _age) {
    fname = _fname;
    age = _age;
    InstructorEvent(_fname, _age);
    }

    function getInstructor() view public returns (string, uint){
    return(fname, age);
    }
    }
     
    #26
  27. Vikram_109

    Vikram_109 Customer
    Customer

    Joined:
    Jan 5, 2019
    Messages:
    11
    Likes Received:
    3

    You can use both. Both have the same functionality to check the conditions and only differ in words

    https://stackoverflow.com/questions...s-the-difference-between-using-if-and-require
     
    #27
    Padmanaban_1 likes this.
  28. _47905

    _47905 Member

    Joined:
    Nov 12, 2018
    Messages:
    4
    Likes Received:
    1
     
    #28
  29. _47905

    _47905 Member

    Joined:
    Nov 12, 2018
    Messages:
    4
    Likes Received:
    1
    Vikram,

    I worked on example with storing name and age from last session. I created HTML form and running ganache in local and deployed my smart contract in remix too and used all address properly. But I am facing below error.

    Can you please suggest what can be wrong?

    Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (errors.js:35)
    at XMLHttpRequest.request.onreadystatechange (httpprovider.js:108)
    at XMLHttpRequestEventTarget.dispatchEvent (xml-http-request.js:68)
    at XMLHttpRequest._setReadyState (xml-http-request.js:367)
    at XMLHttpRequest._onHttpRequestError (bignumber.js:37)
    at module.exports.<anonymous> (xml-http-request.js:411)
    at emitOne (events.js:45)
    at module.exports.emit (events.js:123)
    at request.js:26
     
    #29
  30. _47905

    _47905 Member

    Joined:
    Nov 12, 2018
    Messages:
    4
    Likes Received:
    1
    Hi Vikram, I have attached my code. Please check
     

    Attached Files:

    #30
  31. _47905

    _47905 Member

    Joined:
    Nov 12, 2018
    Messages:
    4
    Likes Received:
    1
    Hi All,

    Please find details for MovieRating project. Once you all setup, Please run in IE only. It will not work in chrome.
    Good luck!!

    Thanks!!
     

    Attached Files:

    #31
    _49392 likes this.

Share This Page